root/trunk/libffado/SConstruct

Revision 777, 11.4 kB (checked in by ppalmers, 16 years ago)

port freebob SSE optimized event encoding functions (untested)

Line 
1 #! /usr/bin/python
2 #
3 # Copyright (C) 2007 Arnold Krille
4 # Copyright (C) 2007 Pieter Palmers
5 #
6 # This file is part of FFADO
7 # FFADO = Free Firewire (pro-)audio drivers for linux
8 #
9 # FFADO is based upon FreeBoB.
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 #
24
25 import os
26 import re
27 from string import Template
28
29 build_dir = ARGUMENTS.get('BUILDDIR', "")
30 if build_dir:
31         build_base=build_dir+'/'
32         if not os.path.isdir( build_base ):
33                 os.makedirs( build_base )
34         print "Building into: " + build_base
35 else:
36         build_base=''
37
38 if not os.path.isdir( "cache" ):
39         os.makedirs( "cache" )
40
41 opts = Options( "cache/"+build_base+"options.cache" )
42
43 #
44 # If this is just to display a help-text for the variable used via ARGUMENTS, then its wrong...
45 opts.Add( "BUILDDIR", "Path to place the built files in", "")
46
47 opts.AddOptions(
48         BoolOption( "DEBUG", """\
49 Toggle debug-build. DEBUG means \"-g -Wall\" and more, otherwise we will use
50   \"-O2\" to optimise.""", True ),
51         PathOption( "PREFIX", "The prefix where ffado will be installed to.", "/usr/local", PathOption.PathAccept ),
52         PathOption( "BINDIR", "Overwrite the directory where apps are installed to.", "$PREFIX/bin", PathOption.PathAccept ),
53         PathOption( "LIBDIR", "Overwrite the directory where libs are installed to.", "$PREFIX/lib", PathOption.PathAccept ),
54         PathOption( "INCLUDEDIR", "Overwrite the directory where headers are installed to.", "$PREFIX/include", PathOption.PathAccept ),
55         PathOption( "SHAREDIR", "Overwrite the directory where misc shared files are installed to.", "$PREFIX/share/libffado", PathOption.PathAccept ),
56         BoolOption( "ENABLE_BEBOB", "Enable/Disable the bebob part.", True ),
57         BoolOption( "ENABLE_FIREWORKS", "Enable/Disable the ECHO Audio FireWorks avc part.", True ),
58         BoolOption( "ENABLE_MOTU", "Enable/Disable the Motu part.", True ),
59         BoolOption( "ENABLE_DICE", "Enable/Disable the DICE part.", False ),
60         BoolOption( "ENABLE_METRIC_HALO", "Enable/Disable the Metric Halo part.", False ),
61         BoolOption( "ENABLE_RME", "Enable/Disable the RME part.", False ),
62         BoolOption( "ENABLE_BOUNCE", "Enable/Disable the BOUNCE part.", False ),
63         BoolOption( "ENABLE_GENERICAVC", """\
64 Enable/Disable the the generic avc part (mainly used by apple).
65   Note that disabling this option might be overwritten by other devices needing
66   this code.""", False ),
67         BoolOption( "ENABLE_ALL", "Enable/Disable support for all devices.", False ),
68         BoolOption( "BUILD_TESTS", """\
69 Build the tests in their directory. As some contain quite some functionality,
70   this is on by default.
71   If you just want to use ffado with jack without the tools, you can disable this.\
72 """, True ),
73     BoolOption( "BUILD_STATIC_TOOLS", "Build a statically linked version of the FFADO tools.", False ),
74     EnumOption('DIST_TARGET', 'Build target for cross compiling packagers', 'auto', allowed_values=('auto', 'i386', 'i686', 'x86_64', 'none' ), ignorecase=2),
75     BoolOption( "ENABLE_OPTIMIZATIONS", "Enable optimizations and the use of processor specific extentions (MMX/SSE/...).", False ),
76
77         )
78
79 ## Load the builders in config
80 buildenv={}
81 if os.environ.has_key('PATH'):
82         buildenv['PATH']=os.environ['PATH']
83 else:
84         buildenv['PATH']=''
85
86 if os.environ.has_key('PKG_CONFIG_PATH'):
87         buildenv['PKG_CONFIG_PATH']=os.environ['PKG_CONFIG_PATH']
88 else:
89         buildenv['PKG_CONFIG_PATH']=''
90
91 if os.environ.has_key('LD_LIBRARY_PATH'):
92         buildenv['LD_LIBRARY_PATH']=os.environ['LD_LIBRARY_PATH']
93 else:
94         buildenv['LD_LIBRARY_PATH']=''
95
96
97 env = Environment( tools=['default','scanreplace','pyuic','dbus','doxygen','pkgconfig'], toolpath=['admin'], ENV = buildenv, options=opts )
98
99
100 Help( """
101 For building ffado you can set different options as listed below. You have to
102 specify them only once, scons will save the last value you used and re-use
103 that.
104 To really undo your settings and return to the factory defaults, remove the
105 "cache"-folder and the file ".sconsign.dblite" from this directory.
106 For example with: "rm -Rf .sconsign.dblite cache"
107
108 Note that this is a development version! Don't complain if its not working!
109 See www.ffado.org for stable releases.
110 """ )
111 Help( opts.GenerateHelpText( env ) )
112
113 # make sure the necessary dirs exist
114 if not os.path.isdir( "cache/" + build_base ):
115         os.makedirs( "cache/" + build_base )
116 if not os.path.isdir( 'cache/objects' ):
117         os.makedirs( 'cache/objects' )
118
119 CacheDir( 'cache/objects' )
120
121 opts.Save( 'cache/' + build_base + "options.cache", env )
122
123 def ConfigGuess( context ):
124         context.Message( "Trying to find the system triple: " )
125         ret = os.popen( "admin/config.guess" ).read()[:-1]
126         context.Result( ret )
127         return ret
128
129 tests = { "ConfigGuess" : ConfigGuess }
130 tests.update( env['PKGCONFIG_TESTS'] )
131 tests.update( env['PYUIC_TESTS'] )
132
133 conf = Configure( env,
134         custom_tests = tests,
135         conf_dir = "cache/" + build_base,
136         log_file = "cache/" + build_base + 'config.log' )
137
138 if not env.GetOption('clean'):
139         #
140         # Check if the environment can actually compile c-files by checking for a
141         # header shipped with gcc.
142         #
143         if not conf.CheckHeader( "stdio.h" ):
144                 print "It seems as if stdio.h is missing. This probably means that your build environment is broken, please make sure you have a working c-compiler and libstdc installed and usable."
145                 Exit( 1 )
146
147         #
148         # The following checks are for headers and libs and packages we need.
149         #
150         allpresent = 1;
151         allpresent &= conf.CheckHeader( "expat.h" )
152         allpresent &= conf.CheckLib( 'expat', 'XML_ExpatVersion', '#include <expat.h>' )
153        
154         allpresent &= conf.CheckForPKGConfig();
155
156         pkgs = {
157                 'libraw1394' : '1.3.0',
158                 'libavc1394' : '0.5.3',
159                 'libiec61883' : '1.1.0',
160                 'alsa' : '1.0.0',
161                 'libxml++-2.6' : '2.13.0',
162                 'dbus-1' : '1.0',
163                 }
164         for pkg in pkgs:
165                 name2 = pkg.replace("+","").replace(".","").replace("-","").upper()
166                 env['%s_FLAGS' % name2] = conf.GetPKGFlags( pkg, pkgs[pkg] )
167                 if env['%s_FLAGS'%name2] == 0:
168                         allpresent &= 0
169
170         if not allpresent:
171                 print """
172 (At least) One of the dependencies is missing. I can't go on without it, please
173 install the needed packages (remember to also install the *-devel packages)
174 """
175                 Exit( 1 )
176
177         #
178         # Optional checks follow:
179         #
180         env['ALSA_SEQ_OUTPUT'] = conf.CheckLib( 'asound', symbol='snd_seq_event_output_direct', autoadd=0 )
181
182 if conf.PyQtCheck():
183         env['PYUIC'] = True
184
185 config_guess = conf.ConfigGuess()
186
187 env = conf.Finish()
188
189 if env['DEBUG']:
190         print "Doing a DEBUG build"
191         # -Werror could be added to, which would force the devs to really remove all the warnings :-)
192         env.AppendUnique( CCFLAGS=["-DDEBUG","-Wall","-g"] ) # HACK!!
193 else:
194         env.AppendUnique( CCFLAGS=["-O2","-DNDEBUG"] )
195
196 # this is required to indicate that the DBUS version we use has support
197 # for platform dependent threading init functions
198 # this is true for DBUS >= 0.96 or so. Since we require >= 1.0 it is
199 # always true
200 env.AppendUnique( CCFLAGS=["-DDBUS_HAS_THREADS_INIT_DEFAULT"] )
201
202 if env['ENABLE_ALL']:
203         env['ENABLE_BEBOB'] = True
204         env['ENABLE_FIREWORKS'] = True
205         env['ENABLE_MOTU'] = True
206         env['ENABLE_DICE'] = True
207         env['ENABLE_METRIC_HALO'] = True
208         env['ENABLE_RME'] = True
209         env['ENABLE_BOUNCE'] = True
210
211 if env['ENABLE_BEBOB'] or env['ENABLE_DICE'] or env['ENABLE_BOUNCE'] or env['ENABLE_FIREWORKS']:
212         env['ENABLE_GENERICAVC'] = True
213
214 env['BUILD_STATIC_LIB'] = False
215 if env['BUILD_STATIC_TOOLS']:
216     print "Building static versions of the tools..."
217     env['BUILD_STATIC_LIB'] = True
218
219 if build_base:
220         env['build_base']="#/"+build_base
221 else:
222         env['build_base']="#/"
223
224 #
225 # XXX: Maybe we can even drop these lower-case variables and only use the uppercase ones?
226 #
227 env['bindir'] = Template( os.path.join( env['BINDIR'] ) ).safe_substitute( env )
228 env['libdir'] = Template( os.path.join( env['LIBDIR'] ) ).safe_substitute( env )
229 env['includedir'] = Template( os.path.join( env['INCLUDEDIR'] ) ).safe_substitute( env )
230 env['sharedir'] = Template( os.path.join( env['SHAREDIR'] ) ).safe_substitute( env )
231
232 env.Command( target=env['sharedir'], source="", action=Mkdir( env['sharedir'] ) )
233
234 env.Alias( "install", env['libdir'] )
235 env.Alias( "install", env['includedir'] )
236 env.Alias( "install", env['sharedir'] )
237 env.Alias( "install", env['bindir'] )
238
239 #
240 # shamelessly copied from the Ardour scons file
241 #
242
243 opt_flags = []
244 env['USE_SSE'] = 0
245
246 # guess at the platform, used to define compiler flags
247
248 config_cpu = 0
249 config_arch = 1
250 config_kernel = 2
251 config_os = 3
252 config = config_guess.split ("-")
253
254 # Autodetect
255 if env['DIST_TARGET'] == 'auto':
256     if re.search ("x86_64", config[config_cpu]) != None:
257         env['DIST_TARGET'] = 'x86_64'
258     elif re.search("i[0-5]86", config[config_cpu]) != None:
259         env['DIST_TARGET'] = 'i386'
260     else:
261         env['DIST_TARGET'] = 'i686'
262     print "Detected DIST_TARGET = " + env['DIST_TARGET']
263
264 if ((re.search ("i[0-9]86", config[config_cpu]) != None) or (re.search ("x86_64", config[config_cpu]) != None)):
265    
266     build_host_supports_sse = 0
267
268     if config[config_kernel] == 'linux' :
269        
270         if env['DIST_TARGET'] != 'i386':
271            
272             flag_line = os.popen ("cat /proc/cpuinfo | grep '^flags'").read()[:-1]
273             x86_flags = flag_line.split (": ")[1:][0].split ()
274            
275             if "mmx" in x86_flags:
276                 opt_flags.append ("-mmmx")
277             if "sse" in x86_flags:
278                 build_host_supports_sse = 1
279             if "3dnow" in x86_flags:
280                 opt_flags.append ("-m3dnow")
281            
282             if config[config_cpu] == "i586":
283                 opt_flags.append ("-march=i586")
284             elif config[config_cpu] == "i686":
285                 opt_flags.append ("-march=i686")
286    
287     if ((env['DIST_TARGET'] == 'i686') or (env['DIST_TARGET'] == 'x86_64')) \
288        and build_host_supports_sse and env['ENABLE_OPTIMIZATIONS']:
289         opt_flags.extend (["-msse", "-mfpmath=sse"])
290         env['USE_SSE'] = 1
291
292 # end of processor-specific section
293 if env['ENABLE_OPTIMIZATIONS']:
294         env.AppendUnique( CCFLAGS=opt_flags )
295         print "Doing an optimized build..."
296
297
298 env['REVISION'] = os.popen('svnversion .').read()[:-1]
299 # This may be as simple as '89' or as complex as '4123:4184M'.
300 # We'll just use the last bit.
301 env['REVISION'] = env['REVISION'].split(':')[-1]
302
303 if env['REVISION'] == 'exported':
304         env['REVISION'] = ''
305
306 env['FFADO_API_VERSION']="5"
307
308 env['PACKAGE'] = "libffado"
309 env['VERSION'] = "1.999.10"
310 env['LIBVERSION'] = "1.0.0"
311
312 #
313 # To have the top_srcdir as the doxygen-script is used from auto*
314 #
315 env['top_srcdir'] = env.Dir( "." ).abspath
316
317 #
318 # Start building
319 #
320 env.ScanReplace( "config.h.in" )
321 # ensure that the config.h is updated with the version
322 env.Depends( "config.h", "SConstruct" )
323
324 pkgconfig = env.ScanReplace( "libffado.pc.in" )
325 env.Install( env['libdir'] + '/pkgconfig', pkgconfig )
326
327 subdirs=['external','src','libffado','tests','support','doc']
328 if build_base:
329         env.SConscript( dirs=subdirs, exports="env", build_dir=build_base+subdir )
330 else:
331         env.SConscript( dirs=subdirs, exports="env" )
332
333 if 'debian' in COMMAND_LINE_TARGETS:
334         env.SConscript("deb/SConscript", exports="env")
335
336 # By default only src is built but all is cleaned
337 if not env.GetOption('clean'):
338     Default( 'external' )
339     Default( 'src' )
340     Default( 'support' )
341     if env['BUILD_TESTS']:
342         Default( 'tests' )
343
Note: See TracBrowser for help on using the browser.