SConstruct 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # see http://www.scons.org if you do not have this tool
  2. from os.path import join
  3. import SCons
  4. # TODO: should use lamda and map to work on python 1.5
  5. def path(prefix, list): return [join(prefix, x) for x in list]
  6. encoder_sources = """
  7. apiwrapper.c
  8. fragment.c
  9. idct.c
  10. internal.c
  11. state.c
  12. quant.c
  13. analyze.c
  14. encfrag.c
  15. encapiwrapper.c
  16. encinfo.c
  17. encode.c
  18. enquant.c
  19. fdct.c
  20. huffenc.c
  21. mathops.c
  22. mcenc.c
  23. rate.c
  24. tokenize.c
  25. """
  26. decoder_sources = """
  27. apiwrapper.c
  28. bitpack.c
  29. decapiwrapper.c
  30. decinfo.c
  31. decode.c
  32. dequant.c
  33. fragment.c
  34. huffdec.c
  35. idct.c
  36. info.c
  37. internal.c
  38. quant.c
  39. state.c
  40. """
  41. env = Environment()
  42. if env['CC'] == 'gcc':
  43. env.Append(CCFLAGS=["-g", "-O2", "-Wall", "-Wno-parentheses"])
  44. def CheckPKGConfig(context, version):
  45. context.Message( 'Checking for pkg-config... ' )
  46. ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
  47. context.Result( ret )
  48. return ret
  49. def CheckPKG(context, name):
  50. context.Message( 'Checking for %s... ' % name )
  51. ret = context.TryAction('pkg-config --exists %s' % name)[0]
  52. context.Result( ret )
  53. return ret
  54. def CheckSDL(context):
  55. name = "sdl-config"
  56. context.Message( 'Checking for %s... ' % name )
  57. ret = SCons.Util.WhereIs('sdl-config')
  58. context.Result( ret )
  59. return ret
  60. # check for appropriate inline asm support
  61. host_x86_32_test = """
  62. int main(int argc, char **argv) {
  63. #if !defined(__i386__)
  64. #error not an x86 host: preprocessor macro __i386__ not defined
  65. #endif
  66. return 0;
  67. }
  68. """
  69. def CheckHost_x86_32(context):
  70. context.Message('Checking for an x86 host...')
  71. result = context.TryCompile(host_x86_32_test, '.c')
  72. context.Result(result)
  73. return result
  74. host_x86_64_test = """
  75. int main(int argc, char **argv) {
  76. #if !defined(__x86_64__)
  77. #error not an x86_64 host: preprocessor macro __x86_64__ not defined
  78. #endif
  79. return 0;
  80. }
  81. """
  82. def CheckHost_x86_64(context):
  83. context.Message('Checking for an x86_64 host...')
  84. result = context.TryCompile(host_x86_64_test, '.c')
  85. context.Result(result)
  86. return result
  87. conf = Configure(env, custom_tests = {
  88. 'CheckPKGConfig' : CheckPKGConfig,
  89. 'CheckPKG' : CheckPKG,
  90. 'CheckSDL' : CheckSDL,
  91. 'CheckHost_x86_32' : CheckHost_x86_32,
  92. 'CheckHost_x86_64' : CheckHost_x86_64,
  93. })
  94. if not conf.CheckPKGConfig('0.15.0'):
  95. print 'pkg-config >= 0.15.0 not found.'
  96. Exit(1)
  97. if not conf.CheckPKG('ogg'):
  98. print 'libogg not found.'
  99. Exit(1)
  100. if conf.CheckPKG('vorbis vorbisenc'):
  101. have_vorbis=True
  102. else:
  103. have_vorbis=False
  104. if conf.CheckPKG('libpng'):
  105. have_libpng=True
  106. else:
  107. have_libpng=False
  108. build_player_example=True
  109. if not conf.CheckHeader('sys/soundcard.h'):
  110. build_player_example=False
  111. if build_player_example and not conf.CheckSDL():
  112. build_player_example=False
  113. if conf.CheckHost_x86_32():
  114. env.Append(CPPDEFINES='OC_X86_ASM')
  115. decoder_sources += """
  116. x86/mmxidct.c
  117. x86/mmxfrag.c
  118. x86/mmxstate.c
  119. x86/x86state.c
  120. """
  121. encoder_sources += """
  122. x86/mmxencfrag.c
  123. x86/mmxfdct.c
  124. x86/x86enc.c
  125. x86/mmxfrag.c
  126. x86/mmxidct.c
  127. x86/mmxstate.c
  128. x86/x86state.c
  129. """
  130. elif conf.CheckHost_x86_64():
  131. env.Append(CPPDEFINES=['OC_X86_ASM', 'OC_X86_64_ASM'])
  132. decoder_sources += """
  133. x86/mmxidct.c
  134. x86/mmxfrag.c
  135. x86/mmxstate.c
  136. x86/x86state.c
  137. """
  138. encoder_sources += """
  139. x86/mmxencfrag.c
  140. x86/mmxfdct.c
  141. x86/x86enc.c
  142. x86/sse2fdct.c
  143. x86/mmxfrag.c
  144. x86/mmxidct.c
  145. x86/mmxstate.c
  146. x86/x86state.c
  147. """
  148. env = conf.Finish()
  149. env.Append(CPPPATH=['include'])
  150. env.ParseConfig('pkg-config --cflags --libs ogg')
  151. libtheoradec_Sources = Split(decoder_sources)
  152. libtheoraenc_Sources = Split(encoder_sources)
  153. libtheoradec_a = env.Library('lib/theoradec',
  154. path('lib', libtheoradec_Sources))
  155. libtheoradec_so = env.SharedLibrary('lib/theoradec',
  156. path('lib', libtheoradec_Sources))
  157. libtheoraenc_a = env.Library('lib/theoraenc',
  158. path('lib', libtheoraenc_Sources))
  159. libtheoraenc_so = env.SharedLibrary('lib/theoraenc',
  160. path('lib', libtheoraenc_Sources) + [libtheoradec_so])
  161. #installing
  162. prefix='/usr'
  163. lib_dir = prefix + '/lib'
  164. env.Alias('install', prefix)
  165. env.Install(lib_dir, [libtheoradec_a, libtheoradec_so])
  166. env.Install(lib_dir, [libtheoraenc_a, libtheoraenc_so])
  167. # example programs
  168. dump_video = env.Clone()
  169. dump_video_Sources = Split("""dump_video.c ../lib/libtheoradec.a""")
  170. dump_video.Program('examples/dump_video', path('examples', dump_video_Sources))
  171. dump_psnr = env.Clone()
  172. dump_psnr.Append(LIBS='m')
  173. dump_psnr_Sources = Split("""dump_psnr.c ../lib/libtheoradec.a""")
  174. dump_psnr.Program('examples/dump_psnr', path('examples', dump_psnr_Sources))
  175. if have_vorbis:
  176. encex = dump_video.Clone()
  177. encex.ParseConfig('pkg-config --cflags --libs vorbisenc vorbis')
  178. encex_Sources = Split("""
  179. encoder_example.c
  180. ../lib/libtheoraenc.a
  181. ../lib/libtheoradec.a
  182. """)
  183. encex.Program('examples/encoder_example', path('examples', encex_Sources))
  184. if build_player_example:
  185. plyex = encex.Clone()
  186. plyex_Sources = Split("""
  187. player_example.c
  188. ../lib/libtheoradec.a
  189. """)
  190. plyex.ParseConfig('sdl-config --cflags --libs')
  191. plyex.Program('examples/player_example', path('examples', plyex_Sources))
  192. png2theora = env.Clone()
  193. png2theora_Sources = Split("""png2theora.c
  194. ../lib/libtheoraenc.a
  195. ../lib/libtheoradec.a
  196. """)
  197. png2theora.ParseConfig('pkg-config --cflags --libs libpng')
  198. png2theora.Program('examples/png2theora', path('examples', png2theora_Sources))