root/trunk/libffado/SConstruct

Revision 756, 11.3 kB (checked in by ppalmers, 16 years ago)

add optimization flags

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