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