Merge branch 'master' into cairocanvas
[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
10 VERSION = '3.1'
11
12 APPNAME = 'Ardour3'
13
14 # Mandatory variables
15 top = '.'
16 out = 'build'
17
18 children = [
19         'libs/pbd',
20         'libs/midi++2',
21         'libs/evoral',
22         'libs/vamp-sdk',
23         'libs/qm-dsp',
24         'libs/vamp-plugins',
25         'libs/taglib',
26         'libs/libltc',
27         'libs/rubberband',
28         'libs/surfaces',
29         'libs/panners',
30         'libs/timecode',
31         'libs/ardour',
32         'libs/gtkmm2ext',
33         'libs/clearlooks-newer',
34         'libs/audiographer',
35         'libs/canvas',
36         'gtk2_ardour',
37         'export',
38         'midi_maps',
39         'mcp',
40         'patchfiles'
41 ]
42
43 i18n_children = [
44         'gtk2_ardour',
45         'libs/ardour',
46         'libs/gtkmm2ext',
47 ]
48
49 if sys.platform == 'linux2':
50     children += [ 'tools/sanity_check' ]
51     lxvst_default = True
52 elif sys.platform == 'darwin':
53     children += [ 'libs/appleutility' ]
54     lxvst_default = False
55 else:
56     lxvst_default = False
57
58 # Version stuff
59
60 def fetch_gcc_version (CC):
61     cmd = "LANG= %s --version" % CC
62     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
63     o = output[0].decode('utf-8')
64     version = o.split(' ')[2].split('.')
65     return version
66
67 def fetch_git_revision ():
68     cmd = "LANG= git describe --tags HEAD"
69     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
70     rev = output[0].decode('utf-8')
71     return rev
72
73 def create_stored_revision():
74     rev = ""
75     if os.path.exists('.git'):
76         rev = fetch_git_revision();
77         print("ardour.git version: " + rev + "\n")
78     elif os.path.exists('libs/ardour/revision.cc'):
79         print("Using packaged revision")
80         return
81     else:
82         print("Missing libs/ardour/revision.cc.  Blame the packager.")
83         sys.exit(-1)
84
85     try:
86         text =  '#include "ardour/revision.h"\n'
87         text += 'namespace ARDOUR { const char* revision = \"%s\"; }\n' % rev
88         print('Writing revision info to libs/ardour/revision.cc using ' + rev)
89         o = open('libs/ardour/revision.cc', 'w')
90         o.write(text)
91         o.close()
92     except IOError:
93         print('Could not open libs/ardour/revision.cc for writing\n')
94         sys.exit(-1)
95
96 def set_compiler_flags (conf,opt):
97     #
98     # Compiler flags and other system-dependent stuff
99     #
100
101     build_host_supports_sse = False
102     optimization_flags = []
103     debug_flags = []
104
105     u = os.uname ()
106     cpu = u[4]
107     platform = u[0].lower()
108     version = u[2]
109
110     is_clang = conf.env['CXX'][0].endswith('clang++')
111     if opt.gprofile:
112         debug_flags = [ '-pg' ]
113     else:
114         if platform != 'darwin' and not is_clang:
115             debug_flags = [ '-rdynamic' ] # waf adds -O0 -g itself. thanks waf!
116
117     # Autodetect
118     if opt.dist_target == 'auto':
119         if platform == 'darwin':
120             # The [.] matches to the dot after the major version, "." would match any character
121             if re.search ("^[0-7][.]", version) != None:
122                 conf.env['build_target'] = 'panther'
123             elif re.search ("^8[.]", version) != None:
124                 conf.env['build_target'] = 'tiger'
125             elif re.search ("^9[.]", version) != None:
126                 conf.env['build_target'] = 'leopard'
127             elif re.search ("^10[.]", version) != None:
128                 conf.env['build_target'] = 'snowleopard'
129             elif re.search ("^11[.]", version) != None:
130                 conf.env['build_target'] = 'lion'
131             else:
132                 conf.env['build_target'] = 'mountainlion'
133         else:
134             if re.search ("x86_64", cpu) != None:
135                 conf.env['build_target'] = 'x86_64'
136             elif re.search("i[0-5]86", cpu) != None:
137                 conf.env['build_target'] = 'i386'
138             elif re.search("powerpc", cpu) != None:
139                 conf.env['build_target'] = 'powerpc'
140             else:
141                 conf.env['build_target'] = 'i686'
142     else:
143         conf.env['build_target'] = opt.dist_target
144
145     if conf.env['build_target'] == 'snowleopard':
146         #
147         # stupid OS X 10.6 has a bug in math.h that prevents llrint and friends
148         # from being visible.
149         # 
150         debug_flags.append ('-U__STRICT_ANSI__')
151         optimization_flags.append ('-U__STRICT_ANSI__')
152
153     if cpu == 'powerpc' and conf.env['build_target'] != 'none':
154         #
155         # Apple/PowerPC optimization options
156         #
157         # -mcpu=7450 does not reliably work with gcc 3.*
158         #
159         if opt.dist_target == 'panther' or opt.dist_target == 'tiger':
160             if platform == 'darwin':
161                 # optimization_flags.extend ([ "-mcpu=7450", "-faltivec"])
162                 # to support g3s but still have some optimization for above
163                 optimization_flags.extend ([ "-mcpu=G3", "-mtune=7450"])
164             else:
165                 optimization_flags.extend ([ "-mcpu=7400", "-maltivec", "-mabi=altivec"])
166         else:
167             optimization_flags.extend([ "-mcpu=750", "-mmultiple" ])
168         optimization_flags.extend (["-mhard-float", "-mpowerpc-gfxopt"])
169         optimization_flags.extend (["-Os"])
170
171     elif ((re.search ("i[0-9]86", cpu) != None) or (re.search ("x86_64", cpu) != None)) and conf.env['build_target'] != 'none':
172
173
174         #
175         # ARCH_X86 means anything in the x86 family from i386 to x86_64
176         # the compile-time presence of the macro _LP64 is used to 
177         # distingush 32 and 64 bit assembler
178         #
179
180         if (re.search ("(i[0-9]86|x86_64)", cpu) != None):
181             debug_flags.append ("-DARCH_X86")
182             optimization_flags.append ("-DARCH_X86")
183
184         if platform == 'linux' :
185
186             #
187             # determine processor flags via /proc/cpuinfo
188             #
189
190             if conf.env['build_target'] != 'i386':
191
192                 flag_line = os.popen ("cat /proc/cpuinfo | grep '^flags'").read()[:-1]
193                 x86_flags = flag_line.split (": ")[1:][0].split ()
194
195                 if "mmx" in x86_flags:
196                     optimization_flags.append ("-mmmx")
197                 if "sse" in x86_flags:
198                     build_host_supports_sse = True
199                 if "3dnow" in x86_flags:
200                     optimization_flags.append ("-m3dnow")
201
202             if cpu == "i586":
203                 optimization_flags.append ("-march=i586")
204             elif cpu == "i686":
205                 optimization_flags.append ("-march=i686")
206
207         if not is_clang and ((conf.env['build_target'] == 'i686') or (conf.env['build_target'] == 'x86_64')) and build_host_supports_sse:
208             optimization_flags.extend (["-msse", "-mfpmath=sse", "-DUSE_XMMINTRIN"])
209             debug_flags.extend (["-msse", "-mfpmath=sse", "-DUSE_XMMINTRIN"])
210
211     # end of processor-specific section
212
213     # optimization section
214     if conf.env['FPU_OPTIMIZATION']:
215         if sys.platform == 'darwin':
216             optimization_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS");
217             debug_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS");
218             conf.env.append_value('LINKFLAGS', "-framework Accelerate")
219         elif conf.env['build_target'] == 'i686' or conf.env['build_target'] == 'x86_64':
220             optimization_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
221             debug_flags.append ("-DBUILD_SSE_OPTIMIZATIONS")
222         if not build_host_supports_sse:
223             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)")
224
225     # end optimization section
226
227     #
228     # no VST on x86_64
229     #
230
231     if conf.env['build_target'] == 'x86_64' and opt.windows_vst:
232         print("\n\n==================================================")
233         print("You cannot use VST plugins with a 64 bit host. Please run waf with --windows-vst=0")
234         print("\nIt is theoretically possible to build a 32 bit host on a 64 bit system.")
235         print("However, this is tricky and not recommended for beginners.")
236         sys.exit (-1)
237
238     if opt.lxvst:
239         if conf.env['build_target'] == 'x86_64':
240             conf.env.append_value('CXXFLAGS', "-DLXVST_64BIT")
241         else:
242             conf.env.append_value('CXXFLAGS', "-DLXVST_32BIT")
243
244     #
245     # a single way to test if we're on OS X
246     #
247
248     if conf.env['build_target'] in ['panther', 'tiger', 'leopard', 'snowleopard' ]:
249         conf.define ('IS_OSX', 1)
250         # force tiger or later, to avoid issues on PPC which defaults
251         # back to 10.1 if we don't tell it otherwise.
252         
253         conf.env.append_value('CFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1040")
254         conf.env.append_value('CXXFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1040")
255         conf.env.append_value('CXXFLAGS', '-mmacosx-version-min=10.4')
256         conf.env.append_value('CFLAGS', '-mmacosx-version-min=10.4')
257
258
259     elif conf.env['build_target'] in [ 'lion', 'mountainlion' ]:
260         conf.env.append_value('CFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1070")
261         conf.env.append_value('CXXFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1070")
262         conf.env.append_value('CXXFLAGS', '-mmacosx-version-min=10.7')
263         conf.env.append_value('CFLAGS', '-mmacosx-version-min=10.7')
264     else:
265         conf.define ('IS_OSX', 0)
266
267     #
268     # save off CPU element in an env
269     #
270     conf.define ('CONFIG_ARCH', cpu)
271
272     #
273     # ARCH="..." overrides all
274     #
275
276     if opt.arch != None:
277         optimization_flags = opt.arch.split()
278
279     #
280     # prepend boiler plate optimization flags that work on all architectures
281     #
282
283     optimization_flags[:0] = [
284             "-O3",
285             "-fomit-frame-pointer",
286             "-ffast-math",
287             "-fstrength-reduce",
288             "-pipe"
289             ]
290
291     if opt.debug:
292         conf.env.append_value('CFLAGS', debug_flags)
293         conf.env.append_value('CXXFLAGS', debug_flags)
294         conf.env.append_value('LINKFLAGS', debug_flags)
295     else:
296         conf.env.append_value('CFLAGS', optimization_flags)
297         conf.env.append_value('CXXFLAGS', optimization_flags)
298         conf.env.append_value('LINKFLAGS', optimization_flags)
299
300     if opt.stl_debug:
301         conf.env.append_value('CXXFLAGS', "-D_GLIBCXX_DEBUG")
302
303     if conf.env['DEBUG_RT_ALLOC']:
304         conf.env.append_value('CFLAGS', '-DDEBUG_RT_ALLOC')
305         conf.env.append_value('CXXFLAGS', '-DDEBUG_RT_ALLOC')
306         conf.env.append_value('LINKFLAGS', '-ldl')
307
308     if conf.env['DEBUG_DENORMAL_EXCEPTION']:
309         conf.env.append_value('CFLAGS', '-DDEBUG_DENORMAL_EXCEPTION')
310         conf.env.append_value('CXXFLAGS', '-DDEBUG_DENORMAL_EXCEPTION')
311
312     if opt.universal:
313         if opt.generic:
314             print ('Specifying Universal and Generic builds at the same time is not supported')
315             sys.exit (1)
316         else:
317             if not Options.options.nocarbon:
318                 conf.env.append_value('CFLAGS', ["-arch", "i386", "-arch", "ppc"])
319                 conf.env.append_value('CXXFLAGS', ["-arch", "i386", "-arch", "ppc"])
320                 conf.env.append_value('LINKFLAGS', ["-arch", "i386", "-arch", "ppc"])
321             else:
322                 conf.env.append_value('CFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"])
323                 conf.env.append_value('CXXFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"])
324                 conf.env.append_value('LINKFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"])
325     else:
326         if opt.generic:
327             conf.env.append_value('CFLAGS', ['-arch', 'i386'])
328             conf.env.append_value('CXXFLAGS', ['-arch', 'i386'])
329             conf.env.append_value('LINKFLAGS', ['-arch', 'i386'])
330
331     #
332     # warnings flags
333     #
334
335     conf.env.append_value('CFLAGS', [ '-Wall',
336                                       '-Wpointer-arith',
337                                       '-Wcast-qual',
338                                       '-Wcast-align',
339                                       '-Wstrict-prototypes',
340                                       '-Wmissing-prototypes'
341                                       ])
342
343     conf.env.append_value('CXXFLAGS', [ '-Wall', 
344                                         '-Wpointer-arith',
345                                         '-Wcast-qual',
346                                         '-Wcast-align', 
347                                         '-Woverloaded-virtual'
348                                         ])
349
350
351     #
352     # more boilerplate
353     #
354
355     conf.env.append_value('CFLAGS', '-DBOOST_SYSTEM_NO_DEPRECATED')
356     conf.env.append_value('CXXFLAGS', '-DBOOST_SYSTEM_NO_DEPRECATED')
357     conf.env.append_value('CFLAGS', '-D_LARGEFILE64_SOURCE')
358     conf.env.append_value('CFLAGS', '-D_FILE_OFFSET_BITS=64')
359     conf.env.append_value('CXXFLAGS', '-D_LARGEFILE64_SOURCE')
360     conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64')
361
362     conf.env.append_value('CXXFLAGS', '-D__STDC_LIMIT_MACROS')
363     conf.env.append_value('CXXFLAGS', '-D__STDC_FORMAT_MACROS')
364     conf.env.append_value('CXXFLAGS', '-DCANVAS_COMPATIBILITY')
365     conf.env.append_value('CXXFLAGS', '-DCANVAS_DEBUG')
366
367     if opt.nls:
368         conf.env.append_value('CXXFLAGS', '-DENABLE_NLS')
369         conf.env.append_value('CFLAGS', '-DENABLE_NLS')
370
371 #----------------------------------------------------------------
372
373 # Waf stages
374
375 def options(opt):
376     opt.load('compiler_c')
377     opt.load('compiler_cxx')
378     autowaf.set_options(opt, debug_by_default=True)
379     opt.add_option('--program-name', type='string', action='store', default='Ardour', dest='program_name',
380                     help='The user-visible name of the program being built')
381     opt.add_option('--arch', type='string', action='store', dest='arch',
382                     help='Architecture-specific compiler flags')
383     opt.add_option('--no-carbon', action='store_true', default=False, dest='nocarbon',
384                     help='Compile without support for AU Plugins with only CARBON UI (needed for 64bit)')
385     opt.add_option('--boost-sp-debug', action='store_true', default=False, dest='boost_sp_debug',
386                     help='Compile with Boost shared pointer debugging')
387     opt.add_option('--depstack-root', type='string', default='~', dest='depstack_root',
388                     help='Directory/folder where dependency stack trees (gtk, a3) can be found (defaults to ~)')
389     opt.add_option('--dist-target', type='string', default='auto', dest='dist_target',
390                     help='Specify the target for cross-compiling [auto,none,x86,i386,i686,x86_64,powerpc,tiger,leopard]')
391     opt.add_option('--fpu-optimization', action='store_true', default=True, dest='fpu_optimization',
392                     help='Build runtime checked assembler code (default)')
393     opt.add_option('--no-fpu-optimization', action='store_false', dest='fpu_optimization')
394     opt.add_option('--freedesktop', action='store_true', default=False, dest='freedesktop',
395                     help='Install MIME type, icons and .desktop file as per freedesktop.org standards')
396     opt.add_option('--freebie', action='store_true', default=False, dest='freebie',
397                     help='Build a version suitable for distribution as a zero-cost binary')
398     opt.add_option('--no-freesound', action='store_false', default=True, dest='freesound',
399                     help='Do not build with Freesound database support')
400     opt.add_option('--gprofile', action='store_true', default=False, dest='gprofile',
401                     help='Compile for use with gprofile')
402     opt.add_option('--internal-shared-libs', action='store_true', default=True, dest='internal_shared_libs',
403                    help='Build internal libs as shared libraries')
404     opt.add_option('--internal-static-libs', action='store_false', dest='internal_shared_libs',
405                    help='Build internal libs as static libraries')
406     opt.add_option('--lv2', action='store_true', default=True, dest='lv2',
407                     help='Compile with support for LV2 (if Lilv+Suil is available)')
408     opt.add_option('--no-lv2', action='store_false', dest='lv2',
409                     help='Do not compile with support for LV2')
410     opt.add_option('--lxvst', action='store_true', default=lxvst_default, dest='lxvst',
411                     help='Compile with support for linuxVST plugins')
412     opt.add_option('--nls', action='store_true', default=True, dest='nls',
413                     help='Enable i18n (native language support) (default)')
414     opt.add_option('--no-nls', action='store_false', dest='nls')
415     opt.add_option('--phone-home', action='store_true', default=True, dest='phone_home',
416                    help='Contact ardour.org at startup for new announcements')
417     opt.add_option('--no-phone-home', action='store_false', dest='phone_home',
418                    help='Do not contact ardour.org at startup for new announcements')
419     opt.add_option('--stl-debug', action='store_true', default=False, dest='stl_debug',
420                     help='Build with debugging for the STL')
421     opt.add_option('--rt-alloc-debug', action='store_true', default=False, dest='rt_alloc_debug',
422                     help='Build with debugging for memory allocation in the real-time thread')
423     opt.add_option('--pt-timing', action='store_true', default=False, dest='pt_timing',
424                     help='Build with logging of timing in the process thread(s)')
425     opt.add_option('--denormal-exception', action='store_true', default=False, dest='denormal_exception',
426                     help='Raise a floating point exception if a denormal is detected')
427     opt.add_option('--test', action='store_true', default=False, dest='build_tests',
428                     help="Build unit tests")
429     #opt.add_option('--tranzport', action='store_true', default=False, dest='tranzport',
430     # help='Compile with support for Frontier Designs Tranzport (if libusb is available)')
431     opt.add_option('--universal', action='store_true', default=False, dest='universal',
432                     help='Compile as universal binary (OS X ONLY, requires that external libraries are universal)')
433     opt.add_option('--generic', action='store_true', default=False, dest='generic',
434                     help='Compile with -arch i386 (OS X ONLY)')
435     opt.add_option('--versioned', action='store_true', default=False, dest='versioned',
436                     help='Add revision information to executable name inside the build directory')
437     opt.add_option('--windows-vst', action='store_true', default=False, dest='windows_vst',
438                     help='Compile with support for Windows VST')
439     opt.add_option('--windows-key', type='string', action='store', dest='windows_key', default='Mod4><Super',
440                     help='X Modifier(s) (Mod1,Mod2, etc) for the Windows key (X11 builds only). ' +
441                     'Multiple modifiers must be separated by \'><\'')
442     opt.add_option('--boost-include', type='string', action='store', dest='boost_include', default='',
443                     help='directory where Boost header files can be found')
444     opt.add_option('--also-include', type='string', action='store', dest='also_include', default='',
445                     help='additional include directory where header files can be found (split multiples with commas)')
446     opt.add_option('--also-libdir', type='string', action='store', dest='also_libdir', default='',
447                     help='additional include directory where shared libraries can be found (split multiples with commas)')
448     opt.add_option('--wine-include', type='string', action='store', dest='wine_include', default='/usr/include/wine/windows',
449                     help='directory where Wine\'s Windows header files can be found')
450     opt.add_option('--noconfirm', action='store_true', default=False, dest='noconfirm',
451                     help='Do not ask questions that require confirmation during the build')
452     for i in children:
453         opt.recurse(i)
454
455 def sub_config_and_use(conf, name, has_objects = True):
456     conf.recurse(name)
457     autowaf.set_local_lib(conf, name, has_objects)
458
459 def configure(conf):
460     conf.load('compiler_c')
461     conf.load('compiler_cxx')
462     conf.env['VERSION'] = VERSION
463     conf.line_just = 52
464     autowaf.set_recursive()
465     autowaf.configure(conf)
466     autowaf.display_header('Ardour Configuration')
467
468     gcc_versions = fetch_gcc_version(str(conf.env['CC']))
469     if not Options.options.debug and gcc_versions[0] == '4' and gcc_versions[1] > '4':
470         print('Version 4.5 of gcc is not ready for use when compiling Ardour with optimization.')
471         print('Please use a different version or re-configure with --debug')
472         exit (1)
473
474     # systems with glibc have libintl builtin. systems without require explicit
475     # linkage against libintl.
476     #
477
478     pkg_config_path = os.getenv('PKG_CONFIG_PATH')
479     user_gtk_root = os.path.expanduser (Options.options.depstack_root + '/gtk/inst')
480
481     if pkg_config_path is not None and pkg_config_path.find (user_gtk_root) >= 0:
482         # told to search user_gtk_root
483         prefinclude = ''.join ([ '-I', user_gtk_root + '/include'])
484         preflib = ''.join ([ '-L', user_gtk_root + '/lib'])
485         conf.env.append_value('CFLAGS', [ prefinclude ])
486         conf.env.append_value('CXXFLAGS',  [prefinclude ])
487         conf.env.append_value('LINKFLAGS', [ preflib ])
488         autowaf.display_msg(conf, 'Will build against private GTK dependency stack in ' + user_gtk_root, 'yes')
489     else:
490         autowaf.display_msg(conf, 'Will build against private GTK dependency stack', 'no')
491
492     if sys.platform == 'darwin':
493         conf.define ('NEED_INTL', 1)
494         autowaf.display_msg(conf, 'Will use explicit linkage against libintl in ' + user_gtk_root, 'yes')
495     else:
496         # libintl is part of the system, so use it
497         autowaf.display_msg(conf, 'Will rely on libintl built into libc', 'yes')
498             
499     user_ardour_root = os.path.expanduser (Options.options.depstack_root + '/a3/inst')
500     if pkg_config_path is not None and pkg_config_path.find (user_ardour_root) >= 0:
501         # told to search user_ardour_root
502         prefinclude = ''.join ([ '-I', user_ardour_root + '/include'])
503         preflib = ''.join ([ '-L', user_ardour_root + '/lib'])
504         conf.env.append_value('CFLAGS', [ prefinclude ])
505         conf.env.append_value('CXXFLAGS',  [prefinclude ])
506         conf.env.append_value('LINKFLAGS', [ preflib ])
507         autowaf.display_msg(conf, 'Will build against private Ardour dependency stack in ' + user_ardour_root, 'yes')
508     else:
509         autowaf.display_msg(conf, 'Will build against private Ardour dependency stack', 'no')
510         
511     if sys.platform == 'darwin':
512
513         # this is required, potentially, for anything we link and then relocate into a bundle
514         conf.env.append_value('LINKFLAGS', [ '-Xlinker', '-headerpad_max_install_names' ])
515
516         conf.define ('HAVE_COREAUDIO', 1)
517         conf.define ('AUDIOUNIT_SUPPORT', 1)
518
519         if not Options.options.freebie:
520             conf.define ('AU_STATE_SUPPORT', 1)
521
522         conf.define ('GTKOSX', 1)
523         conf.define ('TOP_MENUBAR',1)
524         conf.define ('GTKOSX',1)
525
526         # It would be nice to be able to use this to force back-compatibility with 10.4
527         # but even by the time of 11, the 10.4 SDK is no longer available in any normal
528         # way.
529         #
530         #conf.env.append_value('CXXFLAGS_OSX', "-isysroot /Developer/SDKs/MacOSX10.4u.sdk")
531         #conf.env.append_value('CFLAGS_OSX', "-isysroot /Developer/SDKs/MacOSX10.4u.sdk")
532         #conf.env.append_value('LINKFLAGS_OSX', "-sysroot /Developer/SDKs/MacOSX10.4u.sdk")
533         #conf.env.append_value('LINKFLAGS_OSX', "-sysroot /Developer/SDKs/MacOSX10.4u.sdk")
534
535         conf.env.append_value('CXXFLAGS_OSX', "-msse")
536         conf.env.append_value('CFLAGS_OSX', "-msse")
537         conf.env.append_value('CXXFLAGS_OSX', "-msse2")
538         conf.env.append_value('CFLAGS_OSX', "-msse2")
539         #
540         #       TODO: The previous sse flags NEED to be based
541         #       off processor type.  Need to add in a check
542         #       for that.
543         #
544         conf.env.append_value('CXXFLAGS_OSX', '-F/System/Library/Frameworks')
545         conf.env.append_value('CXXFLAGS_OSX', '-F/Library/Frameworks')
546
547         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'AppKit'])
548         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreAudio'])
549         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreAudioKit'])
550         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreFoundation'])
551         conf.env.append_value('LINKFLAGS_OSX', ['-framework', 'CoreServices'])
552
553         conf.env.append_value('LINKFLAGS_OSX', ['-undefined', 'dynamic_lookup' ])
554         conf.env.append_value('LINKFLAGS_OSX', ['-flat_namespace'])
555
556         conf.env.append_value('CXXFLAGS_AUDIOUNITS', "-DAUDIOUNIT_SUPPORT")
557         conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'AudioToolbox', '-framework', 'AudioUnit'])
558         conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'Cocoa'])
559
560         if not Options.options.freebie:
561             conf.env.append_value('CXXFLAGS_AUDIOUNITS', "-DAU_STATE_SUPPORT")
562
563         if re.search ("^[1-9][0-9]\.", os.uname()[2]) == None and not Options.options.nocarbon:
564             conf.env.append_value('CXXFLAGS_AUDIOUNITS', "-DWITH_CARBON")
565             conf.env.append_value('LINKFLAGS_AUDIOUNITS', ['-framework', 'Carbon'])
566         else:
567             print ('No Carbon support available for this build\n')
568
569
570     if Options.options.internal_shared_libs: 
571         conf.define('INTERNAL_SHARED_LIBS', 1)
572
573     if Options.options.boost_include != '':
574         conf.env.append_value('CXXFLAGS', '-I' + Options.options.boost_include)
575
576     if Options.options.also_include != '':
577         conf.env.append_value('CXXFLAGS', '-I' + Options.options.also_include)
578         conf.env.append_value('CFLAGS', '-I' + Options.options.also_include)
579
580     if Options.options.also_libdir != '':
581         conf.env.append_value('LDFLAGS', '-L' + Options.options.also_libdir)
582
583     if Options.options.boost_sp_debug:
584         conf.env.append_value('CXXFLAGS', '-DBOOST_SP_ENABLE_DEBUG_HOOKS')
585
586     autowaf.check_header(conf, 'cxx', 'jack/session.h', define="JACK_SESSION", mandatory = False)
587
588     conf.check_cxx(fragment = "#include <boost/version.hpp>\nint main(void) { return (BOOST_VERSION >= 103900 ? 0 : 1); }\n",
589                   execute = "1",
590                   mandatory = True,
591                   msg = 'Checking for boost library >= 1.39',
592                   okmsg = 'ok',
593                   errmsg = 'too old\nPlease install boost version 1.39 or higher.')
594
595     autowaf.check_pkg(conf, 'glib-2.0', uselib_store='GLIB', atleast_version='2.2')
596     autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD', atleast_version='2.2')
597     autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.32.0')
598     autowaf.check_pkg(conf, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.18')
599     autowaf.check_pkg(conf, 'giomm-2.4', uselib_store='GIOMM', atleast_version='2.2')
600     autowaf.check_pkg(conf, 'libcurl', uselib_store='CURL', atleast_version='7.0.0')
601     autowaf.check_pkg(conf, 'liblo', uselib_store='LO', atleast_version='0.26')
602
603     conf.check_cc(function_name='dlopen', header_name='dlfcn.h', lib='dl', uselib_store='DL')
604
605     # Tell everyone that this is a waf build
606
607     conf.env.append_value('CFLAGS', '-DWAF_BUILD')
608     conf.env.append_value('CXXFLAGS', '-DWAF_BUILD')
609
610     # Set up waf environment and C defines
611     opts = Options.options
612     if opts.phone_home:
613         conf.define('PHONE_HOME', 1)
614         conf.env['PHONE_HOME'] = True
615     if opts.fpu_optimization:
616         conf.env['FPU_OPTIMIZATION'] = True
617     if opts.freesound:
618         conf.define('FREESOUND',1)
619         conf.env['FREESOUND'] = True
620     if opts.nls:
621         conf.define('ENABLE_NLS', 1)
622         conf.env['ENABLE_NLS'] = True
623     if opts.build_tests:
624         conf.env['BUILD_TESTS'] = opts.build_tests
625     #if opts.tranzport:
626     #    conf.env['TRANZPORT'] = 1
627     if opts.windows_vst:
628         conf.define('WINDOWS_VST_SUPPORT', 1)
629         conf.env['WINDOWS_VST_SUPPORT'] = True
630         conf.env.append_value('CFLAGS', '-I' + Options.options.wine_include)
631         conf.env.append_value('CXXFLAGS', '-I' + Options.options.wine_include)
632         autowaf.check_header(conf, 'cxx', 'windows.h', mandatory = True)
633     if opts.lxvst:
634         conf.define('LXVST_SUPPORT', 1)
635         conf.env['LXVST_SUPPORT'] = True
636     if bool(conf.env['JACK_SESSION']):
637         conf.define('HAVE_JACK_SESSION', 1)
638     conf.define('WINDOWS_KEY', opts.windows_key)
639     conf.env['PROGRAM_NAME'] = opts.program_name
640     if opts.rt_alloc_debug:
641         conf.define('DEBUG_RT_ALLOC', 1)
642         conf.env['DEBUG_RT_ALLOC'] = True
643     if opts.pt_timing:
644         conf.define('PT_TIMING', 1)
645         conf.env['PT_TIMING'] = True
646     if opts.denormal_exception:
647         conf.define('DEBUG_DENORMAL_EXCEPTION', 1)
648         conf.env['DEBUG_DENORMAL_EXCEPTION'] = True
649     if opts.build_tests:
650         autowaf.check_pkg(conf, 'cppunit', uselib_store='CPPUNIT', atleast_version='1.12.0', mandatory=True)
651
652     set_compiler_flags (conf, Options.options)
653
654     for i in children:
655         sub_config_and_use(conf, i)
656
657     # Fix utterly braindead FLAC include path to not smash assert.h
658     conf.env['INCLUDES_FLAC'] = []
659
660     config_text = open('libs/ardour/config_text.cc', "w")
661     config_text.write('''#include "ardour/ardour.h"
662 namespace ARDOUR {
663 const char* const ardour_config_info = "\\n\\
664 ''')
665
666     def write_config_text(title, val):
667         autowaf.display_msg(conf, title, val)
668         config_text.write(title + ': ')
669         config_text.write(str(val))
670         config_text.write("\\n\\\n")
671
672     write_config_text('Build documentation',   conf.env['DOCS'])
673     write_config_text('Debuggable build',      conf.env['DEBUG'])
674     write_config_text('Install prefix',        conf.env['PREFIX'])
675     write_config_text('Strict compiler flags', conf.env['STRICT'])
676     write_config_text('Internal Shared Libraries', conf.is_defined('INTERNAL_SHARED_LIBS'))
677
678     write_config_text('Architecture flags',    opts.arch)
679     write_config_text('Aubio',                 conf.is_defined('HAVE_AUBIO'))
680     write_config_text('AudioUnits',            conf.is_defined('AUDIOUNIT_SUPPORT'))
681     write_config_text('AU state support',      conf.is_defined('AU_STATE_SUPPORT'))
682     write_config_text('Build target',          conf.env['build_target'])
683     write_config_text('CoreAudio',             conf.is_defined('HAVE_COREAUDIO'))
684     write_config_text('Debug RT allocations',  conf.is_defined('DEBUG_RT_ALLOC'))
685     write_config_text('Process thread timing', conf.is_defined('PT_TIMING'))
686     write_config_text('Denormal exceptions',   conf.is_defined('DEBUG_DENORMAL_EXCEPTION'))
687     write_config_text('FLAC',                  conf.is_defined('HAVE_FLAC'))
688     write_config_text('FPU optimization',      opts.fpu_optimization)
689     write_config_text('Freedesktop files',     opts.freedesktop)
690     write_config_text('Freesound',             opts.freesound)
691     write_config_text('JACK session support',  conf.is_defined('JACK_SESSION'))
692     write_config_text('LV2 UI embedding',      conf.is_defined('HAVE_SUIL'))
693     write_config_text('LV2 support',           conf.is_defined('LV2_SUPPORT'))
694     write_config_text('LXVST support',         conf.is_defined('LXVST_SUPPORT'))
695     write_config_text('OGG',                   conf.is_defined('HAVE_OGG'))
696     write_config_text('Phone home',            conf.is_defined('PHONE_HOME'))
697     write_config_text('Program name',          opts.program_name)
698     write_config_text('Rubberband',            conf.is_defined('HAVE_RUBBERBAND'))
699     write_config_text('Samplerate',            conf.is_defined('HAVE_SAMPLERATE'))
700 #    write_config_text('Soundtouch',            conf.is_defined('HAVE_SOUNDTOUCH'))
701     write_config_text('Translation',           opts.nls)
702 #    write_config_text('Tranzport',             opts.tranzport)
703     write_config_text('Unit tests',            conf.env['BUILD_TESTS'])
704     write_config_text('Universal binary',      opts.universal)
705     write_config_text('Generic x86 CPU',       opts.generic)
706     write_config_text('Windows VST support',   opts.windows_vst)
707     write_config_text('Wiimote support',       conf.is_defined('BUILD_WIIMOTE'))
708     write_config_text('Windows key',           opts.windows_key)
709
710     write_config_text('C compiler flags',      conf.env['CFLAGS'])
711     write_config_text('C++ compiler flags',    conf.env['CXXFLAGS'])
712     write_config_text('Linker flags',           conf.env['LINKFLAGS'])
713
714     config_text.write ('";\n}\n')
715     config_text.close ()
716     print('')
717
718 def build(bld):
719     create_stored_revision()
720
721     # add directories that contain only headers, to workaround an issue with waf
722
723     bld.path.find_dir ('libs/evoral/evoral')
724     bld.path.find_dir ('libs/vamp-sdk/vamp-sdk')
725     bld.path.find_dir ('libs/surfaces/control_protocol/control_protocol')
726     bld.path.find_dir ('libs/timecode/timecode')
727     bld.path.find_dir ('libs/libltc/ltc')
728     bld.path.find_dir ('libs/rubberband/rubberband')
729     bld.path.find_dir ('libs/gtkmm2ext/gtkmm2ext')
730     bld.path.find_dir ('libs/ardour/ardour')
731     bld.path.find_dir ('libs/taglib/taglib')
732     bld.path.find_dir ('libs/pbd/pbd')
733
734     autowaf.set_recursive()
735
736     for i in children:
737         bld.recurse(i)
738
739     bld.install_files (os.path.join(bld.env['SYSCONFDIR'], 'ardour3', ), 'ardour_system.rc')
740
741 def i18n(bld):
742     bld.recurse (i18n_children)
743
744 def i18n_pot(bld):
745     bld.recurse (i18n_children)
746
747 def i18n_po(bld):
748     bld.recurse (i18n_children)
749
750 def i18n_mo(bld):
751     bld.recurse (i18n_children)
752
753 def tarball(bld):
754     create_stored_revision()