root/trunk/Sconstruct @ 750

Revision 750, 15.7 KB (checked in by mauser, 4 years ago)

removed statements from scons which made trouble with older python versions (especially on OSX)

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                        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               
71                if sys.platform == "darwin" and str(env['coreaudio']) == "1": cppflags.append('-DCOREAUDIO_SUPPORT')
72
73                cppflags.append('-DFLAC_SUPPORT')
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
176        #location of qt4.py
177        qt4ToolLocation="."
178
179        env = Environment(options = opts , tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
180        env.EnableQt4Modules( ['QtCore', 'QtGui'], debug=False)
181        env.CacheDir( "scons_cache" )
182       
183
184        if str(env['jack']) == "1":
185            env.ParseConfig('pkg-config --modversion jack', get_jack_api_flags)
186
187
188        #env.Decider is not known in older scons version
189        try:
190                env.Decider( "MD5-timestamp" )
191        except AttributeError:
192                env.SourceSignatures('MD5')
193
194
195        src = scanFiles( "libs/hydrogen", ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
196        src.append( "version.cpp" )
197
198        static_lib = env.StaticLibrary(target = 'hydrogen', source = src )
199        return static_lib
200
201
202def get_hydrogen_gui( lib_hydrogen , opts ):
203        includes, cppflags, ldflags = get_platform_flags( opts )
204
205        includes.append( "libs/hydrogen/include" )
206        includes.append( "gui/src/UI" )
207        includes.append( "/usr/include/lash-1.0")
208
209        #location of qt4.py
210        qt4ToolLocation="."
211
212        env = Environment(options = opts , tools=['default','qt4'], toolpath=[qt4ToolLocation], ENV=os.environ, CPPPATH = includes, CPPFLAGS = cppflags, CCFLAGS = "", LINKFLAGS=ldflags )
213       
214        env.EnableQt4Modules( ['QtCore', 'QtGui','QtNetwork','QtXml'], debug=False)
215        #
216        env.CacheDir( "scons_cache" )
217       
218        #env.Decider is not known in older scons version
219        try:
220                env.Decider( "MD5-timestamp" )
221        except AttributeError:
222                env.SourceSignatures('MD5')
223
224        # rcc needs a -name flag because examples use identified resource files
225        def takebasename(file):
226                return os.path.splitext(os.path.basename(file))[0]
227
228
229        directory = "gui"
230
231        resources = [ env.Qrc( qrc, QT4_QRCFLAGS = '-name ' + takebasename( qrc ) ) for qrc in scanFiles(directory, ['*.qrc'] ) ]
232        interfaces = [ env.Uic4( uic ) for uic in scanFiles(directory, ['*.ui'] ) ]
233
234
235        src = scanFiles( directory, ['*.cpp', '*.cc', '*.c' ], [ 'moc_'] )
236
237        env.Append( LIBS = lib_hydrogen )
238        env.Append( LIBS = ["sndfile"] )
239       
240        if str(env['lrdf']) == "1": env.Append( LIBS = ["lrdf"] )
241        if str(env['flac']) == "1": env.Append( LIBS = ["FLAC","FLAC++"] )
242        if str(env['lash']) == "1": env.Append( LIBS = ["lash"])
243        if str(env['jack']) == "1": env.Append( LIBS = ["jack"])
244        if str(env['alsa']) == "1": env.Append( LIBS = ["asound"])
245        if str(env['libarchive']) == "1": env.Append( LIBS = ["archive"])
246        else: env.Append( LIBS = ["tar"])
247        if str(env['portaudio']) == "1": env.Append( LIBS = [ "portaudio" ] )
248        if str(env['portmidi']) == "1":
249                env.Append( LIBS = [ "portmidi" ] )
250                env.Append( LIBS = [ "porttime" ] )
251
252        if sys.platform == "darwin":
253                env.Append( LIBS = ["z"] )
254
255        if sys.platform == "darwin" and str(env['coreaudio']) == "1":
256                env.Append( LINKFLAGS = ['-framework','ApplicationServices'])
257                env.Append( LINKFLAGS = ['-framework','AudioUnit'])
258                env.Append( LINKFLAGS = ['-framework','Coreaudio'])
259
260
261
262        env.Append( LIBPATH = '3rdparty\libsndfile-1_0_17' )
263        env.Append( LIBPATH = 'build\pthreads\lib' )
264
265        app = env.Program(target = 'hydrogen', source = src )
266
267        env.Alias('programs', app)
268        env.Default('programs')
269
270        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/i18n"))
271        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/img"))
272        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/drumkits"))
273        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/demo_songs"))
274        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/hydrogen.default.conf"))
275        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/emptySample.wav"))
276        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/click.wav"))
277        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/doc"))
278        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/hydrogen/data', source="./data/DefaultSong.h2song"))
279        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/bin/', source="./hydrogen"))
280        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/applications', source="./hydrogen.desktop"))
281        env.Alias(target="install", source=env.Install(dir= env['DESTDIR'] + env['prefix'] + '/share/pixmaps', source="./data/img/gray/h2-icon.svg"))
282
283
284        return app
285
286def get_jack_api_flags(xenv, pkg_ver):
287    (major, minor, patch) = pkg_ver.rstrip().split('.')
288    major = int(major)
289    minor = int(minor)
290    patch = int(patch)
291    rv = ""
292    if (major == 0) and (minor < 102):
293        rv = "-DJACK_NO_BBT_OFFSET"
294    if (major == 0) and (minor == 102) and (patch < 4):
295        rv = "-DJACK_NO_BBT_OFFSET"
296    xenv.MergeFlags(rv)
297
298opts = Options('scache.conf')
299
300#platform independent settings
301opts.Add('debug', 'Set to 1 to build with debug informations', 0)
302opts.Add('libarchive', 'Set to 1 to enable libarchive instead of libtar', 0)
303opts.Add('prefix','Default: /usr/local',"/usr/local")
304opts.Add('DESTDIR','Default: none',"")
305opts.Add('optflags','Default: none',"")
306
307#platform dependent settings
308if sys.platform == "darwin":
309        opts.Add('coreaudio', 'Set to 1 to enable Coreaudio',1)
310
311if sys.platform != "win32":
312        opts.Add('oss', 'Set to 1 to enable oss',1)
313
314        opts.Add('portmidi', 'Set to 1 to enable portmidi',0)
315       
316        opts.Add('portaudio', 'Set to 1 to enable portaudio',0)
317       
318        opts.Add('lash', 'Set to 1 to enable lash',0)
319       
320        opts.Add('alsa', 'Set to 1 to enable alsa',1)
321       
322        opts.Add('jack', 'Set to 1 to enable jack',1)   
323       
324        opts.Add('lrdf', 'Set to 1 to enable lrdf',1)
325       
326        opts.Add('flac', 'Set to 1 to enable flac',1)
327else:
328        #alsa, lash,oss and jack are not available on windows
329        opts.Add('portmidi', 'Set to 1 to enable portmidi',1)
330       
331        opts.Add('portaudio', 'Set to 1 to enable portaudio',1)
332       
333        opts.Add('oss', 'Set to 1 to enable oss',0)
334
335        opts.Add('lash', 'Set to 1 to enable lash',0)
336       
337        opts.Add('alsa', 'Set to 1 to enable alsa',0)
338       
339        opts.Add('jack', 'Set to 1 to enable jack',0)
340       
341        opts.Add('lrdf', 'Set to 1 to enable lrdf',0)
342       
343        opts.Add('flac', 'Set to 1 to enable flac',0)
344
345
346
347#get includes ( important if you compile on non-standard envorionments)
348
349includes, a , b = get_platform_flags( opts )
350
351env = Environment(options = opts, CPPPATH = includes)
352
353
354Help(opts.GenerateHelpText(env))
355
356
357platform = sys.platform
358
359#just download 3rd party libs if we're *not* running linux.
360#We trust in our package managment system!
361if platform == "darwin" or platform == "win32":
362    download_3rdparty_libs()
363
364
365
366#Check if all required libraries are installed
367conf = Configure(env)
368if not conf.CheckCHeader('sndfile.h'):
369    print 'libsndfile must be installed!'
370    Exit(1)
371
372
373
374# it seems that conf.CheckCHeader  dislikes like the "++" in filenames
375#if not conf.CheckCHeader('FLAC++/all.h'):
376#   print 'FLAC++ must be installed!'
377#   Exit(1)
378
379
380# these libraries are optional (can be enabled/disabled, see 'scons -h')
381
382if str(env['portaudio']) == "1" and not conf.CheckCHeader('portaudio.h'):
383    print "portaudio must be installed!"
384    Exit(1)
385
386if str(env['portmidi']) == "1" and not conf.CheckCHeader('portmidi.h'):
387    print "portmidi must be installed!"
388    Exit(1)
389
390
391#alsa: (default: enabled)
392if str(env['alsa']) == "1" and not conf.CheckCHeader('alsa/asoundlib.h'):
393    print 'alsa must be installed!'
394    Exit(1)
395
396#jack: (default: enabled)
397if str(env['jack']) == "1" and not conf.CheckCHeader('jack/jack.h'):
398    print 'jack must be installed!'
399    Exit(1)
400
401#lash: (default: disabled)
402if str(env['lash']) == "1" and not os.path.isdir("/usr/include/lash-1.0"):
403    print 'liblash must be installed!'
404    Exit(1)
405
406#libarchive: (default: disabled)
407if str(env['libarchive']) == "1" and not conf.CheckCHeader("archive.h"):
408    print 'libarchive must be installed!'
409    Exit(1)
410#libtar: needed if not libarchive
411elif not str(env['libarchive']) == "1" and not conf.CheckCHeader("zlib.h"):
412   print 'zlib devel package must be installed!'
413   Exit(1)
414elif not str(env['libarchive']) == "1" and not conf.CheckCHeader("libtar.h"):
415   print 'libtar must be installed!'
416   Exit(1)
417
418#lrdf: categorizing of ladspa effects
419if str(env['lrdf']) == "1" and not conf.CheckCHeader('lrdf.h'):
420    print 'lrdf must be installed!'
421    Exit(1)
422
423#flac: support for flac samples
424if str(env['flac']) == "1" and not conf.CheckCHeader('FLAC/all.h'):
425    print 'FLAC must be installed!'
426    Exit(1)
427
428
429print ""
430print "================================================================="
431print " Hydrogen build script"
432print ""
433print " Revision: %s" % get_svn_revision()
434print " Platform: %s" % platform
435
436if str(env['debug']) == "1" :
437        print " Debug build"
438else:
439        print " Release build"
440
441print " Prefix: " + env['prefix']
442print " Destdir: " + env['DESTDIR']
443print "================================================================="
444print "Feature Overview:\n"
445
446
447print "      lash: " + printStatus( env["lash"] )
448print "      oss: " + printStatus( env["oss"] )
449print "      alsa: " + printStatus( env["alsa"] )
450print "      jack: " + printStatus( env["jack"] )
451print "libarchive: " + printStatus( env["libarchive"] )
452print " portaudio: " + printStatus( env["portaudio"] )
453print "  portmidi: " + printStatus( env["portmidi"] )
454if sys.platform == "darwin":
455        print " coreaudio: " + printStatus( env["coreaudio"] )
456
457print "\n================================================================="
458print ""
459
460# write the config.h file
461conf = open("config.h", "w")
462
463conf.write( "#ifndef HYD_CONFIG_H\n" )
464conf.write( "#define HYD_CONFIG_H\n" )
465conf.write( "#include <string>\n" )
466
467
468if str(env['debug']) == "1": conf.write( "#define CONFIG_DEBUG\n" )
469if str(env['lash']) == "1": conf.write( "#define LASH\n" )
470
471conf.write( "#ifndef QT_BEGIN_NAMESPACE\n" )
472conf.write( "#    define QT_BEGIN_NAMESPACE\n" )
473conf.write( "#endif\n" )
474conf.write( "#ifndef QT_END_NAMESPACE\n" )
475conf.write( "#    define QT_END_NAMESPACE\n" )
476conf.write( "#endif\n" )
477
478conf.write( "#define CONFIG_PREFIX \"%s\"\n" % env['prefix'] )
479conf.write( "#define DATA_PATH \"%s/share/hydrogen/data\"\n" % env['prefix'] )
480
481conf.write( "#endif\n" )
482
483conf.close()
484
485version = open("version.cpp", "w")
486version.write( "// autogenerated by Sconstruct script\n" )
487version.write( '#include "version.h"\n' )
488version.write( '#include "config.h"\n' )
489version.write( "static const std::string extra_version = \"svn%s\";\n" % get_svn_revision() )
490version.write( "static const std::string VERSION = \"0.9.4-\" + extra_version;\n" )
491version.write( "std::string get_version() { return VERSION;     }\n" )
492version.close()
493
494
495libhyd = get_hydrogen_lib( opts )
496app = get_hydrogen_gui( libhyd , opts )
497
498opts.Save("scache.conf",env)
Note: See TracBrowser for help on using the browser.