root/branches/jackMidi/Sconstruct @ 538

Revision 538, 15.6 KB (checked in by gabriel, 5 years ago)

Merge rev 465:505 from trunk

Line 
1#
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 value:
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():
44        includes = []
45        cppflags = []
46        ldflags = []
47
48        if sys.platform == "linux2" or sys.platform == "darwin":
49                if debug:
50                        cppflags += ['-Wall',  '-g2', '-ggdb', '-O0']
51                else:
52                        cppflags += ['-O3', '-fomit-frame-pointer', '-funroll-loops']
53                        #cppflags += " %s" % get_optimized_flags( target_cpu )
54
55                if alsa: cppflags.append('-DALSA_SUPPORT')
56                if jack: cppflags.append('-DJACK_SUPPORT')
57                if lash: cppflags.append('-DLASH_SUPPORT')
58                if lrdf: cppflags.append('-DLRDF_SUPPORT')
59                if portaudio: cppflags.append('-DPORTAUDIO_SUPPORT')
60                if portmidi: cppflags.append('-DPORTMIDI_SUPPORT')
61
62
63                cppflags.append('-DFLAC_SUPPORT')
64                cppflags.append('-DLADSPA_SUPPORT')
65                cppflags.append('-DOSS_SUPPORT')
66
67
68                includes.append( '/usr/lib/lash-1.0' )
69
70        if libarchive: cppflags.append('-DLIBARCHIVE_SUPPORT')
71
72        includes.append( './' )
73        includes.append( 'gui/src/' )
74        includes.append( '3rdparty/install/include' )
75
76        if sys.platform == 'linux2':
77                ldflags.append('-lasound')
78
79        elif sys.platform == 'darwin':
80                pass
81        elif sys.platform == "win32":
82                includes.append( '3rdparty\install\include' )
83                includes.append( 'build\pthreads\include' )
84                includes.append( '3rdparty\libarchive\include' )
85                includes.append( 'windows\timeFix' )
86        else:
87                raise Exception( "Platform '%s' not supported" % sys.platform )
88
89        return (includes, cppflags, ldflags)
90
91
92
93def download_3rdparty_libs():
94        print " * Downloading required 3rdparty libraries"
95
96        curdir = os.path.abspath( os.path.curdir )
97
98        if sys.platform != "win32":
99                prefix = os.path.abspath( os.path.curdir ) + "/3rdparty/install"
100        else:
101                prefix = os.path.abspath( os.path.curdir ) + "\3rdparty\install"
102
103
104        compile_flags = "--enable-static --disable-shared"
105
106
107        if not os.path.exists( "3rdparty" ):
108                os.mkdir( "3rdparty" )
109
110        if not os.path.exists( "3rdparty/install" ):
111                os.mkdir( "3rdparty/install" )
112
113        if not os.path.exists( "3rdparty/install/lib" ):
114                os.mkdir( "3rdparty/install/lib" )
115
116
117
118
119        if not os.path.exists( "3rdparty/libsndfile.tar.gz" ) and not os.path.exists("3rdparty/libsndfile.zip"):
120                if sys.platform != "win32":
121                        print " * Downloading libsndfile.tar.gz"
122                        urllib.urlretrieve("http://www.mega-nerd.com/libsndfile/libsndfile-1.0.17.tar.gz", "3rdparty/libsndfile.tar.gz")
123                else:
124                        print " * Downloading libsndfile.zip"
125                        urllib.urlretrieve("http://www.mega-nerd.com/libsndfile/libsndfile-1_0_17.zip", "3rdparty/libsndfile.zip")
126
127
128        if sys.platform != "win32":
129                #unix commands
130                if not os.path.exists( "3rdparty/install/lib/libsndfile.a" ):
131                        Execute( "cd 3rdparty; tar xzf libsndfile.tar.gz" )
132                        Execute( "cd 3rdparty/libsndfile-1.0.17; ./configure --disable-flac --prefix=%s %s" % (prefix, compile_flags) )
133                        res = Execute( "cd 3rdparty\libsndfile-1.0.17; make -j2; make install" )
134                        if res != 0:
135                                raise Exception( "Error compiling 3rdparty libraries" )
136        else:
137                #windows
138                if not os.path.exists( "3rdparty\install\lib\libsndfile-1.dll" ):
139                        Execute( "unzip 3rdparty\libsndfile.zip -d 3rdparty" )
140                        Execute( "copy 3rdparty\libsndfile-1_0_17\libsndfile-1.dll 3rdparty\install\lib")
141                        Execute( "copy 3rdparty\libsndfile-1_0_17\sndfile.h 3rdparty\install\lib")
142
143
144
145
146def get_svn_revision():
147        p = subprocess.Popen("svnversion -n", shell=True, stdout=subprocess.PIPE)
148        return p.stdout.read()
149
150
151
152def get_hydrogen_lib():
153        includes, cppflags, ldflags = get_platform_flags()
154
155        includes.append( "libs/hydrogen/include" )
156        includes.append( "/usr/include/lash-1.0")
157
158        #location of qt4.py
159        qt4ToolLocation="."
160
161        env = Environment(tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
162        env.EnableQt4Modules( ['QtCore', 'QtGui'], debug=False)
163        env.CacheDir( "scons_cache" )
164       
165        if jack:
166            env.ParseConfig('pkg-config --modversion jack', get_jack_api_flags)
167
168        #env.Decider is not known in older scons version
169        try:
170                env.Decider( "MD5-timestamp" )
171        except AttributeError:
172                env.SourceSignatures('MD5')
173
174
175        if jack:
176            env.ParseConfig('pkg-config --modversion jack', get_jack_midi_api_version)   
177
178        src = scanFiles( "libs/hydrogen", ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
179        src.append( "version.cpp" )
180
181        static_lib = env.StaticLibrary(target = 'hydrogen', source = src )
182        return static_lib
183
184
185def get_hydrogen_gui( lib_hydrogen ):
186        includes, cppflags, ldflags = get_platform_flags()
187
188        includes.append( "libs/hydrogen/include" )
189        includes.append( "gui/src/UI" )
190        includes.append( "/usr/include/lash-1.0")
191
192        #location of qt4.py
193        qt4ToolLocation="."
194
195        env = Environment(tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
196       
197        #hi, can't compile h2 with Qt3Support on my linux machines anymore (debian unstable & ubuntu )
198        #, although i have correct installed "libqt4-qt3support"
199        #after correct one error into SoundLibraryPanal.cpp i get linking or what ever errors (sorry never seen before) after compiling.
200        #so, think it is better to disable qt3 support for now
201        #
202        #env.EnableQt4Modules( ['QtCore', 'QtGui','QtNetwork','QtXml','Qt3Support'], debug=False)
203        #
204        env.EnableQt4Modules( ['QtCore', 'QtGui','QtNetwork','QtXml'], debug=False)
205        #
206        env.CacheDir( "scons_cache" )
207       
208        #env.Decider is not known in older scons version
209        try:
210                env.Decider( "MD5-timestamp" )
211        except AttributeError:
212                env.SourceSignatures('MD5')
213
214        # rcc needs a -name flag because examples use identified resource files
215        def takebasename(file):
216                return os.path.splitext(os.path.basename(file))[0]
217
218
219        directory = "gui"
220
221        resources = [ env.Qrc( qrc, QT4_QRCFLAGS = '-name ' + takebasename( qrc ) ) for qrc in scanFiles(directory, ['*.qrc'] ) ]
222        interfaces = [ env.Uic4( uic ) for uic in scanFiles(directory, ['*.ui'] ) ]
223
224
225        src = scanFiles( directory, ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
226
227        env.Append( LIBS = lib_hydrogen )
228        env.Append( LIBS = ["sndfile"] )
229       
230        if lrdf: env.Append( LIBS = ["lrdf"] )
231        if flac: env.Append( LIBS = ["FLAC","FLAC++"] )
232        if lash: env.Append( LIBS = ["lash"])
233        if jack:
234            env.Append( LIBS = ["jack"])
235            env.ParseConfig('pkg-config --modversion jack', get_jack_midi_api_version)   
236        if alsa: env.Append( LIBS = ["asound"])
237        if libarchive: env.Append( LIBS = ["archive"])
238        else: env.Append( LIBS = ["tar"])
239        if portaudio: env.Append( LIBS = [ "portaudio" ] )
240        if portmidi:
241                env.Append( LIBS = [ "portmidi" ] )
242                env.Append( LIBS = [ "porttime" ] )
243        env.Append( LIBPATH = '3rdparty\libsndfile-1_0_17' )
244        env.Append( LIBPATH = 'build\pthreads\lib' )
245
246        app = env.Program(target = 'hydrogen', source = src )
247
248        env.Alias('programs', app)
249        env.Default('programs')
250
251        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/i18n"))
252        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/img"))
253        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/drumkits"))
254        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/demo_songs"))
255        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/hydrogen.default.conf"))
256        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/emptySample.wav"))
257        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/click.wav"))
258        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/doc"))
259        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/share/hydrogen/data', source="./data/DefaultSong.h2song"))
260        env.Alias(target="install", source=env.Install(dir= destdir + install_prefix + '/bin/', source="./hydrogen"))
261
262        return app
263
264def get_jack_api_flags(xenv, pkg_ver):
265    (major, minor, patch) = pkg_ver.rstrip().split('.')
266    major = int(major)
267    minor = int(minor)
268    patch = int(patch)
269    rv = ""
270    if (major == 0) and (minor < 102):
271        rv = "-DJACK_NO_BBT_OFFSET"
272    if (major == 0) and (minor == 102) and (patch < 4):
273        rv = "-DJACK_NO_BBT_OFFSET"
274    xenv.MergeFlags(rv)
275
276opts = Options()
277
278#platform independent settings
279opts.Add('debug', 'Set to 1 to build with debug informations', 0)
280opts.Add('libarchive', 'Set to 1 to enable libarchive instead of libtar', 0)
281opts.Add('prefix','Default: /usr/local',"/usr/local")
282opts.Add('destdir','Default: none',"")
283
284#platform dependent settings
285if sys.platform != "win32":
286        opts.Add('portmidi', 'Set to 1 to enable portmidi',0)
287        portmidi = int(ARGUMENTS.get('portmidi',0))
288       
289        opts.Add('portaudio', 'Set to 1 to enable portaudio',0)
290        portaudio = int(ARGUMENTS.get('portaudio',0))
291       
292        opts.Add('lash', 'Set to 1 to enable lash',0)
293        lash = int(ARGUMENTS.get('lash',0))
294       
295       
296        opts.Add('alsa', 'Set to 1 to enable alsa',1)
297        alsa = int(ARGUMENTS.get('alsa',1))
298       
299
300        opts.Add('jack', 'Set to 1 to enable jack',1)   
301        jack = int(ARGUMENTS.get('jack',1))
302       
303
304        opts.Add('lrdf', 'Set to 1 to enable lrdf',1)
305        lrdf = int(ARGUMENTS.get('lrdf',1))
306       
307
308        opts.Add('flac', 'Set to 1 to enable flac',1)
309        flac = int(ARGUMENTS.get('flac',1))
310
311else:
312        #alsa, lash and jack are not available on windows
313        opts.Add('portmidi', 'Set to 1 to enable portmidi',1)
314       
315        opts.Add('portaudio', 'Set to 1 to enable portaudio',1)
316        portaudio = int(ARGUMENTS.get('portaudio',1))
317       
318        opts.Add('lash', 'Set to 1 to enable lash',0)
319        lash = int(ARGUMENTS.get('lash',0))
320       
321
322        opts.Add('alsa', 'Set to 1 to enable alsa',0)
323        alsa = int(ARGUMENTS.get('alsa',0))
324       
325
326        opts.Add('jack', 'Set to 1 to enable jack',0)
327        jack = int(ARGUMENTS.get('jack',0))
328       
329        opts.Add('lrdf', 'Set to 1 to enable lrdf',0)
330        lrdf = int(ARGUMENTS.get('lrdf',0))
331       
332        opts.Add('flac', 'Set to 1 to enable flac',0)
333        flac = int(ARGUMENTS.get('flac',0))
334
335# JACK MIDI version detection.
336def get_jack_midi_api_version(xenv, pkg_ver):
337    global jack_midi
338    rv = ""
339    (major, minor, patch) = pkg_ver.rstrip().split('.')
340    major = int(major)
341    minor = int(minor)
342    patch = int(patch)
343    if major != 0:
344        return rv
345    if minor < 102:
346        return rv
347    rv = "-DJACK_MIDI_SUPPORT"
348    jack_midi = 1
349    if (minor == 102) and (patch <= 26):
350        rv += " -DJACK_MIDI_0_102_0"
351    elif (minor < 104):
352        rv += " -DJACK_MIDI_0_102_27"
353    elif (minor == 104) and (patch == 0):
354        rv += " -DJACK_MIDI_0_102_27"
355    elif (minor >= 105):
356        rv += " -DJACK_MIDI_0_105_0"
357    xenv.MergeFlags(rv)
358
359debug =int(ARGUMENTS.get('debug', 0))
360libarchive = int(ARGUMENTS.get('libarchive', 0))
361
362install_prefix = ARGUMENTS.get('prefix',"/usr/local")
363destdir = ARGUMENTS.get('destdir',"")
364
365
366#get includes ( important if you compile on non-standard envorionments)
367includes, a , b = get_platform_flags()
368env = Environment(options = opts, CPPPATH = includes)
369
370Help(opts.GenerateHelpText(env))
371
372
373platform = sys.platform
374
375#just download 3rd party libs if we're *not* running linux.
376#We trust in our package managment system!
377if platform == "darwin" or platform == "win32":
378    download_3rdparty_libs()
379
380
381
382#Check if all required libraries are installed
383conf = Configure(env)
384if not conf.CheckCHeader('sndfile.h'):
385    print 'libsndfile must be installed!'
386    Exit(1)
387
388
389
390# it seems that conf.CheckCHeader  dislikes like the "++" in filenames
391#if not conf.CheckCHeader('FLAC++/all.h'):
392#   print 'FLAC++ must be installed!'
393#   Exit(1)
394
395
396# these libraries are optional (can be enabled/disabled, see 'scons -h')
397
398if portaudio and not conf.CheckCHeader('portaudio.h'):
399    print "portaudio must be installed!"
400    Exit(1)
401
402if portmidi and not conf.CheckCHeader('portmidi.h'):
403    print "portmidi must be installed!"
404    Exit(1)
405
406
407#alsa: (default: enabled)
408if alsa and not conf.CheckCHeader('alsa/asoundlib.h'):
409    print 'alsa must be installed!'
410    Exit(1)
411
412#jack: (default: enabled)
413if jack and not conf.CheckCHeader('jack/jack.h'):
414    print 'jack must be installed!'
415    Exit(1)
416
417#jack_midi: (default: enabled if jack is)
418if jack and conf.CheckCHeader('jack/midiport.h'):
419    jack_midi = 1
420
421#lash: (default: disabled)
422if lash and not os.path.isdir("/usr/include/lash-1.0"):
423    print 'liblash must be installed!'
424    Exit(1)
425
426#libarchive: (default: disabled)
427if libarchive and not conf.CheckCHeader("archive.h"):
428    print 'libarchive must be installed!'
429    Exit(1)
430#libtar: needed if not libarchive
431elif not libarchive and not conf.CheckCHeader("zlib.h"):
432    print 'zlib devel package must be installed!'
433    Exit(1)
434elif not libarchive and not conf.CheckCHeader("libtar.h"):
435    print 'libtar must be installed!'
436    Exit(1)
437
438#lrdf: categorizing of ladspa effects
439if lrdf and not conf.CheckCHeader('lrdf.h'):
440    print 'lrdf must be installed!'
441    Exit(1)
442
443#flac: support for flac samples
444if flac and not conf.CheckCHeader('FLAC/all.h'):
445    print 'FLAC must be installed!'
446    Exit(1)
447
448
449
450print ""
451print "================================================================="
452print " Hydrogen build script"
453print ""
454print " Revision: %s" % get_svn_revision()
455print " Platform: %s" % platform
456
457if debug:
458        print " Debug build"
459else:
460        print " Release build"
461
462print " Prefix: " + install_prefix
463print " Destdir: " + destdir
464print "================================================================="
465print "Feature Overview:\n"
466
467print "      lash: " + printStatus( lash )
468print "      alsa: " + printStatus( alsa )
469print "      jack: " + printStatus( jack )
470print " jack_midi: " + printStatus( jack_midi )
471print "libarchive: " + printStatus( libarchive ) + (' (using libtar instead)', '')[libarchive]
472print " portaudio: " + printStatus( portaudio )
473print "  portmidi: " + printStatus( portmidi )
474
475print "\n================================================================="
476print ""
477
478
479# write the config.h file
480conf = open("config.h", "w")
481
482conf.write( "#ifndef HYD_CONFIG_H\n" )
483conf.write( "#define HYD_CONFIG_H\n" )
484conf.write( "#include <string>\n" )
485
486
487if debug: conf.write( "#define CONFIG_DEBUG\n" )
488if lash: conf.write( "#define LASH\n" )
489
490conf.write( "#ifndef QT_BEGIN_NAMESPACE\n" )
491conf.write( "#    define QT_BEGIN_NAMESPACE\n" )
492conf.write( "#endif\n" )
493conf.write( "#ifndef QT_END_NAMESPACE\n" )
494conf.write( "#    define QT_END_NAMESPACE\n" )
495conf.write( "#endif\n" )
496
497conf.write( "#define CONFIG_PREFIX \"%s\"\n" % install_prefix )
498conf.write( "#define DATA_PATH \"%s/share/hydrogen/data\"\n" % install_prefix )
499
500conf.write( "#endif\n" )
501
502conf.close()
503
504version = open("version.cpp", "w")
505version.write( "// autogenerated by Sconstruct script\n" )
506version.write( '#include "version.h"\n' )
507version.write( '#include "config.h"\n' )
508version.write( "static const std::string extra_version = \"svn%s\";\n" % get_svn_revision() )
509version.write( "static const std::string VERSION = \"0.9.4-\" + extra_version;\n" )
510version.write( "std::string get_version() { return VERSION;     }\n" )
511version.close()
512
513libhyd = get_hydrogen_lib()
514app = get_hydrogen_gui( libhyd )
Note: See TracBrowser for help on using the browser.