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