SConstruct 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. # pass collect_metrics=1 on the scons command line
  45. # to enable metrics collection for mode training.
  46. collect_metrics = ARGUMENTS.get('collect_metrics', 0)
  47. if int(collect_metrics):
  48. env.Append(CPPDEFINES=['OC_COLLECT_METRICS'])
  49. env.Append(LIBS=['m'])
  50. def CheckPKGConfig(context, version):
  51. context.Message( 'Checking for pkg-config... ' )
  52. ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
  53. context.Result( ret )
  54. return ret
  55. def CheckPKG(context, name):
  56. context.Message( 'Checking for %s... ' % name )
  57. ret = context.TryAction('pkg-config --exists %s' % name)[0]
  58. context.Result( ret )
  59. return ret
  60. def CheckSDL(context):
  61. name = "sdl-config"
  62. context.Message( 'Checking for %s... ' % name )
  63. ret = SCons.Util.WhereIs('sdl-config')
  64. context.Result( ret )
  65. return ret
  66. # check for appropriate inline asm support
  67. host_x86_32_test = """
  68. int main(int argc, char **argv) {
  69. #if !defined(__i386__)
  70. #error not an x86 host: preprocessor macro __i386__ not defined
  71. #endif
  72. return 0;
  73. }
  74. """
  75. def CheckHost_x86_32(context):
  76. context.Message('Checking for an x86 host...')
  77. result = context.TryCompile(host_x86_32_test, '.c')
  78. context.Result(result)
  79. return result
  80. host_x86_64_test = """
  81. int main(int argc, char **argv) {
  82. #if !defined(__x86_64__)
  83. #error not an x86_64 host: preprocessor macro __x86_64__ not defined
  84. #endif
  85. return 0;
  86. }
  87. """
  88. def CheckHost_x86_64(context):
  89. context.Message('Checking for an x86_64 host...')
  90. result = context.TryCompile(host_x86_64_test, '.c')
  91. context.Result(result)
  92. return result
  93. conf = Configure(env, custom_tests = {
  94. 'CheckPKGConfig' : CheckPKGConfig,
  95. 'CheckPKG' : CheckPKG,
  96. 'CheckSDL' : CheckSDL,
  97. 'CheckHost_x86_32' : CheckHost_x86_32,
  98. 'CheckHost_x86_64' : CheckHost_x86_64,
  99. })
  100. if not conf.CheckPKGConfig('0.15.0'):
  101. print 'pkg-config >= 0.15.0 not found.'
  102. Exit(1)
  103. if not conf.CheckPKG('ogg'):
  104. print 'libogg not found.'
  105. Exit(1)
  106. if conf.CheckPKG('vorbis vorbisenc'):
  107. have_vorbis=True
  108. else:
  109. have_vorbis=False
  110. if conf.CheckPKG('libpng'):
  111. have_libpng=True
  112. else:
  113. have_libpng=False
  114. build_player_example=True
  115. if not conf.CheckHeader('sys/soundcard.h'):
  116. build_player_example=False
  117. if build_player_example and not conf.CheckSDL():
  118. build_player_example=False
  119. if conf.CheckHost_x86_32():
  120. env.Append(CPPDEFINES='OC_X86_ASM')
  121. decoder_sources += """
  122. x86/x86cpu.c
  123. x86/mmxidct.c
  124. x86/mmxfrag.c
  125. x86/mmxstate.c
  126. x86/sse2idct.c
  127. x86/x86state.c
  128. """
  129. encoder_sources += """
  130. x86/x86cpu.c
  131. x86/mmxencfrag.c
  132. x86/mmxfdct.c
  133. x86/x86enc.c
  134. x86/x86enquant.c
  135. x86/sse2encfrag.c
  136. x86/mmxfrag.c
  137. x86/mmxidct.c
  138. x86/mmxstate.c
  139. x86/x86state.c
  140. """
  141. elif conf.CheckHost_x86_64():
  142. env.Append(CPPDEFINES=['OC_X86_ASM', 'OC_X86_64_ASM'])
  143. decoder_sources += """
  144. x86/x86cpu.c
  145. x86/mmxidct.c
  146. x86/mmxfrag.c
  147. x86/mmxstate.c
  148. x86/sse2idct.c
  149. x86/x86state.c
  150. """
  151. encoder_sources += """
  152. x86/x86cpu.c
  153. x86/mmxencfrag.c
  154. x86/mmxfdct.c
  155. x86/x86enc.c
  156. x86/x86enquant.c
  157. x86/sse2fdct.c
  158. x86/mmxfrag.c
  159. x86/mmxidct.c
  160. x86/mmxstate.c
  161. x86/x86state.c
  162. x86/sse2encfrag.c
  163. """
  164. env = conf.Finish()
  165. env.Append(CPPPATH=['include'])
  166. env.ParseConfig('pkg-config --cflags --libs ogg')
  167. libtheoradec_Sources = Split(decoder_sources)
  168. libtheoraenc_Sources = Split(encoder_sources)
  169. libtheoradec_a = env.Library('lib/theoradec',
  170. path('lib', libtheoradec_Sources))
  171. libtheoradec_so = env.SharedLibrary('lib/theoradec',
  172. path('lib', libtheoradec_Sources))
  173. libtheoraenc_a = env.Library('lib/theoraenc',
  174. path('lib', libtheoraenc_Sources))
  175. libtheoraenc_so = env.SharedLibrary('lib/theoraenc',
  176. path('lib', libtheoraenc_Sources) + [libtheoradec_so])
  177. #installing
  178. prefix='/usr'
  179. lib_dir = prefix + '/lib'
  180. env.Alias('install', prefix)
  181. env.Install(lib_dir, [libtheoradec_a, libtheoradec_so])
  182. env.Install(lib_dir, [libtheoraenc_a, libtheoraenc_so])
  183. # example programs
  184. dump_video = env.Clone()
  185. dump_video_Sources = Split("""dump_video.c ../lib/libtheoradec.a""")
  186. dump_video.Program('examples/dump_video', path('examples', dump_video_Sources))
  187. dump_psnr = env.Clone()
  188. dump_psnr.Append(LIBS='m')
  189. dump_psnr_Sources = Split("""dump_psnr.c ../lib/libtheoradec.a""")
  190. dump_psnr.Program('examples/dump_psnr', path('examples', dump_psnr_Sources))
  191. libtheora_info = env.Clone()
  192. libtheora_info_Sources = Split("""
  193. libtheora_info.c
  194. ../lib/libtheoraenc.a
  195. ../lib/libtheoradec.a
  196. """)
  197. libtheora_info.Program('examples/libtheora_info',
  198. path('examples', libtheora_info_Sources))
  199. if have_vorbis:
  200. encex = dump_video.Clone()
  201. encex.ParseConfig('pkg-config --cflags --libs vorbisenc vorbis')
  202. encex.Append(LIBS=['m'])
  203. encex_Sources = Split("""
  204. encoder_example.c
  205. ../lib/libtheoraenc.a
  206. ../lib/libtheoradec.a
  207. """)
  208. encex.Program('examples/encoder_example', path('examples', encex_Sources))
  209. if build_player_example:
  210. plyex = encex.Clone()
  211. plyex_Sources = Split("""
  212. player_example.c
  213. ../lib/libtheoradec.a
  214. """)
  215. plyex.ParseConfig('sdl-config --cflags --libs')
  216. plyex.Append(LIBS=['m'])
  217. plyex.Program('examples/player_example', path('examples', plyex_Sources))
  218. png2theora = env.Clone()
  219. png2theora_Sources = Split("""png2theora.c
  220. ../lib/libtheoraenc.a
  221. ../lib/libtheoradec.a
  222. """)
  223. png2theora.ParseConfig('pkg-config --cflags --libs libpng')
  224. png2theora.Append(LIBS=['m'])
  225. png2theora.Program('examples/png2theora', path('examples', png2theora_Sources))
  226. tiff2theora = env.Clone()
  227. tiff2theora_Sources = Split("""tiff2theora.c
  228. ../lib/libtheoraenc.a
  229. ../lib/libtheoradec.a
  230. """)
  231. tiff2theora.Append(LIBS=['tiff', 'm'])
  232. tiff2theora.Program('examples/tiff2theora', path('examples', tiff2theora_Sources))