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