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