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