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