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