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