1 # see http://www.scons.org if you do not have this tool
2 from os.path import join
5 # TODO: should use lamda and map to work on python 1.5
6 def path(prefix, list): return [join(prefix, x) for x in list]
46 if env['CC'] == 'gcc':
47 env.Append(CCFLAGS=["-g", "-O2", "-Wall", "-Wno-parentheses"])
49 def CheckPKGConfig(context, version):
50 context.Message( 'Checking for pkg-config... ' )
51 ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
55 def CheckPKG(context, name):
56 context.Message( 'Checking for %s... ' % name )
57 ret = context.TryAction('pkg-config --exists %s' % name)[0]
61 def CheckSDL(context):
63 context.Message( 'Checking for %s... ' % name )
64 ret = SCons.Util.WhereIs('sdl-config')
68 # check for appropriate inline asm support
69 host_x86_32_test = """
70 int main(int argc, char **argv) {
71 #if !defined(__i386__)
72 #error not an x86 host: preprocessor macro __i386__ not defined
77 def CheckHost_x86_32(context):
78 context.Message('Checking for an x86 host...')
79 result = context.TryCompile(host_x86_32_test, '.c')
80 context.Result(result)
83 host_x86_64_test = """
84 int main(int argc, char **argv) {
85 #if !defined(__x86_64__)
86 #error not an x86_64 host: preprocessor macro __x86_64__ not defined
91 def CheckHost_x86_64(context):
92 context.Message('Checking for an x86_64 host...')
93 result = context.TryCompile(host_x86_64_test, '.c')
94 context.Result(result)
97 conf = Configure(env, custom_tests = {
98 'CheckPKGConfig' : CheckPKGConfig,
99 'CheckPKG' : CheckPKG,
100 'CheckSDL' : CheckSDL,
101 'CheckHost_x86_32' : CheckHost_x86_32,
102 'CheckHost_x86_64' : CheckHost_x86_64,
105 if not conf.CheckPKGConfig('0.15.0'):
106 print 'pkg-config >= 0.15.0 not found.'
109 if not conf.CheckPKG('ogg'):
110 print 'libogg not found.'
113 if conf.CheckPKG('vorbis vorbisenc'):
118 if conf.CheckPKG('libpng'):
123 build_player_example=True
124 if not conf.CheckHeader('sys/soundcard.h'):
125 build_player_example=False
126 if build_player_example and not conf.CheckSDL():
127 build_player_example=False
129 if conf.CheckHost_x86_32():
130 env.Append(CPPDEFINES='OC_X86_ASM')
131 decoder_sources += """
137 encoder_sources += """
146 elif conf.CheckHost_x86_64():
147 env.Append(CPPDEFINES=['OC_X86_ASM', 'OC_X86_64_ASM'])
148 decoder_sources += """
154 encoder_sources += """
167 env.Append(CPPPATH=['include'])
168 env.ParseConfig('pkg-config --cflags --libs ogg')
170 libtheoradec_Sources = Split(decoder_sources)
171 libtheoraenc_Sources = Split(encoder_sources)
173 libtheoradec_a = env.Library('lib/theoradec',
174 path('lib', libtheoradec_Sources))
175 libtheoradec_so = env.SharedLibrary('lib/theoradec',
176 path('lib', libtheoradec_Sources))
178 libtheoraenc_a = env.Library('lib/theoraenc',
179 path('lib', libtheoraenc_Sources))
180 libtheoraenc_so = env.SharedLibrary('lib/theoraenc',
181 path('lib', libtheoraenc_Sources) + [libtheoradec_so])
185 lib_dir = prefix + '/lib'
186 env.Alias('install', prefix)
187 env.Install(lib_dir, [libtheoradec_a, libtheoradec_so])
188 env.Install(lib_dir, [libtheoraenc_a, libtheoraenc_so])
191 dump_video = env.Clone()
192 dump_video_Sources = Split("""dump_video.c ../lib/libtheoradec.a""")
193 dump_video.Program('examples/dump_video', path('examples', dump_video_Sources))
195 dump_psnr = env.Clone()
196 dump_psnr.Append(LIBS='m')
197 dump_psnr_Sources = Split("""dump_psnr.c ../lib/libtheoradec.a""")
198 dump_psnr.Program('examples/dump_psnr', path('examples', dump_psnr_Sources))
201 encex = dump_video.Clone()
202 encex.ParseConfig('pkg-config --cflags --libs vorbisenc vorbis')
203 encex_Sources = Split("""
205 ../lib/libtheoraenc.a
206 ../lib/libtheoradec.a
208 encex.Program('examples/encoder_example', path('examples', encex_Sources))
210 if build_player_example:
211 plyex = encex.Clone()
212 plyex_Sources = Split("""
214 ../lib/libtheoradec.a
216 plyex.ParseConfig('sdl-config --cflags --libs')
217 plyex.Program('examples/player_example', path('examples', plyex_Sources))
219 png2theora = env.Clone()
220 png2theora_Sources = Split("""png2theora.c
221 ../lib/libtheoraenc.a
222 ../lib/libtheoradec.a
224 png2theora.ParseConfig('pkg-config --cflags --libs libpng')
225 png2theora.Program('examples/png2theora', path('examples', png2theora_Sources))