root/branches/jackMidi/Sconstruct @ 401

Revision 401, 14.0 KB (checked in by gabriel, 5 years ago)

Merge rev 373:374 from trunk.

Conflicts:

features.pri
libs/hydrogen/src/hydrogen.cpp

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