spec: Use %license macro to copy license
[platform/upstream/libtheora.git] / SConstruct
1 # see http://www.scons.org if you do not have this tool
2 from os.path import join
3 import SCons
4
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]
7
8 encoder_sources = """
9         apiwrapper.c
10         fragment.c
11         idct.c
12         internal.c
13         state.c
14         quant.c
15         analyze.c
16         encfrag.c
17         encapiwrapper.c
18         encinfo.c
19         encode.c
20         enquant.c
21         fdct.c
22         huffenc.c
23         mathops.c
24         mcenc.c
25         rate.c
26         tokenize.c
27 """
28
29 decoder_sources = """
30         apiwrapper.c
31         bitpack.c
32         decapiwrapper.c
33         decinfo.c
34         decode.c
35         dequant.c
36         fragment.c
37         huffdec.c
38         idct.c
39         info.c
40         internal.c
41         quant.c
42         state.c
43 """
44
45 env = Environment()
46 if env['CC'] == 'gcc':
47   env.Append(CCFLAGS=["-g", "-O2", "-Wall", "-Wno-parentheses"])
48
49 def CheckPKGConfig(context, version): 
50   context.Message( 'Checking for pkg-config... ' ) 
51   ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0] 
52   context.Result( ret ) 
53   return ret 
54
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      
61 def CheckSDL(context):
62   name = "sdl-config"
63   context.Message( 'Checking for %s... ' % name )
64   ret = SCons.Util.WhereIs('sdl-config')
65   context.Result( ret ) 
66   return ret
67
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
73 #endif
74   return 0;
75     }
76     """
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)
81   return result
82
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
87 #endif
88   return 0;
89     }
90     """
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)
95   return result
96
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,
103   })
104   
105 if not conf.CheckPKGConfig('0.15.0'): 
106    print 'pkg-config >= 0.15.0 not found.' 
107    Exit(1)
108
109 if not conf.CheckPKG('ogg'): 
110   print 'libogg not found.' 
111   Exit(1) 
112
113 if conf.CheckPKG('vorbis vorbisenc'):
114   have_vorbis=True
115 else:
116   have_vorbis=False
117
118 if conf.CheckPKG('libpng'):
119   have_libpng=True
120 else:
121   have_libpng=False
122   
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
128
129 if conf.CheckHost_x86_32():
130   env.Append(CPPDEFINES='OC_X86_ASM')
131   decoder_sources += """
132         x86/mmxidct.c
133         x86/mmxfrag.c
134         x86/mmxstate.c
135         x86/x86state.c
136   """
137   encoder_sources += """
138         x86/mmxencfrag.c
139         x86/mmxfdct.c
140         x86/x86enc.c
141         x86/mmxfrag.c
142         x86/mmxidct.c
143         x86/mmxstate.c
144         x86/x86state.c
145   """
146 elif conf.CheckHost_x86_64():
147   env.Append(CPPDEFINES=['OC_X86_ASM', 'OC_X86_64_ASM'])
148   decoder_sources += """
149         x86/mmxidct.c
150         x86/mmxfrag.c
151         x86/mmxstate.c
152         x86/x86state.c
153   """
154   encoder_sources += """
155         x86/mmxencfrag.c
156         x86/mmxfdct.c
157         x86/x86enc.c
158         x86/sse2fdct.c
159         x86/mmxfrag.c
160         x86/mmxidct.c
161         x86/mmxstate.c
162         x86/x86state.c
163   """
164
165 env = conf.Finish()
166
167 env.Append(CPPPATH=['include'])
168 env.ParseConfig('pkg-config --cflags --libs ogg')
169
170 libtheoradec_Sources = Split(decoder_sources)
171 libtheoraenc_Sources = Split(encoder_sources)
172
173 libtheoradec_a = env.Library('lib/theoradec',
174         path('lib', libtheoradec_Sources))
175 libtheoradec_so = env.SharedLibrary('lib/theoradec',
176         path('lib', libtheoradec_Sources))
177
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])
182
183 #installing
184 prefix='/usr'
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])
189
190 # example programs
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))
194
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))
199
200 if have_vorbis:
201   encex = dump_video.Clone()
202   encex.ParseConfig('pkg-config --cflags --libs vorbisenc vorbis')
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
210   if build_player_example:
211     plyex = encex.Clone()
212     plyex_Sources = Split("""
213         player_example.c
214         ../lib/libtheoradec.a
215     """)
216     plyex.ParseConfig('sdl-config --cflags --libs')
217     plyex.Program('examples/player_example', path('examples', plyex_Sources))
218
219 png2theora = env.Clone()
220 png2theora_Sources = Split("""png2theora.c
221         ../lib/libtheoraenc.a
222         ../lib/libtheoradec.a
223 """)
224 png2theora.ParseConfig('pkg-config --cflags --libs libpng')
225 png2theora.Program('examples/png2theora', path('examples', png2theora_Sources))