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