root/branches/transport_redesign_2/Sconstruct @ 1111

Revision 1111, 18.5 KB (checked in by gabriel@…, 4 years ago)

Add check for Boost header.

Line 
1#                                  emacs: -*- python -*-
2# Hydrogen build script
3#
4
5# vim: set filetype=python
6# kate: syntax python
7
8import urllib
9import os
10import subprocess
11import sys
12import glob
13
14def printStatus( value ):
15    if str(value) == "1":
16        return "enabled"
17    else:
18        return "disabled"
19
20def recursiveDirs(root) :
21        return filter( ( lambda a : a.rfind( ".svn") == -1 ),  [ a[0] for a in os.walk( root ) ] )
22
23def unique( list ) :
24        return dict.fromkeys( list ).keys()
25
26def scanFiles(dir, accept=[ "*.cpp" ], reject=[] ) :
27        sources = []
28        paths = recursiveDirs( dir )
29        for path in paths:
30                for pattern in accept:
31                        sources += glob.glob( path + "/" + pattern )
32        for pattern in reject:
33                sources = filter( ( lambda a : a.rfind( pattern ) == -1 ),  sources )
34        return unique( sources )
35
36def subdirsContaining( root, patterns ):
37        dirs = unique( map( os.path.dirname, scanFiles( root, patterns ) ) )
38        dirs.sort()
39        return dirs
40
41
42
43def get_platform_flags( opts ):
44        includes = []
45        cppflags = []
46        ldflags = []
47
48        env = Environment( options = opts )
49
50        if sys.platform == "linux2" or sys.platform == "darwin":
51                if str(env['debug']) == "1":
52                        cppflags += ['-Wall',  '-g2', '-ggdb', '-O0']
53                        for flag in env["optflags"].split(" "):
54                                cppflags.append(flag)
55                       
56                else:
57                        cppflags += ['-O3', '-fomit-frame-pointer', '-funroll-loops']
58                        #cppflags += " %s" % get_optimized_flags( target_cpu )
59                        for flag in env["optflags"].split(" "):
60                                cppflags.append(flag)
61
62
63                if str(env['oss']) == "1": cppflags.append('-DOSS_SUPPORT')
64                if str(env['alsa']) == "1": cppflags.append('-DALSA_SUPPORT')
65                if str(env['jack']) == "1": cppflags.append('-DJACK_SUPPORT')
66                if str(env['lash']) == "1": cppflags.append('-DLASH_SUPPORT')
67                if str(env['lrdf']) == "1": cppflags.append('-DLRDF_SUPPORT')
68                if str(env['portaudio']) == "1": cppflags.append('-DPORTAUDIO_SUPPORT')
69                if str(env['portmidi']) == "1": cppflags.append('-DPORTMIDI_SUPPORT')
70                if str(env['flac']) == "1": cppflags.append('-DFLAC_SUPPORT')
71               
72                if sys.platform == "darwin" and str(env['coreaudio']) == "1": cppflags.append('-DCOREAUDIO_SUPPORT')
73
74                cppflags.append('-DLADSPA_SUPPORT')
75               
76
77
78        if str(env['libarchive']) == "1": cppflags.append('-DLIBARCHIVE_SUPPORT')
79
80        includes.append( './' )
81        includes.append( 'gui/src/' )
82        includes.append( '3rdparty/install/include' )
83
84        if sys.platform == 'linux2':
85                ldflags.append('-lasound')
86
87        elif sys.platform == 'darwin':
88                includes.append( [ '/sw/include', '/usr/local/include' ] )
89                ldflags.append( [ '-L/sw/lib', '-F/sw/lib', '-F/sw/lib/qt4-mac/lib', '-L/usr/local/lib' ] )
90
91        elif sys.platform == "win32":
92                includes.append( '3rdparty\libsndfile-1_0_17' )
93                includes.append( 'build\pthreads\include' )
94                includes.append( '3rdparty\libarchive\include' )
95                includes.append( 'windows\timeFix' )
96        else:
97                raise Exception( "Platform '%s' not supported" % sys.platform )
98
99        return (includes, cppflags, ldflags)
100
101
102
103def download_3rdparty_libs():
104        print " * Downloading required 3rdparty libraries"
105
106        curdir = os.path.abspath( os.path.curdir )
107
108        if sys.platform != "win32":
109                prefix = os.path.abspath( os.path.curdir ) + "/3rdparty/install"
110        else:
111                prefix = os.path.abspath( os.path.curdir ) + "\3rdparty\install"
112
113
114        compile_flags = "--enable-static --disable-shared"
115
116
117        if not os.path.exists( "3rdparty" ):
118                os.mkdir( "3rdparty" )
119       
120
121
122        if not os.path.exists( "3rdparty/install" ):
123                os.mkdir( "3rdparty/install" )
124
125        if not os.path.exists( "3rdparty/install/lib" ):
126                os.mkdir( "3rdparty/install/lib" )
127
128
129
130
131        if not os.path.exists( "3rdparty/libsndfile.tar.gz" ) and not os.path.exists("3rdparty/libsndfile.zip"):
132                if sys.platform != "win32":
133                        print " * Downloading libsndfile.tar.gz"
134                        urllib.urlretrieve("http://www.mega-nerd.com/libsndfile/libsndfile-1.0.17.tar.gz", "3rdparty/libsndfile.tar.gz")
135                else:
136                        print " * Downloading libsndfile.zip"
137                        urllib.urlretrieve("http://www.mega-nerd.com/libsndfile/libsndfile-1_0_17.zip", "3rdparty/libsndfile.zip")
138
139
140        if sys.platform != "win32":
141                #unix commands
142                if not os.path.exists( "3rdparty/install/lib/libsndfile.a" ):
143                        Execute( "cd 3rdparty; tar xzf libsndfile.tar.gz" )
144                        Execute( "cd 3rdparty/libsndfile-1.0.17; ./configure --disable-flac --prefix=%s %s" % (prefix, compile_flags) )
145                        res = Execute( "cd 3rdparty/libsndfile-1.0.17; make -j2; make install" )
146                        if res != 0:
147                                raise Exception( "Error compiling 3rdparty libraries" )
148        else:
149                #windows
150                if not os.path.exists( "3rdparty\install\lib\libsndfile-1.dll" ):
151                        Execute( "unzip 3rdparty\libsndfile.zip -d 3rdparty" )
152                        Execute( "copy 3rdparty\libsndfile-1_0_17\libsndfile-1.dll 3rdparty\install\lib")
153                        Execute( "copy 3rdparty\libsndfile-1_0_17\sndfile.h 3rdparty\install\lib")
154
155
156
157
158def get_svn_revision():
159       
160        if sys.platform != "win32":
161                p = subprocess.Popen("svnversion -n", shell=True, stdout=subprocess.PIPE)
162                return p.stdout.read()
163        else:
164                return "win32 build"
165
166
167def get_hydrogen_lib( opts ):
168        includes, cppflags, ldflags = get_platform_flags( opts )
169
170        includes.append( "libs/hydrogen/include" )
171       
172        env = Environment( options = opts )
173        if str(env['lash']) == "1": includes.append( "/usr/include/lash-1.0")
174
175        # Alwasys build the tests in debug.
176        cppflags += ['-Wall',  '-g2', '-ggdb', '-O0']
177
178        #location of qt4.py
179        qt4ToolLocation="."
180
181        env = Environment(options = opts , tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
182        env.EnableQt4Modules( ['QtCore', 'QtGui'], debug=False)
183        env.CacheDir( "scons_cache" )
184       
185
186        if str(env['jack']) == "1":
187            env.ParseConfig('pkg-config --modversion jack', get_jack_api_flags)
188
189
190        #env.Decider is not known in older scons version
191        try:
192                env.Decider( "MD5-timestamp" )
193        except AttributeError:
194                env.SourceSignatures('MD5')
195
196
197        src = scanFiles( "libs/hydrogen", ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
198        src.append( "version.cpp" )
199
200        static_lib = env.StaticLibrary(target = 'hydrogen', source = src )
201        return static_lib
202
203def runUnitTest(env, target, source):
204    app = str(source[0].abspath)
205    if not subprocess.call(app):
206        open(str(target[0], 'w').write("PASSED\n"))
207
208# Courtesy Dov Grobgeld 2005-12-18 on the scons Wiki
209def builder_unit_test(target, source, env):
210    app = str(source[0].abspath)
211    if os.spawnl(os.P_WAIT, app, app, "--log_level=message", "--report_level=short")==0:
212        open(str(target[0]),'w').write("PASSED\n")
213    else:
214        return 1
215
216
217def get_hydrogen_lib_tests( h2lib, opts ):
218        includes, cppflags, ldflags = get_platform_flags( opts )
219
220        includes.append( "libs/hydrogen/include" )
221       
222        env = Environment( options = opts )
223        if str(env['lash']) == "1": includes.append( "/usr/include/lash-1.0")
224
225
226        #location of qt4.py
227        qt4ToolLocation="."
228
229        ldflags.append( "-L." )
230        cppflags.append( "-DBOOST_TEST_DYN_LINK" )
231
232        env = Environment(options = opts , tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
233        env.EnableQt4Modules( ['QtCore', 'QtGui'], debug=False)
234        env.CacheDir( "scons_cache" )
235       
236        env.Append( LIBS = "hydrogen" )
237        env.Append( LIBS = "boost_unit_test_framework" )
238
239        if str(env['jack']) == "1":
240            env.ParseConfig('pkg-config --modversion jack', get_jack_api_flags)
241
242
243        #env.Decider is not known in older scons version
244        try:
245                env.Decider( "MD5-timestamp" )
246        except AttributeError:
247                env.SourceSignatures('MD5')
248
249        # Create a builder for unit tests
250        bld = Builder(action = builder_unit_test)
251        env.Append(BUILDERS = {'Test' :  bld})
252
253        src = scanFiles( "test", ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
254
255        tests = env.Program(target = 't_Hydrogen', source = src)
256        env.Alias("test", tests)
257        env.Test("tests.passed", tests)
258        env.Alias("test", "tests.passed")
259
260        return tests
261
262
263def install_images( arg , dir , files):
264        #install all image files in a subdirectory
265        for file in files:
266                if file.endswith(".png"):
267                       
268                        if env['prefix'].endswith("/"):
269                                dname = dir[2:] 
270                        else:
271                                dname = dir[1:] 
272
273                        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/' + dname, source= dir + "/" + file))
274
275def get_hydrogen_gui( lib_hydrogen , opts ):
276        includes, cppflags, ldflags = get_platform_flags( opts )
277
278        includes.append( "libs/hydrogen/include" )
279        includes.append( "gui/src/UI" )
280        includes.append( "/usr/include/lash-1.0")
281
282        #location of qt4.py
283        qt4ToolLocation="."
284
285        env = Environment(options = opts , tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
286       
287        env.EnableQt4Modules( ['QtCore', 'QtGui','QtNetwork','QtXml'], debug=False)
288        #
289        env.CacheDir( "scons_cache" )
290       
291        #env.Decider is not known in older scons version
292        try:
293                env.Decider( "MD5-timestamp" )
294        except AttributeError:
295                env.SourceSignatures('MD5')
296
297        # rcc needs a -name flag because examples use identified resource files
298        def takebasename(file):
299                return os.path.splitext(os.path.basename(file))[0]
300
301
302        directory = "gui"
303
304        resources = [ env.Qrc( qrc, QT4_QRCFLAGS = '-name ' + takebasename( qrc ) ) for qrc in scanFiles(directory, ['*.qrc'] ) ]
305        interfaces = [ env.Uic4( uic ) for uic in scanFiles(directory, ['*.ui'] ) ]
306
307
308        src = scanFiles( directory, ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
309
310        env.Append( LIBS = lib_hydrogen )
311        env.Append( LIBS = ["sndfile"] )
312       
313        if str(env['lrdf']) == "1": env.Append( LIBS = ["lrdf"] )
314        if str(env['flac']) == "1": env.Append( LIBS = ["FLAC","FLAC++"] )
315        if str(env['lash']) == "1": env.Append( LIBS = ["lash"])
316        if str(env['jack']) == "1": env.Append( LIBS = ["jack"])
317        if str(env['alsa']) == "1": env.Append( LIBS = ["asound"])
318        if str(env['libarchive']) == "1": env.Append( LIBS = ["archive"])
319        else: env.Append( LIBS = ["tar"])
320        if str(env['portaudio']) == "1": env.Append( LIBS = [ "portaudio" ] )
321        if str(env['portmidi']) == "1":
322                env.Append( LIBS = [ "portmidi" ] )
323                env.Append( LIBS = [ "porttime" ] )
324
325        if sys.platform == "darwin":
326                env.Append( LIBS = ["z"] )
327
328        if sys.platform == "darwin" and str(env['coreaudio']) == "1":
329                env.Append( LINKFLAGS = ['-framework','ApplicationServices'])
330                env.Append( LINKFLAGS = ['-framework','AudioUnit'])
331                env.Append( LINKFLAGS = ['-framework','Coreaudio'])
332
333
334
335        env.Append( LIBPATH = '3rdparty\libsndfile-1_0_17' )
336        env.Append( LIBPATH = 'build\pthreads\lib' )
337
338        app = env.Program(target = 'hydrogen', source = src )
339
340        env.Alias('programs', app)
341        env.Default('programs')
342
343        for N in glob.glob('./data/i18n/hydrogen.*'):
344            env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data/i18n', source=N))
345        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/img"))
346
347        #add every img in ./data/img to the install list.
348        os.path.walk("./data/img/",install_images,env)
349
350
351        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/drumkits"))
352        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/demo_songs"))
353        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/hydrogen.default.conf"))
354        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/emptySample.wav"))
355        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/click.wav"))
356        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/doc"))
357        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/DefaultSong.h2song"))
358        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/bin/', source="./hydrogen"))
359        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/applications', source="./hydrogen.desktop"))
360        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/pixmaps', source="./data/img/gray/h2-icon.svg"))
361
362
363        return app
364
365def get_jack_api_flags(xenv, pkg_ver):
366    (major, minor, patch) = pkg_ver.rstrip().split('.')
367    major = int(major)
368    minor = int(minor)
369    patch = int(patch)
370    rv = ""
371    if (major == 0) and (minor < 102):
372        rv = "-DJACK_NO_BBT_OFFSET"
373    if (major == 0) and (minor == 102) and (patch < 4):
374        rv = "-DJACK_NO_BBT_OFFSET"
375    xenv.MergeFlags(rv)
376
377opts = Options('scache.conf')
378
379#platform independent settings
380opts.Add('debug', 'Set to 1 to build with debug informations', 0)
381opts.Add('libarchive', 'Set to 1 to enable libarchive instead of libtar', 0)
382opts.Add('prefix','Default: /usr/local',"/usr/local")
383opts.Add('DESTDIR','Default: none',"")
384opts.Add('optflags','Default: none',"")
385
386#platform dependent settings
387if sys.platform == "darwin":
388        opts.Add('coreaudio', 'Set to 1 to enable Coreaudio',1)
389
390if sys.platform != "win32":
391        opts.Add('oss', 'Set to 1 to enable oss',1)
392
393        opts.Add('portmidi', 'Set to 1 to enable portmidi',0)
394       
395        opts.Add('portaudio', 'Set to 1 to enable portaudio',0)
396       
397        opts.Add('lash', 'Set to 1 to enable lash',0)
398       
399        opts.Add('alsa', 'Set to 1 to enable alsa',1)
400       
401        opts.Add('jack', 'Set to 1 to enable jack',1)   
402       
403        opts.Add('lrdf', 'Set to 1 to enable lrdf',1)
404       
405        opts.Add('flac', 'Set to 1 to enable flac',1)
406else:
407        #alsa, lash,oss and jack are not available on windows
408        opts.Add('portmidi', 'Set to 1 to enable portmidi',1)
409       
410        opts.Add('portaudio', 'Set to 1 to enable portaudio',1)
411       
412        opts.Add('oss', 'Set to 1 to enable oss',0)
413
414        opts.Add('lash', 'Set to 1 to enable lash',0)
415       
416        opts.Add('alsa', 'Set to 1 to enable alsa',0)
417       
418        opts.Add('jack', 'Set to 1 to enable jack',0)
419       
420        opts.Add('lrdf', 'Set to 1 to enable lrdf',0)
421       
422        opts.Add('flac', 'Set to 1 to enable flac',0)
423
424
425
426#get includes ( important if you compile on non-standard envorionments)
427
428includes, a , b = get_platform_flags( opts )
429
430env = Environment(options = opts, CPPPATH = includes)
431
432
433Help(opts.GenerateHelpText(env))
434
435
436platform = sys.platform
437
438#just download 3rd party libs if we're *not* running linux.
439#We trust in our package managment system!
440if platform == "darwin" or platform == "win32":
441    download_3rdparty_libs()
442
443
444
445#Check if all required libraries are installed
446conf = Configure(env)
447if not conf.CheckCHeader('sndfile.h'):
448    print 'libsndfile must be installed!'
449    Exit(1)
450
451
452
453# it seems that conf.CheckCHeader  dislikes like the "++" in filenames
454#if not conf.CheckCHeader('FLAC++/all.h'):
455#   print 'FLAC++ must be installed!'
456#   Exit(1)
457
458
459# these libraries are optional (can be enabled/disabled, see 'scons -h')
460
461if str(env['portaudio']) == "1" and not conf.CheckCHeader('portaudio.h'):
462    print "portaudio must be installed!"
463    Exit(1)
464
465if str(env['portmidi']) == "1" and not conf.CheckCHeader('portmidi.h'):
466    print "portmidi must be installed!"
467    Exit(1)
468
469
470#alsa: (default: enabled)
471if str(env['alsa']) == "1" and not conf.CheckCHeader('alsa/asoundlib.h'):
472    print 'alsa must be installed!'
473    Exit(1)
474
475#jack: (default: enabled)
476if str(env['jack']) == "1" and not conf.CheckCHeader('jack/jack.h'):
477    print 'jack must be installed!'
478    Exit(1)
479
480#lash: (default: disabled)
481if str(env['lash']) == "1" and not os.path.isdir("/usr/include/lash-1.0"):
482    print 'liblash must be installed!'
483    Exit(1)
484
485#libarchive: (default: disabled)
486if str(env['libarchive']) == "1" and not conf.CheckCHeader("archive.h"):
487    print 'libarchive must be installed!'
488    Exit(1)
489#libtar: needed if not libarchive
490elif not str(env['libarchive']) == "1" and not conf.CheckCHeader("zlib.h"):
491   print 'zlib devel package must be installed!'
492   Exit(1)
493elif not str(env['libarchive']) == "1" and not conf.CheckCHeader("libtar.h"):
494   print 'libtar must be installed!'
495   Exit(1)
496
497#lrdf: categorizing of ladspa effects
498if str(env['lrdf']) == "1" and not conf.CheckCHeader('lrdf.h'):
499    print 'lrdf must be installed!'
500    Exit(1)
501
502#flac: support for flac samples
503if str(env['flac']) == "1" and not conf.CheckCHeader('FLAC/all.h'):
504    print 'FLAC must be installed!'
505    Exit(1)
506
507#boost:  If building a 'test', make sure we have Boost UTF
508if 'test' in COMMAND_LINE_TARGETS and not conf.CheckCXXHeader("boost/test/unit_test.hpp"):
509    print "To build tests, you must have the Boost Unit Test Framework installed."
510    Exit(1)
511
512
513print ""
514print "================================================================="
515print " Hydrogen build script"
516print ""
517print " Revision: %s" % get_svn_revision()
518print " Platform: %s" % platform
519
520if str(env['debug']) == "1" :
521        print " Debug build"
522else:
523        print " Release build"
524
525print " Prefix: " + env['prefix']
526print " Destdir: " + env['DESTDIR']
527print "================================================================="
528print "Feature Overview:\n"
529
530
531print "      lash: " + printStatus( env["lash"] )
532print "      oss: " + printStatus( env["oss"] )
533print "      alsa: " + printStatus( env["alsa"] )
534print "      jack: " + printStatus( env["jack"] )
535print "libarchive: " + printStatus( env["libarchive"] )
536print " portaudio: " + printStatus( env["portaudio"] )
537print "  portmidi: " + printStatus( env["portmidi"] )
538if sys.platform == "darwin":
539        print " coreaudio: " + printStatus( env["coreaudio"] )
540
541print "\n================================================================="
542print ""
543
544# write the config.h file
545conf = open("config.h", "w")
546
547conf.write( "#ifndef HYD_CONFIG_H\n" )
548conf.write( "#define HYD_CONFIG_H\n" )
549conf.write( "#include <string>\n" )
550
551
552if str(env['debug']) == "1": conf.write( "#define CONFIG_DEBUG\n" )
553if str(env['lash']) == "1": conf.write( "#define LASH\n" )
554
555conf.write( "#ifndef QT_BEGIN_NAMESPACE\n" )
556conf.write( "#    define QT_BEGIN_NAMESPACE\n" )
557conf.write( "#endif\n" )
558conf.write( "#ifndef QT_END_NAMESPACE\n" )
559conf.write( "#    define QT_END_NAMESPACE\n" )
560conf.write( "#endif\n" )
561
562conf.write( "#define CONFIG_PREFIX \"%s\"\n" % env['prefix'] )
563conf.write( "#define DATA_PATH \"%s/share/hydrogen/data\"\n" % env['prefix'] )
564
565conf.write( "#endif\n" )
566
567conf.close()
568
569version = open("version.cpp", "w")
570version.write( "// autogenerated by Sconstruct script\n" )
571version.write( '#include "version.h"\n' )
572version.write( '#include "config.h"\n' )
573version.write( "static const std::string extra_version = \"svn%s\";\n" % get_svn_revision() )
574version.write( "static const std::string VERSION = \"0.9.4-\" + extra_version;\n" )
575version.write( "std::string get_version() { return VERSION;     }\n" )
576version.close()
577
578
579libhyd = get_hydrogen_lib( opts )
580app = get_hydrogen_gui( libhyd , opts )
581tests = get_hydrogen_lib_tests( libhyd, opts )
582
583opts.Save("scache.conf",env)
Note: See TracBrowser for help on using the browser.