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