root/branches/jackMidi/Sconstruct @ 826

Revision 826, 16.1 KB (checked in by gabriel@…, 4 years ago)

Merge rev 594:682 from trunk

Conflicts:

Sconstruct

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