root/trunk/Sconstruct @ 692

Revision 692, 14.9 KB (checked in by mauser, 4 years ago)

added g++ flags for C++0X

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