Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / wscript
1 #
2 #    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
3 #
4 #    This program is free software; you can redistribute it and/or modify
5 #    it under the terms of the GNU General Public License as published by
6 #    the Free Software Foundation; either version 2 of the License, or
7 #    (at your option) any later version.
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program; if not, write to the Free Software
16 #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #
18
19 import subprocess
20 import os
21 import shlex
22 import sys
23 import glob
24 import distutils
25 import distutils.spawn
26 from waflib import Logs, Context
27
28 APPNAME = 'dcpomatic'
29 VERSION = '2.8.4devel'
30
31 def options(opt):
32     opt.load('compiler_cxx')
33     opt.load('winres')
34
35     opt.add_option('--enable-debug',      action='store_true', default=False, help='build with debugging information and without optimisation')
36     opt.add_option('--disable-gui',       action='store_true', default=False, help='disable building of GUI tools')
37     opt.add_option('--disable-tests',     action='store_true', default=False, help='disable building of tests')
38     opt.add_option('--install-prefix',                         default=None,  help='prefix of where DCP-o-matic will be installed')
39     opt.add_option('--target-windows',    action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
40     opt.add_option('--static-dcpomatic',  action='store_true', default=False, help='link to components of DCP-o-matic statically')
41     opt.add_option('--static-boost',      action='store_true', default=False, help='link statically to Boost')
42     opt.add_option('--static-wxwidgets',  action='store_true', default=False, help='link statically to wxWidgets')
43     opt.add_option('--static-ffmpeg',     action='store_true', default=False, help='link statically to FFmpeg')
44     opt.add_option('--static-xmlpp',      action='store_true', default=False, help='link statically to libxml++')
45     opt.add_option('--static-xmlsec',     action='store_true', default=False, help='link statically to xmlsec')
46     opt.add_option('--static-ssh',        action='store_true', default=False, help='link statically to libssh')
47     opt.add_option('--static-cxml',       action='store_true', default=False, help='link statically to libcxml')
48     opt.add_option('--static-dcp',        action='store_true', default=False, help='link statically to libdcp')
49     opt.add_option('--static-sub',        action='store_true', default=False, help='link statically to libsub')
50     opt.add_option('--static-curl',       action='store_true', default=False, help='link statically to libcurl')
51     opt.add_option('--workaround-gssapi', action='store_true', default=False, help='link to gssapi_krb5')
52
53 def configure(conf):
54     conf.load('compiler_cxx')
55     if conf.options.target_windows:
56         conf.load('winres')
57
58     # Save conf.options that we need elsewhere in conf.env
59     conf.env.DISABLE_GUI = conf.options.disable_gui
60     conf.env.DISABLE_TESTS = conf.options.disable_tests
61     conf.env.TARGET_WINDOWS = conf.options.target_windows
62     conf.env.TARGET_OSX = sys.platform == 'darwin'
63     conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
64     conf.env.VERSION = VERSION
65     conf.env.DEBUG = conf.options.enable_debug
66     conf.env.STATIC_DCPOMATIC = conf.options.static_dcpomatic
67     if conf.options.install_prefix is None:
68         conf.env.INSTALL_PREFIX = conf.env.PREFIX
69     else:
70         conf.env.INSTALL_PREFIX = conf.options.install_prefix
71
72     # Common CXXFLAGS
73     conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS',
74                                        '-D__STDC_LIMIT_MACROS',
75                                        '-D__STDC_FORMAT_MACROS',
76                                        '-msse',
77                                        '-fno-strict-aliasing',
78                                        '-Wall',
79                                        '-Wno-attributes',
80                                        '-Wextra',
81                                        # Remove auto_ptr warnings from libxml++-2.6
82                                        '-Wno-deprecated-declarations',
83                                        '-D_FILE_OFFSET_BITS=64'])
84
85     gcc = conf.env['CC_VERSION']
86     if int(gcc[0]) >= 4 and int(gcc[1]) > 1:
87         conf.env.append_value('CXXFLAGS', ['-Wno-unused-result'])
88
89     if conf.options.enable_debug:
90         conf.env.append_value('CXXFLAGS', ['-g', '-DDCPOMATIC_DEBUG', '-fno-omit-frame-pointer'])
91     else:
92         conf.env.append_value('CXXFLAGS', '-O2')
93
94     #
95     # Windows/Linux/OS X specific
96     #
97
98     # Windows
99     if conf.env.TARGET_WINDOWS:
100         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_WINDOWS')
101         conf.env.append_value('CXXFLAGS', '-DWIN32_LEAN_AND_MEAN')
102         conf.env.append_value('CXXFLAGS', '-DBOOST_USE_WINDOWS_H')
103         conf.env.append_value('CXXFLAGS', '-DUNICODE')
104         conf.env.append_value('CXXFLAGS', '-DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN')
105         conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
106         wxrc = os.popen('wx-config --rescomp').read().split()[1:]
107         conf.env.append_value('WINRCFLAGS', wxrc)
108         if conf.options.enable_debug:
109             conf.env.append_value('CXXFLAGS', ['-mconsole'])
110             conf.env.append_value('LINKFLAGS', ['-mconsole'])
111         conf.check(lib='ws2_32', uselib_store='WINSOCK2', msg="Checking for library winsock2")
112         conf.check(lib='bfd', uselib_store='BFD', msg="Checking for library bfd")
113         conf.check(lib='dbghelp', uselib_store='DBGHELP', msg="Checking for library dbghelp")
114         conf.check(lib='iberty', uselib_store='IBERTY', msg="Checking for library iberty")
115         conf.check(lib='shlwapi', uselib_store='SHLWAPI', msg="Checking for library shlwapi")
116         conf.check(lib='mswsock', uselib_store='MSWSOCK', msg="Checking for library mswsock")
117         boost_lib_suffix = '-mt'
118         boost_thread = 'boost_thread-mt'
119         conf.check_cxx(fragment="""
120                                #include <boost/locale.hpp>\n
121                                int main() { std::locale::global (boost::locale::generator().generate ("")); }\n
122                                """,
123                                msg='Checking for boost locale library',
124                                libpath='/usr/local/lib',
125                                lib=['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
126                                uselib_store='BOOST_LOCALE')
127
128     # POSIX
129     if conf.env.TARGET_LINUX or conf.env.TARGET_OSX:
130         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_POSIX')
131         boost_lib_suffix = ''
132         boost_thread = 'boost_thread'
133         conf.env.append_value('LINKFLAGS', '-pthread')
134
135     # Linux
136     if conf.env.TARGET_LINUX:
137         conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
138         conf.env.append_value('CXXFLAGS', '-DLINUX_LOCALE_PREFIX="%s/share/locale"' % conf.env['INSTALL_PREFIX'])
139         conf.env.append_value('CXXFLAGS', '-DLINUX_SHARE_PREFIX="%s/share/dcpomatic2"' % conf.env['INSTALL_PREFIX'])
140         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_LINUX')
141         if not conf.env.DISABLE_GUI:
142             conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='GTK', mandatory=True)
143
144     # OSX
145     if conf.env.TARGET_OSX:
146         conf.env.append_value('CXXFLAGS', ['-DDCPOMATIC_OSX', '-Wno-unused-function', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
147         conf.env.append_value('LINKFLAGS', '-headerpad_max_install_names')
148
149     #
150     # Dependencies.
151     #
152
153     # It should be possible to use check_cfg for both dynamic and static linking, but
154     # e.g. pkg-config --libs --static foo returns some libraries that should be statically
155     # linked and others that should be dynamic.  This doesn't work too well with waf
156     # as it wants them separate.
157
158     # libcurl
159     if conf.options.static_curl:
160         conf.env.STLIB_CURL = ['curl']
161         conf.env.LIB_CURL = ['ssh2', 'idn']
162     else:
163         conf.check_cfg(package='libcurl', args='--cflags --libs', atleast_version='7.19.1', uselib_store='CURL', mandatory=True)
164
165     # libicu
166     if conf.check_cfg(package='icu-i18n', args='--cflags --libs', uselib_store='ICU', mandatory=False) is None:
167         if conf.check_cfg(package='icu', args='--cflags --libs', uselib_store='ICU', mandatory=False) is None:
168             conf.check_cxx(fragment="""
169                             #include <unicode/ucsdet.h>
170                             int main(void) {
171                                 UErrorCode status = U_ZERO_ERROR;
172                                 UCharsetDetector* detector = ucsdet_open (&status);
173                                 return 0; }\n
174                             """,
175                        mandatory=True,
176                        msg='Checking for libicu',
177                        okmsg='yes',
178                        libpath=['/usr/local/lib', '/usr/lib', '/usr/lib/x86_64-linux-gnu'],
179                        lib=['icuio', 'icui18n', 'icudata', 'icuuc'],
180                        uselib_store='ICU')
181
182     # libsamplerate
183     conf.check_cfg(package='samplerate', args='--cflags --libs', uselib_store='SAMPLERATE', mandatory=True)
184
185     # glib
186     conf.check_cfg(package='glib-2.0', args='--cflags --libs', uselib_store='GLIB', mandatory=True)
187
188     # ImageMagick / GraphicsMagick
189     if distutils.spawn.find_executable('Magick++-config'):
190         conf.check_cfg(package='', path='Magick++-config', args='--cppflags --cxxflags --libs', uselib_store='MAGICK', mandatory=True)
191         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_IMAGE_MAGICK')
192     else:
193         image = conf.check_cfg(package='ImageMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
194         graphics = conf.check_cfg(package='GraphicsMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
195         if image is None and graphics is None:
196             Logs.pprint('RED', 'Neither ImageMagick++ nor GraphicsMagick++ found: one or the other is required')
197         if image is not None:
198             conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_IMAGE_MAGICK')
199         if graphics is not None:
200             conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_GRAPHICS_MAGICK')
201
202     # See if we are using the MagickCore or MagickLib namespaces
203     conf.check_cxx(fragment="""
204                             #include <Magick++.h>
205                             using namespace MagickCore;
206                             """,
207                    mandatory=False,
208                    msg='Checking for MagickCore namespace',
209                    okmsg='yes',
210                    define_name='DCPOMATIC_HAVE_MAGICKCORE_NAMESPACE')
211
212     conf.check_cxx(fragment="""
213                             #include <Magick++.h>
214                             using namespace MagickLib
215                             """,
216                    mandatory=False,
217                    msg='Checking for MagickLib namespace',
218                    okmsg='yes',
219                    define_name='DCPOMATIC_HAVE_MAGICKLIB_NAMESPACE')
220
221     # libzip
222     conf.check_cfg(package='libzip', args='--cflags --libs', uselib_store='ZIP', mandatory=True)
223
224     # fontconfig
225     conf.check_cfg(package='fontconfig', args='--cflags --libs', uselib_store='FONTCONFIG', mandatory=True)
226
227     # pangomm
228     conf.check_cfg(package='pangomm-1.4', args='--cflags --libs', uselib_store='PANGOMM', mandatory=True)
229
230     # cairomm
231     conf.check_cfg(package='cairomm-1.0', args='--cflags --libs', uselib_store='CAIROMM', mandatory=True)
232
233     # libcxml
234     if conf.options.static_cxml:
235         conf.check_cfg(package='libcxml', atleast_version='0.15.1', args='--cflags', uselib_store='CXML', mandatory=True)
236         conf.env.STLIB_CXML = ['cxml']
237     else:
238         conf.check_cfg(package='libcxml', atleast_version='0.15.1', args='--cflags --libs', uselib_store='CXML', mandatory=True)
239
240     # libssh
241     if conf.options.static_ssh:
242         conf.env.STLIB_SSH = ['ssh']
243         if conf.options.workaround_gssapi:
244             conf.env.LIB_SSH = ['gssapi_krb5']
245     else:
246         conf.check_cc(fragment="""
247                                #include <libssh/libssh.h>\n
248                                int main () {\n
249                                ssh_session s = ssh_new ();\n
250                                return 0;\n
251                                }
252                                """,
253                       msg='Checking for library libssh',
254                       mandatory=True,
255                       lib='ssh',
256                       uselib_store='SSH')
257
258     # libdcp
259     if conf.options.static_dcp:
260         conf.check_cfg(package='libdcp-1.0', atleast_version='1.3.3', args='--cflags', uselib_store='DCP', mandatory=True)
261         conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
262         conf.env.STLIB_DCP = ['dcp-1.0', 'asdcp-cth', 'kumu-cth', 'openjp2']
263         conf.env.LIB_DCP = ['glibmm-2.4', 'ssl', 'crypto', 'bz2', 'xslt']
264     else:
265         conf.check_cfg(package='libdcp-1.0', atleast_version='1.3.3', args='--cflags --libs', uselib_store='DCP', mandatory=True)
266         conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
267
268     # libsub
269     if conf.options.static_sub:
270         conf.check_cfg(package='libsub-1.0', atleast_version='1.1.12', args='--cflags', uselib_store='SUB', mandatory=True)
271         conf.env.DEFINES_SUB = [f.replace('\\', '') for f in conf.env.DEFINES_SUB]
272         conf.env.STLIB_SUB = ['sub-1.0']
273     else:
274         conf.check_cfg(package='libsub-1.0', atleast_version='1.1.12', args='--cflags --libs', uselib_store='SUB', mandatory=True)
275         conf.env.DEFINES_SUB = [f.replace('\\', '') for f in conf.env.DEFINES_SUB]
276
277     # libxml++
278     if conf.options.static_xmlpp:
279         conf.env.STLIB_XMLPP = ['xml++-2.6']
280         conf.env.LIB_XMLPP = ['xml2']
281     else:
282         conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
283
284     # libxmlsec
285     if conf.options.static_xmlsec:
286         conf.env.STLIB_XMLSEC = ['xmlsec1-openssl', 'xmlsec1']
287     else:
288         conf.env.LIB_XMLSEC = ['xmlsec1-openssl', 'xmlsec1']
289
290     # FFmpeg
291     if conf.options.static_ffmpeg:
292         names = ['avformat', 'avfilter', 'avcodec', 'avutil', 'swscale', 'postproc']
293         for name in names:
294             static = subprocess.Popen(shlex.split('pkg-config --static --libs lib%s' % name), stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
295             libs = []
296             stlibs = []
297             include = []
298             libpath = []
299             for s in static.split():
300                 if s.startswith('-L'):
301                     libpath.append(s[2:])
302                 elif s.startswith('-I'):
303                     include.append(s[2:])
304                 elif s.startswith('-l'):
305                     if s[2:] not in names:
306                         libs.append(s[2:])
307                     else:
308                         stlibs.append(s[2:])
309
310             conf.env['LIB_%s' % name.upper()] = libs
311             conf.env['STLIB_%s' % name.upper()] = stlibs
312             conf.env['INCLUDES_%s' % name.upper()] = include
313             conf.env['LIBPATH_%s' % name.upper()] = libpath
314     else:
315         conf.check_cfg(package='libavformat', args='--cflags --libs', uselib_store='AVFORMAT', mandatory=True)
316         conf.check_cfg(package='libavfilter', args='--cflags --libs', uselib_store='AVFILTER', mandatory=True)
317         conf.check_cfg(package='libavcodec', args='--cflags --libs', uselib_store='AVCODEC', mandatory=True)
318         conf.check_cfg(package='libavutil', args='--cflags --libs', uselib_store='AVUTIL', mandatory=True)
319         conf.check_cfg(package='libswscale', args='--cflags --libs', uselib_store='SWSCALE', mandatory=True)
320         conf.check_cfg(package='libpostproc', args='--cflags --libs', uselib_store='POSTPROC', mandatory=True)
321
322     # Check to see if we have our version of FFmpeg that allows us to get at EBUR128 results
323     conf.check_cxx(fragment="""
324                             extern "C" {\n
325                             #include <libavfilter/f_ebur128.h>\n
326                             }\n
327                             int main () { av_ebur128_get_true_peaks (0); }\n
328                             """,
329                    msg='Checking for EBUR128-patched FFmpeg',
330                    libpath=conf.env['LIBPATH_AVFORMAT'],
331                    lib='avfilter avutil swresample',
332                    includes=conf.env['INCLUDES_AVFORMAT'],
333                    define_name='DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG',
334                    mandatory=False)
335
336     # Check to see if we have our AVSubtitleRect has a pict member
337     # Older versions (e.g. that shipped with Ubuntu 16.04) do
338     conf.check_cxx(fragment="""
339                             extern "C" {\n
340                             #include <libavcodec/avcodec.h>\n
341                             }\n
342                             int main () { AVSubtitleRect r; r.pict; }\n
343                             """,
344                    msg='Checking for AVSubtitleRect::pict',
345                    cxxflags='-Wno-unused-result -Wno-unused-value -Wdeprecated-declarations -Werror',
346                    libpath=conf.env['LIBPATH_AVCODEC'],
347                    lib='avcodec',
348                    includes=conf.env['INCLUDES_AVCODEC'],
349                    define_name='DCPOMATIC_HAVE_AVSUBTITLERECT_PICT',
350                    mandatory=False)
351
352     # Check to see if we have our AVComponentDescriptor has a depth_minus1 member
353     # Older versions (e.g. that shipped with Ubuntu 16.04) do
354     conf.check_cxx(fragment="""
355                             extern "C" {\n
356                             #include <libavutil/pixdesc.h>\n
357                             }\n
358                             int main () { AVComponentDescriptor d; d.depth_minus1; }\n
359                             """,
360                    msg='Checking for AVComponentDescriptor::depth_minus1',
361                    cxxflags='-Wno-unused-result -Wno-unused-value -Wdeprecated-declarations -Werror',
362                    libpath=conf.env['LIBPATH_AVUTIL'],
363                    lib='avutil',
364                    includes=conf.env['INCLUDES_AVUTIL'],
365                    define_name='DCPOMATIC_HAVE_AVCOMPONENTDESCRIPTOR_DEPTH_MINUS1',
366                    mandatory=False)
367
368     # Hack: the previous two check_cxx calls end up copying their (necessary) cxxflags
369     # to these variables.  We don't want to use these for the actual build, so clearn them out.
370     conf.env['CXXFLAGS_AVCODEC'] = []
371     conf.env['CXXFLAGS_AVUTIL'] = []
372
373     # Boost
374     if conf.options.static_boost:
375         conf.env.STLIB_BOOST_THREAD = ['boost_thread']
376         conf.env.STLIB_BOOST_FILESYSTEM = ['boost_filesystem%s' % boost_lib_suffix]
377         conf.env.STLIB_BOOST_DATETIME = ['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix]
378         conf.env.STLIB_BOOST_SIGNALS2 = ['boost_signals2']
379         conf.env.STLIB_BOOST_SYSTEM = ['boost_system']
380         conf.env.STLIB_BOOST_REGEX = ['boost_regex']
381     else:
382         conf.check_cxx(fragment="""
383                             #include <boost/version.hpp>\n
384                             #if BOOST_VERSION < 104500\n
385                             #error boost too old\n
386                             #endif\n
387                             int main(void) { return 0; }\n
388                             """,
389                        mandatory=True,
390                        msg='Checking for boost library >= 1.45',
391                        okmsg='yes',
392                        errmsg='too old\nPlease install boost version 1.45 or higher.')
393
394         conf.check_cxx(fragment="""
395                             #include <boost/thread.hpp>\n
396                             int main() { boost::thread t (); }\n
397                             """,
398                        msg='Checking for boost threading library',
399                        libpath='/usr/local/lib',
400                        lib=[boost_thread, 'boost_system%s' % boost_lib_suffix],
401                        uselib_store='BOOST_THREAD')
402
403         conf.check_cxx(fragment="""
404                             #include <boost/filesystem.hpp>\n
405                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
406                             """,
407                        msg='Checking for boost filesystem library',
408                        libpath='/usr/local/lib',
409                        lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
410                        uselib_store='BOOST_FILESYSTEM')
411
412         conf.check_cxx(fragment="""
413                             #include <boost/date_time.hpp>\n
414                             int main() { boost::gregorian::day_clock::local_day(); }\n
415                             """,
416                        msg='Checking for boost datetime library',
417                        libpath='/usr/local/lib',
418                        lib=['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
419                        uselib_store='BOOST_DATETIME')
420
421         conf.check_cxx(fragment="""
422                             #include <boost/signals2.hpp>\n
423                             int main() { boost::signals2::signal<void (int)> x; }\n
424                             """,
425                        msg='Checking for boost signals2 library',
426                        uselib_store='BOOST_SIGNALS2')
427
428         conf.check_cxx(fragment="""
429                             #include <boost/regex.hpp>\n
430                             int main() { boost::regex re ("foo"); }\n
431                             """,
432                        msg='Checking for boost regex library',
433                        lib=['boost_regex%s' % boost_lib_suffix],
434                        uselib_store='BOOST_REGEX')
435
436     # libxml++ requires glibmm and versions of glibmm 2.45.31 and later
437     # must be built with -std=c++11 as they use c++11
438     # features and c++11 is not (yet) the default in gcc.
439     glibmm_version = conf.cmd_and_log(['pkg-config', '--modversion', 'glibmm-2.4'], output=Context.STDOUT, quiet=Context.BOTH)
440     s = glibmm_version.split('.')
441     v = (int(s[0]) << 16) | (int(s[1]) << 8) | int(s[2])
442     if v >= 0x022D1F:
443         conf.env.append_value('CXXFLAGS', '-std=c++11')
444
445     # Other stuff
446
447     conf.find_program('msgfmt', var='MSGFMT')
448
449     datadir = conf.env.DATADIR
450     if not datadir:
451         datadir = os.path.join(conf.env.PREFIX, 'share')
452
453     conf.define('LOCALEDIR', os.path.join(datadir, 'locale'))
454     conf.define('DATADIR', datadir)
455
456     conf.recurse('src')
457     if not conf.env.DISABLE_TESTS:
458         conf.recurse('test')
459
460     Logs.pprint('YELLOW', '')
461     if conf.env.TARGET_WINDOWS:
462         Logs.pprint('YELLOW', '\t' + 'Target'.ljust(25) + ': Windows')
463     elif conf.env.TARGET_LINUX:
464         Logs.pprint('YELLOW', '\t' + 'Target'.ljust(25) + ': Linux')
465     elif conf.env.TARGET_OSX:
466         Logs.pprint('YELLOW', '\t' + 'Target'.ljust(25) + ': OS X')
467
468     def report(name, variable):
469         linkage = ''
470         if variable:
471             linkage = 'static'
472         else:
473             linkage = 'dynamic'
474         Logs.pprint('YELLOW', '\t%s: %s' % (name.ljust(25), linkage))
475
476     report('DCP-o-matic libraries', conf.options.static_dcpomatic)
477     report('Boost', conf.options.static_boost)
478     report('wxWidgets', conf.options.static_wxwidgets)
479     report('FFmpeg', conf.options.static_ffmpeg)
480     report('libxml++', conf.options.static_xmlpp)
481     report('xmlsec', conf.options.static_xmlsec)
482     report('libssh', conf.options.static_ssh)
483     report('libcxml', conf.options.static_cxml)
484     report('libdcp', conf.options.static_dcp)
485     report('libcurl', conf.options.static_curl)
486
487     Logs.pprint('YELLOW', '')
488
489 def build(bld):
490     create_version_cc(VERSION, bld.env.CXXFLAGS)
491
492     bld.recurse('src')
493     bld.recurse('graphics')
494
495     if not bld.env.DISABLE_TESTS:
496         bld.recurse('test')
497     if bld.env.TARGET_WINDOWS:
498         bld.recurse('platform/windows')
499     if bld.env.TARGET_LINUX:
500         bld.recurse('platform/linux')
501     if bld.env.TARGET_OSX:
502         bld.recurse('platform/osx')
503
504     if not bld.env.TARGET_WINDOWS:
505         bld.install_files('${PREFIX}/share/dcpomatic2', 'fonts/LiberationSans-Regular.ttf')
506         bld.install_files('${PREFIX}/share/dcpomatic2', 'fonts/LiberationSans-Italic.ttf')
507         bld.install_files('${PREFIX}/share/dcpomatic2', 'fonts/LiberationSans-Bold.ttf')
508
509     bld.add_post_fun(post)
510
511 def git_revision():
512     if not os.path.exists('.git'):
513         return None
514
515     cmd = "LANG= git log --abbrev HEAD^..HEAD ."
516     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
517     o = output[0].decode('utf-8')
518     return o.replace("commit ", "")[0:10]
519
520 def dist(ctx):
521     r = git_revision()
522     if r is not None:
523         f = open('.git_revision', 'w')
524         print >>f,r
525     f.close()
526
527     ctx.excl = """
528                TODO core *~ src/wx/*~ src/lib/*~ builds/*~ doc/manual/*~ src/tools/*~ *.pyc .waf* build .git
529                deps alignment hacks sync *.tar.bz2 *.exe .lock* *build-windows doc/manual/pdf doc/manual/html
530                GRSYMS GRTAGS GSYMS GTAGS
531                """
532
533 def create_version_cc(version, cxx_flags):
534     commit = git_revision()
535     if commit is None and os.path.exists('.git_revision'):
536         f = open('.git_revision', 'r')
537         commit = f.readline().strip()
538
539     if commit is None:
540         commit = 'release'
541
542     try:
543         text =  '#include "version.h"\n'
544         text += 'char const * dcpomatic_git_commit = \"%s\";\n' % commit
545         text += 'char const * dcpomatic_version = \"%s\";\n' % version
546
547         t = ''
548         for f in cxx_flags:
549             f = f.replace('"', '\\"')
550             t += f + ' '
551         text += 'char const * dcpomatic_cxx_flags = \"%s\";\n' % t[:-1]
552
553         print('Writing version information to src/lib/version.cc')
554         o = open('src/lib/version.cc', 'w')
555         o.write(text)
556         o.close()
557     except IOError:
558         print('Could not open src/lib/version.cc for writing\n')
559         sys.exit(-1)
560
561 def post(ctx):
562     if ctx.cmd == 'install':
563         ctx.exec_command('/sbin/ldconfig')
564
565 def pot(bld):
566     bld.recurse('src')
567
568 def pot_merge(bld):
569     bld.recurse('src')
570
571 def tags(bld):
572     os.system('etags src/lib/*.cc src/lib/*.h src/wx/*.cc src/wx/*.h src/tools/*.cc')
573
574 def cppcheck(bld):
575     os.system('cppcheck --enable=all --quiet .')