remove tabs from python code
[ardour.git] / wscript
1 #!/usr/bin/env python
2 from waflib.extras import autowaf as autowaf
3 from waflib import Options
4 import os
5 import re
6 import string
7 import subprocess
8 import sys
9 import platform as PLATFORM
10 from waflib.Tools import winres
11 from waflib.Build import Context
12 from waflib.Build import BuildContext
13
14 class i18n(BuildContext):
15         cmd = 'i18n'
16         fun = 'i18n'
17
18 class i18n_pot(BuildContext):
19         cmd = 'i18n_pot'
20         fun = 'i18n_pot'
21
22 class i18n_po(BuildContext):
23         cmd = 'i18n_po'
24         fun = 'i18n_po'
25
26 class i18n_mo(BuildContext):
27         cmd = 'i18n_mo'
28         fun = 'i18n_mo'
29
30 def is_tracks_build(self, *k, **kw):
31         return self.env['PROGRAM_NAME'] == 'Tracks Live'
32
33 Context.Context.is_tracks_build = is_tracks_build
34
35 compiler_flags_dictionaries= {
36     'gcc' : {
37         # Flags required when building a debug build
38         'debuggable' : [ '-O0', '-g' ],
39         # Flags required for the linker (if any) when building a debug build
40         'linker-debuggable' : '',
41         # Flags required when building a non-debug optimized build
42         'nondebuggable' : '-DNDEBUG',
43         # Flags required to enable profiling at runtime
44         'profile' : '-pg',
45         # Flags required to disable warnings about unused arguments to function calls
46         'silence-unused-arguments' : '',
47         # Flags required to use SSE unit for general math
48         'sse' : '-msse',
49         # Flags required to use SSE unit for floating point math
50         'fpmath-sse' : '-mfpmath=sse',
51         # Flags required to use XMM Intrinsics
52         'xmmintrinsics' : '-DUSE_XMMINTRIN',
53         # Flags to use posix pipes between compiler stages
54         'pipe' : '-pipe',
55         # Flags for maximally optimized build
56         'full-optimization' : [ '-O3', '-fomit-frame-pointer', '-ffast-math', '-fstrength-reduce', ],
57         # Flag to ensure that compiler error output includes column/line numbers
58         'show-column' : '-fshow-column',
59         # Flags required to build for x86 only (OS X feature)
60         'generic-x86' : '',
61         # Flags required to build for PowerPC only (OS X feature)
62         'generic-ppc' : '',
63         # All flags required to get basic warnings to be generated by the compiler
64         'basic-warnings' : [ '-Wall', '-Wpointer-arith', '-Wcast-qual', '-Wcast-align', '-Wno-unused-parameter' ],
65         # Any additional flags for warnings that are specific to C (not C++)
66         'extra-c-warnings' : [ '-Wstrict-prototypes', '-Wmissing-prototypes' ],
67         # Any additional flags for warnings that are specific to C++ (not C)
68         'extra-cxx-warnings' : [ '-Woverloaded-virtual', '-Wno-unused-local-typedefs' ],
69         # Flags used for "strict" compilation, C and C++ (i.e. compiler will warn about language issues)
70         'strict' : ['-Wall', '-Wcast-align', '-Wextra', '-Wwrite-strings', '-Wunsafe-loop-optimizations', '-Wlogical-op' ],
71         # Flags used for "strict" compilation, C only (i.e. compiler will warn about language issues)
72         'c-strict' : ['-std=c99', '-pedantic', '-Wshadow'],
73         # Flags used for "strict" compilation, C++ only (i.e. compiler will warn about language issues)
74         'cxx-strict' : [ '-ansi', '-Wnon-virtual-dtor', '-Woverloaded-virtual', '-fstrict-overflow' ],
75         # Flags required for whatever consider the strictest possible compilation 
76         'ultra-strict' : ['-Wredundant-decls', '-Wstrict-prototypes', '-Wmissing-prototypes'],
77         # Flag to turn on C99 compliance by itself 
78         'c99': '-std=c99',
79         # Flag to enable AT&T assembler syntax
80         'attasm': '-masm=att',
81         # Flags to make AVX instructions/intrinsics available
82         'avx': '-mavx',
83         # Flags to generate position independent code, when needed to build a shared object
84         'pic': '-fPIC',
85         # Flags required to compile C code with anonymous unions (only part of C11)
86         'c-anonymous-union': '-fms-extensions',
87     },
88     'msvc' : {
89         'debuggable' : ['/DDEBUG', '/Od', '/Zi', '/MDd', '/Gd', '/EHsc'],
90         'linker-debuggable' : ['/DEBUG', '/INCREMENTAL' ],
91         'nondebuggable' : ['/DNDEBUG', '/Ob1', '/MD', '/Gd', '/EHsc'],
92         'profile' : '',
93         'sse' : '/arch:SSE',
94         'silence-unused-arguments' : '',
95         'sse' : '',
96         'fpmath-sse' : '',
97         'xmmintrinsics' : '',
98         'pipe' : '',
99         'full-optimization' : '/O2',
100         'no-frame-pointer' : '',
101         'fast-math' : '',
102         'strength-reduce' : '',
103         'show-column' : '',
104         'generic-x86' : '',
105         'generic-ppc' : '',
106         'basic-warnings' : '',
107         'extra-c-warnings' : '',
108         'extra-cxx-warnings' : '',
109         'ultra-strict' : '',
110         'c-strict' : '',
111         'cxx-strict' : '',
112         'strict' : '',
113         'c99': '/TP',
114         'attasm': '',
115         'avx': '',
116         'pic': '',
117         'c-anonymous-union': '',
118     },
119 }
120
121 # Copy, edit and insert variants on gcc dict for gcc-darwin and clang
122
123 gcc_darwin_dict = compiler_flags_dictionaries['gcc'].copy()
124 gcc_darwin_dict['extra-cxx-warnings'] = [ '-Woverloaded-virtual' ]
125 gcc_darwin_dict['cxx-strict'] = [ '-ansi', '-Wnon-virtual-dtor', '-Woverloaded-virtual' ]
126 gcc_darwin_dict['strict'] = ['-Wall', '-Wcast-align', '-Wextra', '-Wwrite-strings' ]
127 gcc_darwin_dict['generic-x86'] = [ '-arch', 'i386' ]
128 gcc_darwin_dict['generic-ppc'] = [ '-arch', 'ppc' ]
129 compiler_flags_dictionaries['gcc-darwin'] = gcc_darwin_dict;
130
131 clang_dict = compiler_flags_dictionaries['gcc'].copy();
132 clang_dict['sse'] = ''
133 clang_dict['fpmath-sse'] = ''
134 clang_dict['xmmintrinsics'] = ''
135 clang_dict['silence-unused-arguments'] = '-Qunused-arguments'
136 clang_dict['extra-cxx-warnings'] = [ '-Woverloaded-virtual', '-Wno-mismatched-tags' ]
137 clang_dict['cxx-strict'] = [ '-ansi', '-Wnon-virtual-dtor', '-Woverloaded-virtual', '-fstrict-overflow' ]
138 clang_dict['strict'] = ['-Wall', '-Wcast-align', '-Wextra', '-Wwrite-strings' ]
139 clang_dict['generic-x86'] = [ '-arch', 'i386' ]
140 compiler_flags_dictionaries['clang'] = clang_dict;
141
142 clang_darwin_dict = compiler_flags_dictionaries['clang'].copy();
143 clang_darwin_dict['cxx-strict'] = [ '-ansi', '-Wnon-virtual-dtor', '-Woverloaded-virtual', ]
144 clang_darwin_dict['full-optimization'] = [ '-O3', '-ffast-math', '-fstrength-reduce' ]
145 compiler_flags_dictionaries['clang-darwin'] = clang_darwin_dict;
146
147 def fetch_git_revision ():
148     cmd = "git describe HEAD | sed 's/^[A-Za-z]*+//'"
149     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
150     rev = output[0].decode ('utf-8')
151     return rev
152
153 def fetch_tarball_revision ():
154     if not os.path.exists ('libs/ardour/revision.cc'):
155         print ('This tarball was not created correctly - it is missing libs/ardour/revision.cc')
156         sys.exit (1)
157     with open('libs/ardour/revision.cc') as f:
158         content = f.readlines()
159         remove_punctuation_map = dict((ord(char), None) for char in '";')
160         return content[1].decode('utf-8').strip().split(' ')[7].translate (remove_punctuation_map)
161
162 if os.path.isdir (os.path.join(os.getcwd(), '.git')):
163     rev = fetch_git_revision ()
164 else:
165     rev = fetch_tarball_revision ()
166
167 #
168 # rev is now of the form MAJOR.MINOR[-rcX]-rev-commit
169 # or, if right at the same rev as a release, MAJOR.MINOR[-rcX]
170 #
171
172 parts = rev.split ('.', 1)
173 MAJOR = parts[0]
174 other = parts[1].split('-', 1)
175 MINOR = other[0]
176 if len(other) > 1:
177     MICRO = other[1].rsplit('-',1)[0].replace('-','.')
178 else:
179     MICRO = '0'
180
181 V = MAJOR + '.' + MINOR + '.' + MICRO
182 # Ensure that these are not unicode, which
183 # can cause odd problems elsewhere
184 VERSION = V.encode ('ascii', 'ignore')
185 PROGRAM_VERSION = MAJOR.encode ('ascii', 'ignore')
186
187 # Mandatory variables
188 top = '.'
189 out = 'build'
190
191 children = [
192         # optionally external libraries
193         'libs/qm-dsp',
194         'libs/vamp-plugins',
195         'libs/libltc',
196         # core ardour libraries
197         'libs/pbd',
198         'libs/midi++2',
199         'libs/evoral',
200         'libs/surfaces',
201         'libs/panners',
202         'libs/backends',
203         'libs/timecode',
204         'libs/ardour',
205         'libs/gtkmm2ext',
206         'libs/audiographer',
207         'libs/canvas',
208         'libs/plugins/reasonablesynth.lv2',
209         'gtk2_ardour',
210         'export',
211         'midi_maps',
212         'mcp',
213         'patchfiles',
214         'headless',
215         # shared helper binaries (plugin-scanner, exec-wrapper)
216         'libs/fst',
217         'libs/vfork',
218         'libs/ardouralsautil',
219         'cfgtool',
220 ]
221
222 i18n_children = [
223         'gtk2_ardour',
224         'libs/ardour',
225         'libs/gtkmm2ext',
226 ]
227
228 # Version stuff
229
230 def fetch_gcc_version (CC):
231     cmd = "%s --version" % CC
232     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
233     o = output[0].decode('utf-8')
234     version = o.split(' ')[2].split('.')
235     return version
236
237 def create_stored_revision():
238     rev = ""
239     if os.path.exists('.git'):
240         rev = fetch_git_revision();
241         print("Git version: " + rev + "\n")
242     elif os.path.exists('libs/ardour/revision.cc'):
243         print("Using packaged revision")
244         return
245     else:
246         print("Missing libs/ardour/revision.cc.  Blame the packager.")
247         sys.exit(-1)
248
249     try:
250         #
251         # if you change the format of this, be sure to fix fetch_tarball_revision() above
252         # so that  it still works.
253         #
254         text =  '#include "ardour/revision.h"\n'
255         text += 'namespace ARDOUR { const char* revision = \"%s\"; }\n' % rev
256         print('Writing revision info to libs/ardour/revision.cc using ' + rev)
257         o = open('libs/ardour/revision.cc', 'w')
258         o.write(text)
259         o.close()
260     except IOError:
261         print('Could not open libs/ardour/revision.cc for writing\n')
262         sys.exit(-1)
263
264 def set_compiler_flags (conf,opt):
265     #
266     # Compiler flags and other system-dependent stuff
267     #
268     build_host_supports_sse = False
269
270     # Flags necessary for building
271     compiler_flags = []     # generic
272     c_flags = []            # C-specific
273     cxx_flags = []          # C++-specific
274     linker_flags = []
275
276     # Optimization flags (overridable)
277     optimization_flags = []
278
279     # Debugging flags
280     debug_flags = []
281
282     u = PLATFORM.uname ()
283     cpu = u[4]
284     platform = u[0].lower()
285     version = u[2]
286
287     # waf adds -O0 -g itself. thanks waf!
288     is_clang = conf.check_cxx(fragment = '''
289 #ifndef __clang__
290 #error
291 #endif
292 int main() { return 0; }''',
293                          features  = 'cxx',
294                          mandatory = False,
295                          execute   = False,
296                          msg       = 'Checking for clang')
297
298     if is_clang:
299         if platform == 'darwin':
300             compiler_name = 'clang-darwin'
301         else:
302             compiler_name = 'clang'
303     elif conf.env['MSVC_COMPILER']:
304             compiler_name = 'msvc'
305     else:
306         if platform == 'darwin':
307             compiler_name = 'gcc-darwin'
308         else:
309             compiler_name = 'gcc'
310
311     flags_dict = compiler_flags_dictionaries[compiler_name] 
312     # Save the compiler flags because we need them at build time
313     # when we need to add compiler specific flags in certain
314     # libraries
315     conf.env['compiler_flags_dict'] = flags_dict;
316     
317     autowaf.set_basic_compiler_flags (conf,flags_dict)
318     
319     if conf.options.asan:
320         conf.check_cxx(cxxflags=["-fsanitize=address", "-fno-omit-frame-pointer"], linkflags=["-fsanitize=address"])
321         cxx_flags.append('-fsanitize=address')
322         cxx_flags.append('-fno-omit-frame-pointer')
323         linker_flags.append('-fsanitize=address')
324
325     if opt.gprofile:
326         debug_flags = [ flags_dict['profile'] ]
327
328     # OSX
329     if platform == 'darwin':
330         if re.search ("^13[.]", version) != None:
331             conf.env['build_host'] = 'mavericks'
332         elif re.search ("^14[.]", version) != None:
333             conf.env['build_host'] = 'yosemite'
334         else:
335             conf.env['build_host'] = 'irrelevant'
336
337     # Autodetect
338     if opt.dist_target == 'auto':
339         if platform == 'darwin':
340             # The [.] matches to the dot after the major version, "." would match any character
341             if re.search ("^[0-7][.]", version) != None:
342                 conf.env['build_target'] = 'panther'
343             elif re.search ("^8[.]", version) != None:
344                 conf.env['build_target'] = 'tiger'
345             elif re.search ("^9[.]", version) != None:
346                 conf.env['build_target'] = 'leopard'
347             elif re.search ("^10[.]", version) != None:
348                 conf.env['build_target'] = 'snowleopard'
349             elif re.search ("^11[.]", version) != None:
350                 conf.env['build_target'] = 'lion'
351             elif re.search ("^12[.]", version) != None:
352                 conf.env['build_target'] = 'mountainlion'
353             elif re.search ("^13[.]", version) != None:
354                 conf.env['build_target'] = 'mavericks'
355             else:
356                 conf.env['build_target'] = 'yosemite'
357         else:
358             match = re.search(
359                     "(?P<cpu>i[0-6]86|x86_64|powerpc|ppc|ppc64|arm|s390x?)",
360                     cpu)
361             if (match):
362                 conf.env['build_target'] = match.group("cpu")
363                 if re.search("i[0-5]86", conf.env['build_target']):
364                     conf.env['build_target'] = "i386"
365             else:
366                 conf.env['build_target'] = 'none'
367     else:
368         conf.env['build_target'] = opt.dist_target
369
370     if conf.env['build_target'] == 'snowleopard':
371         #
372         # stupid OS X 10.6 has a bug in math.h that prevents llrint and friends
373         # from being visible.
374         # 
375         compiler_flags.append ('-U__STRICT_ANSI__')
376
377     if conf.options.cxx11 or conf.env['build_host'] in [ 'mavericks', 'yosemite' ]:
378         conf.check_cxx(cxxflags=["-std=c++11"])
379         cxx_flags.append('-std=c++11')
380         if platform == "darwin":
381             cxx_flags.append('--stdlib=libstdc++')
382             # Mavericks and later changed the syntax to be used when including Carbon headers,
383             # from requiring a full path to requiring just the header name.
384             cxx_flags.append('-DCARBON_FLAT_HEADERS')
385             linker_flags.append('--stdlib=libstdc++')
386             # Prevents visibility issues in standard headers
387             conf.define("_DARWIN_C_SOURCE", 1)
388
389     if (is_clang and platform == "darwin") or conf.env['build_host'] in ['mavericks', 'yosemite']:
390         # Silence warnings about the non-existing osx clang compiler flags
391         # -compatibility_version and -current_version.  These are Waf
392         # generated and not needed with clang
393         c_flags.append("-Qunused-arguments")
394         cxx_flags.append("-Qunused-arguments")
395
396     if (re.search ("(i[0-9]86|x86_64|AMD64)", cpu) != None) and conf.env['build_target'] != 'none':
397
398         #
399         # ARCH_X86 means anything in the x86 family from i386 to x86_64
400         # the compile-time presence of the macro _LP64 is used to 
401         # distingush 32 and 64 bit assembler
402         #
403  
404         compiler_flags.append ("-DARCH_X86")
405
406         if platform == 'linux' :
407
408             #
409             # determine processor flags via /proc/cpuinfo
410             #
411
412             if conf.env['build_target'] != 'i386':
413
414                 flag_line = os.popen ("cat /proc/cpuinfo | grep '^flags'").read()[:-1]
415                 x86_flags = flag_line.split (": ")[1:][0].split ()
416
417                 if "mmx" in x86_flags:
418                     compiler_flags.append ("-mmmx")
419                 if "sse" in x86_flags:
420                     build_host_supports_sse = True
421                 if "3dnow" in x86_flags:
422                     compiler_flags.append ("-m3dnow")
423
424             if cpu == "i586":
425                 compiler_flags.append ("-march=i586")
426             elif cpu == "i686":
427                 compiler_flags.append ("-march=i686")
428
429         if not is_clang and ((conf.env['build_target'] == 'i686') or (conf.env['build_target'] == 'x86_64')) and build_host_supports_sse:
430             compiler_flags.extend ([ flags_dict['sse'], flags_dict['fpmath-sse'], flags_dict['xmmintrinsics'] ])
431             
432         if (conf.env['build_target'] == 'mingw'):
433             if (re.search ("(x86_64|AMD64)", cpu) != None):
434                 # on Windows sse is supported by 64 bit platforms only
435                 build_host_supports_sse = True
436
437                 # mingw GCC compiler to uses at&t (Unix specific) assembler dialect by default
438                 # compiler_flags.append (["--mmnemonic=att", "msyntax=att")
439                 
440                 compiler_flags.extend ([ flags_dict['sse'], flags_dict['fpmath-sse'], flags_dict['xmmintrinsics'], flags_dict['attasm'] ])
441
442     # end of processor-specific section
443
444     # optimization section
445     if conf.env['FPU_OPTIMIZATION']:
446         if sys.platform == 'darwin':
447             compiler_flags.append("-DBUILD_VECLIB_OPTIMIZATIONS");
448             conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'Accelerate'])
449         elif conf.env['build_target'] == 'i686' or conf.env['build_target'] == 'x86_64':
450                 compiler_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
451         elif conf.env['build_target'] == 'mingw':
452                 # usability of the 64 bit windows assembler depends on the compiler target,
453                 # not the build host, which in turn can only be inferred from the name
454                 # of the compiler. 
455                 if re.search ('/^x86_64/', str(conf.env['CC'])):
456                         compiler_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
457         if not build_host_supports_sse:
458             print("\nWarning: you are building Ardour with SSE support even though your system does not support these instructions. (This may not be an error, especially if you are a package maintainer)")
459
460     # end optimization section
461
462     #
463     # no VST on x86_64
464     #
465
466     if conf.env['build_target'] == 'x86_64' and opt.windows_vst:
467         print("\n\n==================================================")
468         print("You cannot use VST plugins with a 64 bit host. Please run waf with --windows-vst=0")
469         print("\nIt is theoretically possible to build a 32 bit host on a 64 bit system.")
470         print("However, this is tricky and not recommended for beginners.")
471         sys.exit (-1)
472
473     if conf.env['LXVST_SUPPORT'] == True:
474         if conf.env['build_target'] == 'x86_64':
475             compiler_flags.append("-DLXVST_64BIT")
476         else:
477             compiler_flags.append("-DLXVST_32BIT")
478
479     #
480     # a single way to test if we're on OS X
481     #
482
483     if conf.env['build_target'] in ['panther', 'tiger', 'leopard' ]:
484         # force tiger or later, to avoid issues on PPC which defaults
485         # back to 10.1 if we don't tell it otherwise.
486
487         compiler_flags.extend(
488                 ("-DMAC_OS_X_VERSION_MIN_REQUIRED=1040",
489                  '-mmacosx-version-min=10.4'))
490
491     elif conf.env['build_target'] in [ 'snowleopard' ]:
492         compiler_flags.extend(
493                 ("-DMAC_OS_X_VERSION_MIN_REQUIRED=1060",
494                  '-mmacosx-version-min=10.6'))
495
496     elif conf.env['build_target'] in [ 'lion', 'mountainlion' ]:
497         compiler_flags.extend(
498                 ("-DMAC_OS_X_VERSION_MIN_REQUIRED=1070",
499                  '-mmacosx-version-min=10.7'))
500
501     elif conf.env['build_target'] in [ 'mavericks', 'yosemite' ]:
502         compiler_flags.extend(
503                 ("-DMAC_OS_X_VERSION_MAX_ALLOWED=1090",
504                  "-mmacosx-version-min=10.8"))
505
506     #
507     # save off CPU element in an env
508     #
509     conf.define ('CONFIG_ARCH', cpu)
510
511     #
512     # ARCH="..." overrides all
513     #
514
515     if opt.arch != None:
516         optimization_flags = opt.arch.split()
517
518     #
519     # prepend boiler plate optimization flags that work on all architectures
520     #
521
522     optimization_flags[:0] = [flags_dict['pipe']]
523
524     # don't prepend optimization flags if "-O<something>" is present
525     prepend_opt_flags = True
526     for flag in optimization_flags:
527         if flag.startswith("-O"):
528             prepend_opt_flags = False
529             break
530
531     if prepend_opt_flags:
532         optimization_flags[:0] = flags_dict['full-optimization']
533
534     if opt.debug_symbols:
535         optimization_flags += flags_dict['debuggable']
536
537     if opt.stl_debug:
538         cxx_flags.append("-D_GLIBCXX_DEBUG")
539
540     if conf.env['DEBUG_RT_ALLOC']:
541         compiler_flags.append('-DDEBUG_RT_ALLOC')
542         linker_flags.append('-ldl')
543
544     if conf.env['DEBUG_DENORMAL_EXCEPTION']:
545         compiler_flags.append('-DDEBUG_DENORMAL_EXCEPTION')
546
547     if opt.generic:
548         compiler_flags.extend(flags_dict['generic-x86'])
549         linker_flags.extend(flags_dict['generic-x86'])
550
551     if opt.ppc:
552         compiler_flags.extend(flags_dict['generic-ppc'])
553         linker_flags.extend(flags_dict['generic-ppc'])
554
555     #
556     # warnings flags
557     #
558
559     compiler_flags.extend(flags_dict['basic-warnings'])
560
561     c_flags.extend(flags_dict['extra-c-warnings'])
562     cxx_flags.extend (flags_dict['extra-cxx-warnings'])
563
564     #
565     # more boilerplate
566     #
567
568     # need ISOC9X for llabs()
569     compiler_flags.extend(
570         ('-DBOOST_SYSTEM_NO_DEPRECATED', '-D_ISOC9X_SOURCE',
571          '-D_LARGEFILE64_SOURCE', '-D_FILE_OFFSET_BITS=64'))
572     cxx_flags.extend(
573         ('-D__STDC_LIMIT_MACROS', '-D__STDC_FORMAT_MACROS', 
574          '-DCANVAS_COMPATIBILITY', '-DCANVAS_DEBUG'))
575     
576     if opt.nls:
577         compiler_flags.append('-DENABLE_NLS')
578
579     compiler_flags.append ('-DPROGRAM_NAME="' + Options.options.program_name + '"')
580     compiler_flags.append ('-DPROGRAM_VERSION="' + PROGRAM_VERSION + '"')
581
582     conf.env['PROGRAM_NAME'] = Options.options.program_name
583     
584     if opt.debug:
585         conf.env.append_value('CFLAGS', debug_flags)
586         conf.env.append_value('CXXFLAGS', debug_flags)
587     else:
588         conf.env.append_value('CFLAGS', optimization_flags)
589         conf.env.append_value('CXXFLAGS', optimization_flags)
590
591     if opt.backtrace:
592         if platform != 'darwin' and not is_clang and not Options.options.dist_target == 'mingw':
593             linker_flags += [ '-rdynamic' ]
594
595     conf.env.append_value('CFLAGS', compiler_flags)
596     conf.env.append_value('CFLAGS', c_flags)
597     conf.env.append_value('CXXFLAGS', compiler_flags)
598     conf.env.append_value('CXXFLAGS', cxx_flags)
599     conf.env.append_value('LINKFLAGS', linker_flags)
600
601 def is_tracks_build (conf):
602         return conf.env['PROGRAM_NAME'] == 'Tracks Live'
603     
604 #----------------------------------------------------------------
605
606 # Waf stages
607
608 def options(opt):
609     opt.load('compiler_c')
610     opt.load('compiler_cxx')
611     autowaf.set_options(opt, debug_by_default=True)
612     opt.add_option('--program-name', type='string', action='store', default='Ardour', dest='program_name',
613                     help='The user-visible name of the program being built')
614     opt.add_option('--arch', type='string', action='store', dest='arch',
615                     help='Architecture-specific compiler FLAGS')
616     opt.add_option('--with-backends', type='string', action='store', default='jack', dest='with_backends',
617                     help='Specify which backend modules are to be included(jack,alsa,wavesaudio,dummy,coreaudio)')
618     opt.add_option('--backtrace', action='store_true', default=False, dest='backtrace',
619                     help='Compile with -rdynamic -- allow obtaining backtraces from within Ardour')
620     opt.add_option('--no-carbon', action='store_true', default=False, dest='nocarbon',
621                     help='Compile without support for AU Plugins with only CARBON UI (needed for 64bit)')
622     opt.add_option('--boost-sp-debug', action='store_true', default=False, dest='boost_sp_debug',
623                     help='Compile with Boost shared pointer debugging')
624     opt.add_option('--debug-symbols', action='store_true', default=False, dest='debug_symbols',
625                     help='Add debug-symbols to optimized builds')
626     opt.add_option('--depstack-root', type='string', default='~', dest='depstack_root',
627                     help='Directory/folder where dependency stack trees (gtk, a3) can be found (defaults to ~)')
628     opt.add_option('--dist-target', type='string', default='auto', dest='dist_target',
629                     help='Specify the target for cross-compiling [auto,none,x86,i386,i686,x86_64,tiger,leopard,mingw,msvc]')
630     opt.add_option('--fpu-optimization', action='store_true', default=True, dest='fpu_optimization',
631                     help='Build runtime checked assembler code (default)')
632     opt.add_option('--no-fpu-optimization', action='store_false', dest='fpu_optimization')
633     opt.add_option('--exports-hidden', action='store_true', default=False, dest='exports_hidden')
634     opt.add_option('--freedesktop', action='store_true', default=False, dest='freedesktop',
635                     help='Install MIME type, icons and .desktop file as per freedesktop.org standards')
636     opt.add_option('--freebie', action='store_true', default=False, dest='freebie',
637                     help='Build a version suitable for distribution as a zero-cost binary')
638     opt.add_option('--gprofile', action='store_true', default=False, dest='gprofile',
639                     help='Compile for use with gprofile')
640     opt.add_option('--libjack', type='string', default="auto", dest='libjack_link',
641                     help='libjack link mode  [auto|link|weak]')
642     opt.add_option('--internal-shared-libs', action='store_true', default=True, dest='internal_shared_libs',
643                    help='Build internal libs as shared libraries')
644     opt.add_option('--internal-static-libs', action='store_false', dest='internal_shared_libs',
645                    help='Build internal libs as static libraries')
646     opt.add_option('--use-external-libs', action='store_true', default=False, dest='use_external_libs',
647                    help='Use external/system versions of some bundled libraries')
648     opt.add_option('--lv2', action='store_true', default=True, dest='lv2',
649                     help='Compile with support for LV2 (if Lilv+Suil is available)')
650     opt.add_option('--no-lv2', action='store_false', dest='lv2',
651                     help='Do not compile with support for LV2')
652     opt.add_option('--lv2dir', type='string', help="install destination for builtin LV2 bundles [Default: LIBDIR/lv2]")
653     opt.add_option('--lxvst', action='store_true', default=True, dest='lxvst',
654                     help='Compile with support for linuxVST plugins')
655     opt.add_option('--no-lxvst', action='store_false', dest='lxvst',
656                     help='Compile without support for linuxVST plugins')
657     opt.add_option('--no-lrdf', action='store_true', dest='no_lrdf',
658                     help='Compile without support for LRDF LADSPA data even if present')
659     opt.add_option('--nls', action='store_true', default=True, dest='nls',
660                     help='Enable i18n (native language support) (default)')
661     opt.add_option('--no-nls', action='store_false', dest='nls')
662     opt.add_option('--phone-home', action='store_true', default=True, dest='phone_home',
663                    help='Contact ardour.org at startup for new announcements')
664     opt.add_option('--no-phone-home', action='store_false', dest='phone_home',
665                    help='Do not contact ardour.org at startup for new announcements')
666     opt.add_option('--stl-debug', action='store_true', default=False, dest='stl_debug',
667                     help='Build with debugging for the STL')
668     opt.add_option('--rt-alloc-debug', action='store_true', default=False, dest='rt_alloc_debug',
669                     help='Build with debugging for memory allocation in the real-time thread')
670     opt.add_option('--pt-timing', action='store_true', default=False, dest='pt_timing',
671                     help='Build with logging of timing in the process thread(s)')
672     opt.add_option('--denormal-exception', action='store_true', default=False, dest='denormal_exception',
673                     help='Raise a floating point exception if a denormal is detected')
674     opt.add_option('--test', action='store_true', default=False, dest='build_tests',
675                     help="Build unit tests")
676     opt.add_option('--run-tests', action='store_true', default=False, dest='run_tests',
677                     help="Run tests after build")
678     opt.add_option('--single-tests', action='store_true', default=False, dest='single_tests',
679                     help="Build a single executable for each unit test")
680     #opt.add_option('--tranzport', action='store_true', default=False, dest='tranzport',
681     # help='Compile with support for Frontier Designs Tranzport (if libusb is available)')
682     opt.add_option('--generic', action='store_true', default=False, dest='generic',
683                     help='Compile with -arch i386 (OS X ONLY)')
684     opt.add_option('--ppc', action='store_true', default=False, dest='ppc',
685                     help='Compile with -arch ppc (OS X ONLY)')
686     opt.add_option('--versioned', action='store_true', default=False, dest='versioned',
687                     help='Add revision information to executable name inside the build directory')
688     opt.add_option('--windows-vst', action='store_true', default=False, dest='windows_vst',
689                     help='Compile with support for Windows VST')
690     opt.add_option('--windows-key', type='string', action='store', dest='windows_key', default='Mod4><Super',
691                     help='X Modifier(s) (Mod1,Mod2, etc) for the Windows key (X11 builds only). ' +
692                     'Multiple modifiers must be separated by \'><\'')
693     opt.add_option('--boost-include', type='string', action='store', dest='boost_include', default='',
694                     help='directory where Boost header files can be found')
695     opt.add_option('--also-include', type='string', action='store', dest='also_include', default='',
696                     help='additional include directory where header files can be found (split multiples with commas)')
697     opt.add_option('--also-libdir', type='string', action='store', dest='also_libdir', default='',
698                     help='additional include directory where shared libraries can be found (split multiples with commas)')
699     opt.add_option('--wine-include', type='string', action='store', dest='wine_include', default='/usr/include/wine/windows',
700                     help='directory where Wine\'s Windows header files can be found')
701     opt.add_option('--noconfirm', action='store_true', default=False, dest='noconfirm',
702                     help='Do not ask questions that require confirmation during the build')
703     opt.add_option('--cxx11', action='store_true', default=False, dest='cxx11',
704                     help='Turn on c++11 compiler flags (-std=c++11)')
705     opt.add_option('--address-sanitizer', action='store_true', default=False, dest='asan',
706                     help='Turn on AddressSanitizer (requires GCC >= 4.8 or clang >= 3.1)')
707     for i in children:
708         opt.recurse(i)
709
710 def sub_config_and_use(conf, name, has_objects = True):
711     conf.recurse(name)
712     autowaf.set_local_lib(conf, name, has_objects)
713
714 def configure(conf):
715     conf.load('compiler_c')
716     conf.load('compiler_cxx')
717     if Options.options.dist_target == 'mingw':
718         conf.load('winres')
719
720     if Options.options.dist_target == 'msvc':
721         conf.env['MSVC_VERSIONS'] = ['msvc 10.0', 'msvc 9.0', 'msvc 8.0', 'msvc 7.1', 'msvc 7.0', 'msvc 6.0', ]
722         conf.env['MSVC_TARGETS'] = ['x64']
723         conf.load('msvc')
724
725     if Options.options.debug:
726         # Nuke user CFLAGS/CXXFLAGS if debug is set (they likely contain -O3, NDEBUG, etc)
727         conf.env['CFLAGS'] = []
728         conf.env['CXXFLAGS'] = []
729
730     conf.env['VERSION'] = VERSION
731     conf.env['MAJOR'] = MAJOR
732     conf.env['MINOR'] = MINOR
733     conf.env['MICRO'] = MICRO
734     conf.line_just = 52
735     autowaf.set_recursive()
736     autowaf.configure(conf)
737     autowaf.display_header('Ardour Configuration')
738
739     gcc_versions = fetch_gcc_version(str(conf.env['CC']))
740     if not Options.options.debug and gcc_versions[0] == '4' and gcc_versions[1] > '4':
741         print('Version 4.5 of gcc is not ready for use when compiling Ardour with optimization.')
742         print('Please use a different version or re-configure with --debug')
743         exit (1)
744
745     # systems with glibc have libintl builtin. systems without require explicit
746     # linkage against libintl.
747     #
748
749     pkg_config_path = os.getenv('PKG_CONFIG_PATH')
750     user_gtk_root = os.path.expanduser (Options.options.depstack_root + '/gtk/inst')
751
752     if pkg_config_path is not None and pkg_config_path.find (user_gtk_root) >= 0:
753         # told to search user_gtk_root
754         prefinclude = ''.join ([ '-I', user_gtk_root + '/include'])
755         preflib = ''.join ([ '-L', user_gtk_root + '/lib'])
756         conf.env.append_value('CFLAGS', [ prefinclude ])
757         conf.env.append_value('CXXFLAGS',  [prefinclude ])
758         conf.env.append_value('LINKFLAGS', [ preflib ])
759         autowaf.display_msg(conf, 'Will build against private GTK dependency stack in ' + user_gtk_root, 'yes')
760     else:
761         autowaf.display_msg(conf, 'Will build against private GTK dependency stack', 'no')
762
763     if sys.platform == 'darwin':
764         conf.define ('NEED_INTL', 1)
765         autowaf.display_msg(conf, 'Will use explicit linkage against libintl in ' + user_gtk_root, 'yes')
766     else:
767         # libintl is part of the system, so use it
768         autowaf.display_msg(conf, 'Will rely on libintl built into libc', 'yes')
769             
770     user_ardour_root = os.path.expanduser (Options.options.depstack_root + '/a3/inst')
771     if pkg_config_path is not None and pkg_config_path.find (user_ardour_root) >= 0:
772         # told to search user_ardour_root
773         prefinclude = ''.join ([ '-I', user_ardour_root + '/include'])
774         preflib = ''.join ([ '-L', user_ardour_root + '/lib'])
775         conf.env.append_value('CFLAGS', [ prefinclude ])
776         conf.env.append_value('CXXFLAGS',  [prefinclude ])
777         conf.env.append_value('LINKFLAGS', [ preflib ])
778         autowaf.display_msg(conf, 'Will build against private Ardour dependency stack in ' + user_ardour_root, 'yes')
779     else:
780         autowaf.display_msg(conf, 'Will build against private Ardour dependency stack', 'no')
781         
782     if Options.options.freebie:
783         conf.env.append_value ('CFLAGS', '-DSILENCE_AFTER')
784         conf.env.append_value ('CXXFLAGS', '-DSILENCE_AFTER')
785         conf.define ('FREEBIE', 1)
786
787     if Options.options.lv2dir:
788         conf.env['LV2DIR'] = Options.options.lv2dir
789     else:
790         conf.env['LV2DIR'] = os.path.join(conf.env['LIBDIR'], 'ardour' + str(conf.env['MAJOR']), 'lv2')
791
792     conf.env['LV2DIR'] = os.path.normpath(conf.env['LV2DIR'])
793
794     if sys.platform == 'darwin':
795
796         # this is required, potentially, for anything we link and then relocate into a bundle
797         conf.env.append_value('LINKFLAGS', [ '-Xlinker', '-headerpad_max_install_names' ])
798
799         conf.define ('HAVE_COREAUDIO', 1)
800         conf.define ('AUDIOUNIT_SUPPORT', 1)
801
802         conf.define ('GTKOSX', 1)
803         conf.define ('TOP_MENUBAR',1)
804         conf.define ('GTKOSX',1)
805
806         # It would be nice to be able to use this to force back-compatibility with 10.4
807         # but even by the time of 11, the 10.4 SDK is no longer available in any normal
808         # way.
809         #
810         #conf.env.append_value('CXXFLAGS_OSX', "-isysroot /Developer/SDKs/MacOSX10.4u.sdk")
811         #conf.env.append_value('CFLAGS_OSX', "-isysroot /Developer/SDKs/MacOSX10.4u.sdk")
812         #conf.env.append_value('LINKFLAGS_OSX', "-sysroot /Developer/SDKs/MacOSX10.4u.sdk")
813         #conf.env.append_value('LINKFLAGS_OSX', "-sysroot /Developer/SDKs/MacOSX10.4u.sdk")
814
815         conf.env.append_value('CXXFLAGS_OSX', "-msse")
816         conf.env.append_value('CFLAGS_OSX', "-msse")
817         conf.env.append_value('CXXFLAGS_OSX', "-msse2")
818         conf.env.append_value('CFLAGS_OSX', "-msse2")
819         #
820         #       TODO: The previous sse flags NEED to be based
821         #       off processor type.  Need to add in a check
822         #       for that.
823         #
824         conf.env.append_value('CXXFLAGS_OSX', '-F/System/Library/Frameworks')
825         conf.env.append_value('CXXFLAGS_OSX', '-F/Library/Frameworks')
826
827         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'AppKit'])
828         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreAudio'])
829         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreAudioKit'])
830         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreFoundation'])
831         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreServices'])
832
833         conf.env.append_value('LINKFLAGS_OSX', ['-undefined', 'dynamic_lookup' ])
834         conf.env.append_value('LINKFLAGS_OSX', ['-flat_namespace'])
835
836         conf.env.append_value('CXXFLAGS_AUDIOUNITS', "-DAUDIOUNIT_SUPPORT")
837         conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'AudioToolbox', '-framework', 'AudioUnit'])
838         conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'Cocoa'])
839
840         if (
841                 # osx up to and including 10.6 (uname 10.X.X)
842                 (re.search ("^[1-9][0-9]\.", os.uname()[2]) == None or not re.search ("^10\.", os.uname()[2]) == None)
843                 and (Options.options.generic or Options.options.ppc)
844                 and not Options.options.nocarbon
845            ):
846             conf.env.append_value('CXXFLAGS_AUDIOUNITS', "-DWITH_CARBON")
847             conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'Carbon'])
848         else:
849             print ('No Carbon support available for this build\n')
850
851
852     if Options.options.internal_shared_libs: 
853         conf.define('INTERNAL_SHARED_LIBS', 1)
854
855     if Options.options.use_external_libs:
856         conf.define('USE_EXTERNAL_LIBS', 1)
857
858     if Options.options.boost_include != '':
859         conf.env.append_value('CXXFLAGS', '-I' + Options.options.boost_include)
860
861     if Options.options.also_include != '':
862         conf.env.append_value('CXXFLAGS', '-I' + Options.options.also_include)
863         conf.env.append_value('CFLAGS', '-I' + Options.options.also_include)
864
865     if Options.options.also_libdir != '':
866         conf.env.append_value('LDFLAGS', '-L' + Options.options.also_libdir)
867
868     if Options.options.boost_sp_debug:
869         conf.env.append_value('CXXFLAGS', '-DBOOST_SP_ENABLE_DEBUG_HOOKS')
870
871     # executing a test program is n/a when cross-compiling
872     if Options.options.dist_target != 'mingw':
873         if Options.options.dist_target != 'msvc':
874             conf.check_cc(function_name='dlopen', header_name='dlfcn.h', lib='dl', uselib_store='DL')
875         conf.check_cxx(fragment = "#include <boost/version.hpp>\nint main(void) { return (BOOST_VERSION >= 103900 ? 0 : 1); }\n",
876                   execute = "1",
877                   mandatory = True,
878                   msg = 'Checking for boost library >= 1.39',
879                   okmsg = 'ok',
880                   errmsg = 'too old\nPlease install boost version 1.39 or higher.')
881
882     if re.search ("linux", sys.platform) != None and Options.options.dist_target != 'mingw':
883         autowaf.check_pkg(conf, 'alsa', uselib_store='ALSA')
884
885     autowaf.check_pkg(conf, 'glib-2.0', uselib_store='GLIB', atleast_version='2.28', mandatory=True)
886     autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD', atleast_version='2.2', mandatory=True)
887     autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.32.0', mandatory=True)
888     autowaf.check_pkg(conf, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.18', mandatory=True)
889     autowaf.check_pkg(conf, 'giomm-2.4', uselib_store='GIOMM', atleast_version='2.2', mandatory=True)
890     autowaf.check_pkg(conf, 'libcurl', uselib_store='CURL', atleast_version='7.0.0', mandatory=True)
891     autowaf.check_pkg(conf, 'liblo', uselib_store='LO', atleast_version='0.26', mandatory=True)
892     autowaf.check_pkg(conf, 'taglib', uselib_store='TAGLIB', atleast_version='1.6', mandatory=True)
893     autowaf.check_pkg(conf, 'vamp-sdk', uselib_store='VAMPSDK', atleast_version='2.1', mandatory=True)
894     autowaf.check_pkg(conf, 'vamp-hostsdk', uselib_store='VAMPHOSTSDK', atleast_version='2.1', mandatory=True)
895     autowaf.check_pkg(conf, 'rubberband', uselib_store='RUBBERBAND', mandatory=True)
896
897     if Options.options.dist_target == 'mingw':
898         Options.options.fpu_optimization = True
899         conf.env.append_value('CFLAGS', '-DPLATFORM_WINDOWS')
900         conf.env.append_value('CFLAGS', '-DCOMPILER_MINGW')
901         conf.env.append_value('CXXFLAGS', '-DPLATFORM_WINDOWS')
902         conf.env.append_value('CXXFLAGS', '-DCOMPILER_MINGW')
903         conf.env.append_value('LIB', 'pthread')
904         # needed for at least libsmf
905         conf.check_cc(function_name='htonl', header_name='winsock2.h', lib='ws2_32')
906         conf.env.append_value('LIB', 'ws2_32')
907         conf.env.append_value('LIB', 'winmm')
908         # needed for mingw64 packages, not harmful on normal mingw build
909         conf.env.append_value('LIB', 'intl')
910         conf.check_cc(function_name='regcomp', header_name='regex.h',
911                       lib='regex', uselib_store="REGEX", define_name='HAVE_REGEX_H')
912         # TODO put this only where it is needed
913         conf.env.append_value('LIB', 'regex')
914         # TODO this should only be necessary for a debug build
915         conf.env.append_value('LIB', 'dbghelp')
916         
917         # work around GdkDrawable BitBlt performance issue on windows
918         # see http://gareus.org/wiki/ardour_windows_gdk_and_cairo
919         conf.env.append_value('CFLAGS', '-DUSE_CAIRO_IMAGE_SURFACE')
920         conf.env.append_value('CXXFLAGS', '-DUSE_CAIRO_IMAGE_SURFACE')
921         conf.define ('WINDOWS', 1)
922
923     if Options.options.dist_target == 'msvc':
924         conf.env.append_value('CFLAGS', '-DPLATFORM_WINDOWS')
925         conf.env.append_value('CFLAGS', '-DCOMPILER_MSVC')
926         conf.env.append_value('CXXFLAGS', '-DPLATFORM_WINDOWS')
927         conf.env.append_value('CXXFLAGS', '-DCOMPILER_MSVC')
928         # work around GdkDrawable BitBlt performance issue on windows
929         # see http://gareus.org/wiki/ardour_windows_gdk_and_cairo
930         conf.env.append_value('CFLAGS', '-DUSE_CAIRO_IMAGE_SURFACE')
931         conf.env.append_value('CXXFLAGS', '-DUSE_CAIRO_IMAGE_SURFACE')
932         # MORE STUFF PROBABLY NEEDED HERE
933         conf.define ('WINDOWS', 1)
934         
935     # Tell everyone that this is a waf build
936
937     conf.env.append_value('CFLAGS', '-DWAF_BUILD')
938     conf.env.append_value('CXXFLAGS', '-DWAF_BUILD')
939
940     opts = Options.options
941
942     # (optionally) Adopt Microsoft-like convention that makes all non-explicitly exported
943     # symbols invisible (rather than doing this all over the wscripts in the src tree)
944     #
945     # This won't apply to MSVC but that hasn't been added as a target yet
946     #
947     # We can't do this till all tests are complete, since some fail if this is et.
948     if opts.exports_hidden:
949         conf.define ('EXPORT_VISIBILITY_HIDDEN', True)
950         if opts.internal_shared_libs:
951             conf.env.append_value ('CXXFLAGS', '-fvisibility=hidden')
952             conf.env.append_value ('CFLAGS', '-fvisibility=hidden')
953     else:
954         conf.define ('EXPORT_VISIBILITY_HIDDEN', False)
955
956     # Set up waf environment and C defines
957     if opts.phone_home:
958         conf.define('PHONE_HOME', 1)
959         conf.env['PHONE_HOME'] = True
960     if opts.fpu_optimization:
961         conf.env['FPU_OPTIMIZATION'] = True
962     if opts.nls:
963         conf.define('ENABLE_NLS', 1)
964         conf.env['ENABLE_NLS'] = True
965     if opts.build_tests:
966         conf.env['BUILD_TESTS'] = True
967         conf.env['RUN_TESTS'] = opts.run_tests
968     if opts.single_tests:
969         conf.env['SINGLE_TESTS'] = opts.single_tests
970     #if opts.tranzport:
971     #    conf.env['TRANZPORT'] = 1
972     if opts.windows_vst:
973         conf.define('WINDOWS_VST_SUPPORT', 1)
974         conf.env['WINDOWS_VST_SUPPORT'] = True
975         if not Options.options.dist_target == 'mingw':
976             conf.env.append_value('CFLAGS', '-I' + Options.options.wine_include)
977             conf.env.append_value('CXXFLAGS', '-I' + Options.options.wine_include)
978             autowaf.check_header(conf, 'cxx', 'windows.h', mandatory = True)
979     if opts.lxvst:
980         if sys.platform == 'darwin':
981             conf.env['LXVST_SUPPORT'] = False
982         elif Options.options.dist_target == 'mingw':
983             conf.env['LXVST_SUPPORT'] = False
984         else:
985             conf.define('LXVST_SUPPORT', 1)
986             conf.env['LXVST_SUPPORT'] = True
987     conf.env['WINDOWS_KEY'] = opts.windows_key
988     if opts.rt_alloc_debug:
989         conf.define('DEBUG_RT_ALLOC', 1)
990         conf.env['DEBUG_RT_ALLOC'] = True
991     if opts.pt_timing:
992         conf.define('PT_TIMING', 1)
993         conf.env['PT_TIMING'] = True
994     if opts.denormal_exception:
995         conf.define('DEBUG_DENORMAL_EXCEPTION', 1)
996         conf.env['DEBUG_DENORMAL_EXCEPTION'] = True
997     if opts.build_tests:
998         autowaf.check_pkg(conf, 'cppunit', uselib_store='CPPUNIT', atleast_version='1.12.0', mandatory=True)
999
1000     backends = opts.with_backends.split(',')
1001
1002     if not backends:
1003         print("Must configure and build at least one backend")
1004         sys.exit(1)
1005
1006     if conf.is_tracks_build():
1007         # For Tracks, override backends on OS X or Windows    
1008         if sys.platform == 'darwin' or sys.platform == 'mingw' or sys.platform == 'msvc':
1009             backends = [ 'wavesaudio' ]
1010
1011     conf.env['BACKENDS'] = backends
1012     conf.env['BUILD_JACKBACKEND'] = any('jack' in b for b in backends)
1013     conf.env['BUILD_ALSABACKEND'] = any('alsa' in b for b in backends)
1014     conf.env['BUILD_DUMMYBACKEND'] = any('dummy' in b for b in backends)
1015     conf.env['BUILD_WAVESBACKEND'] = any('wavesaudio' in b for b in backends)
1016     conf.env['BUILD_CORECRAPPITA'] = any('coreaudio' in b for b in backends)
1017
1018     if conf.env['BUILD_CORECRAPPITA'] and conf.env['BUILD_WAVESBACKEND']:
1019         print("Coreaudio + Waves Backend are mutually exclusive")
1020         sys.exit(1)
1021
1022     if sys.platform != 'darwin' and conf.env['BUILD_CORECRAPPITA']:
1023         print("Coreaudio backend is only available for OSX")
1024         sys.exit(1)
1025
1026     if re.search ("linux", sys.platform) != None and Options.options.dist_target != 'mingw' and conf.env['BUILD_WAVESBACKEND']:
1027         print("Waves Backend is not for Linux")
1028         sys.exit(1)
1029
1030     if re.search ("linux", sys.platform) == None and conf.env['BUILD_ALSABACKEND']:
1031         print("ALSA Backend is only available on Linux")
1032         sys.exit(1)
1033
1034     set_compiler_flags (conf, Options.options)
1035
1036     if sys.platform == 'darwin':
1037         sub_config_and_use(conf, 'libs/appleutility')
1038     elif Options.options.dist_target != 'mingw':
1039         sub_config_and_use(conf, 'tools/sanity_check')
1040
1041     sub_config_and_use(conf, 'libs/clearlooks-newer')
1042
1043     for i in children:
1044         sub_config_and_use(conf, i)
1045
1046     # Fix utterly braindead FLAC include path to not smash assert.h
1047     conf.env['INCLUDES_FLAC'] = []
1048
1049     config_text = open('libs/ardour/config_text.cc', "w")
1050     config_text.write('''#include "ardour/ardour.h"
1051 namespace ARDOUR {
1052 const char* const ardour_config_info = "\\n\\
1053 ''')
1054
1055     def write_config_text(title, val):
1056         autowaf.display_msg(conf, title, val)
1057         config_text.write(title + ': ')
1058         config_text.write(str(val).replace ('"', '\\"'))
1059         config_text.write("\\n\\\n")
1060
1061     write_config_text('Build documentation',   conf.env['DOCS'])
1062     write_config_text('Debuggable build',      conf.env['DEBUG'])
1063     write_config_text('Export all symbols (backtrace)', opts.backtrace)
1064     write_config_text('Install prefix',        conf.env['PREFIX'])
1065     write_config_text('Strict compiler flags', conf.env['STRICT'])
1066     write_config_text('Internal Shared Libraries', conf.is_defined('INTERNAL_SHARED_LIBS'))
1067     write_config_text('Use External Libraries', conf.is_defined('USE_EXTERNAL_LIBS'))
1068     write_config_text('Library exports hidden', conf.is_defined('EXPORT_VISIBILITY_HIDDEN'))
1069
1070     write_config_text('ALSA Backend',          conf.env['BUILD_ALSABACKEND'])
1071     write_config_text('ALSA DBus Reservation', conf.is_defined('HAVE_DBUS'))
1072     write_config_text('Architecture flags',    opts.arch)
1073     write_config_text('Aubio',                 conf.is_defined('HAVE_AUBIO'))
1074     write_config_text('AudioUnits',            conf.is_defined('AUDIOUNIT_SUPPORT'))
1075     write_config_text('Free/Demo copy',        conf.is_defined('FREEBIE'))
1076     write_config_text('Build target',          conf.env['build_target'])
1077     write_config_text('CoreAudio',             conf.is_defined('HAVE_COREAUDIO'))
1078     write_config_text('CoreAudio/Midi Backend',conf.env['BUILD_CORECRAPPITA'])
1079     write_config_text('Debug RT allocations',  conf.is_defined('DEBUG_RT_ALLOC'))
1080     write_config_text('Debug Symbols',         conf.is_defined('debug_symbols') or conf.env['DEBUG'])
1081     write_config_text('Dummy backend',         conf.env['BUILD_DUMMYBACKEND'])
1082     write_config_text('Process thread timing', conf.is_defined('PT_TIMING'))
1083     write_config_text('Denormal exceptions',   conf.is_defined('DEBUG_DENORMAL_EXCEPTION'))
1084     write_config_text('FLAC',                  conf.is_defined('HAVE_FLAC'))
1085     write_config_text('FPU optimization',      opts.fpu_optimization)
1086     write_config_text('Freedesktop files',     opts.freedesktop)
1087     write_config_text('JACK Backend',          conf.env['BUILD_JACKBACKEND'])
1088     write_config_text('Libjack linking',       conf.env['libjack_link'])
1089     write_config_text('Libjack metadata',      conf.is_defined ('HAVE_JACK_METADATA'))
1090     write_config_text('LV2 UI embedding',      conf.is_defined('HAVE_SUIL'))
1091     write_config_text('LV2 support',           conf.is_defined('LV2_SUPPORT'))
1092     write_config_text('LXVST support',         conf.is_defined('LXVST_SUPPORT'))
1093     write_config_text('OGG',                   conf.is_defined('HAVE_OGG'))
1094     write_config_text('Phone home',            conf.is_defined('PHONE_HOME'))
1095     write_config_text('Program name',          opts.program_name)
1096     write_config_text('Samplerate',            conf.is_defined('HAVE_SAMPLERATE'))
1097 #    write_config_text('Soundtouch',            conf.is_defined('HAVE_SOUNDTOUCH'))
1098     write_config_text('Translation',           opts.nls)
1099 #    write_config_text('Tranzport',             opts.tranzport)
1100     write_config_text('Unit tests',            conf.env['BUILD_TESTS'])
1101     write_config_text('Mac i386 Architecture', opts.generic)
1102     write_config_text('Mac ppc Architecture',  opts.ppc)
1103     write_config_text('Waves Backend',         conf.env['BUILD_WAVESBACKEND'])
1104     write_config_text('Windows VST support',   opts.windows_vst)
1105     write_config_text('Wiimote support',       conf.is_defined('BUILD_WIIMOTE'))
1106     write_config_text('Windows key',           opts.windows_key)
1107
1108     write_config_text('C compiler flags',      conf.env['CFLAGS'])
1109     write_config_text('C++ compiler flags',    conf.env['CXXFLAGS'])
1110     write_config_text('Linker flags',          conf.env['LINKFLAGS'])
1111
1112     config_text.write ('";\n}\n')
1113     config_text.close ()
1114     print('')
1115
1116 def build(bld):
1117     create_stored_revision()
1118
1119     # add directories that contain only headers, to workaround an issue with waf
1120
1121     if not bld.is_defined('USE_EXTERNAL_LIBS'):
1122         bld.path.find_dir ('libs/libltc/ltc')
1123     bld.path.find_dir ('libs/evoral/evoral')
1124     bld.path.find_dir ('libs/surfaces/control_protocol/control_protocol')
1125     bld.path.find_dir ('libs/timecode/timecode')
1126     bld.path.find_dir ('libs/gtkmm2ext/gtkmm2ext')
1127     bld.path.find_dir ('libs/ardour/ardour')
1128     bld.path.find_dir ('libs/pbd/pbd')
1129
1130     # set up target directories
1131     lwrcase_dirname = 'ardour' + bld.env['MAJOR']
1132
1133     if bld.is_tracks_build():
1134         bld.env.append_value ('CXXFLAGS', '-DUSE_TRACKS_CODE_FEATURES')
1135         bld.env.append_value ('CFLAGS', '-DUSE_TRACKS_CODE_FEATURES')
1136         lwrcase_dirname = 'trx'
1137         
1138     # configuration files go here
1139     bld.env['CONFDIR'] = os.path.join(bld.env['SYSCONFDIR'], lwrcase_dirname)
1140     # data files loaded at run time go here
1141     bld.env['DATADIR'] = os.path.join(bld.env['DATADIR'], lwrcase_dirname)
1142     # shared objects loaded at runtime go here (two aliases)
1143     bld.env['DLLDIR'] = os.path.join(bld.env['LIBDIR'], lwrcase_dirname)
1144     bld.env['LIBDIR'] = bld.env['DLLDIR']
1145     bld.env['LOCALEDIR'] = os.path.join(bld.env['DATADIR'], 'locale')
1146     bld.env['lwrcase_dirname'] = lwrcase_dirname;
1147
1148     autowaf.set_recursive()
1149
1150     if sys.platform == 'darwin':
1151         bld.recurse('libs/appleutility')
1152     elif bld.env['build_target'] != 'mingw':
1153         bld.recurse('tools/sanity_check')
1154
1155     bld.recurse('libs/clearlooks-newer')
1156
1157     for i in children:
1158         bld.recurse(i)
1159
1160     bld.install_files (bld.env['CONFDIR'], 'system_config')
1161
1162     if bld.env['RUN_TESTS']:
1163         bld.add_post_fun(test)
1164
1165 def i18n(bld):
1166     print(bld.env)
1167     bld.recurse (i18n_children)
1168
1169 def i18n_pot(bld):
1170     bld.recurse (i18n_children)
1171
1172 def i18n_po(bld):
1173     bld.recurse (i18n_children)
1174
1175 def i18n_mo(bld):
1176     bld.recurse (i18n_children)
1177
1178 def tarball(bld):
1179     create_stored_revision()
1180
1181 def test(bld):
1182     subprocess.call("gtk2_ardour/artest")