Bump libdcp for <Hash> in CPLs.
[dcpomatic.git] / wscript
1 import subprocess
2 import os
3 import sys
4
5 APPNAME = 'dcpomatic'
6 VERSION = '1.72.2devel'
7
8 def options(opt):
9     opt.load('compiler_cxx')
10     opt.load('winres')
11
12     opt.add_option('--enable-debug',      action='store_true', default=False, help='build with debugging information and without optimisation')
13     opt.add_option('--disable-gui',       action='store_true', default=False, help='disable building of GUI tools')
14     opt.add_option('--target-windows',    action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
15     opt.add_option('--target-debian',     action='store_true', default=False, help='set up to compile for a Debian/Ubuntu package')
16     opt.add_option('--debian-unstable',   action='store_true', default=False, help='add extra libraries to static-build correctly on Debian unstable')
17     opt.add_option('--target-centos-6',   action='store_true', default=False, help='set up to compile for a Centos 6.5 package')
18     opt.add_option('--target-centos-7',   action='store_true', default=False, help='set up to compile for a Centos 7 package')
19     opt.add_option('--magickpp-config',   action='store',      default='Magick++-config', help='path to Magick++-config')
20     opt.add_option('--wx-config',         action='store',      default='wx-config', help='path to wx-config')
21     opt.add_option('--address-sanitizer', action='store_true', default=False, help='build with address sanitizer')
22     opt.add_option('--install-prefix',                         default=None,  help='prefix of where DCP-o-matic will be installed')
23
24 def static_ffmpeg(conf):
25     conf.check_cfg(package='libavformat', args='--cflags', uselib_store='AVFORMAT', mandatory=True)
26     conf.env.STLIB_AVFORMAT = ['avformat']
27     conf.check_cfg(package='libavfilter', args='--cflags', uselib_store='AVFILTER', mandatory=True)
28     conf.env.STLIB_AVFILTER = ['avfilter', 'swresample']
29     conf.check_cfg(package='libavcodec', args='--cflags', uselib_store='AVCODEC', mandatory=True)
30     conf.env.STLIB_AVCODEC = ['avcodec']
31     conf.env.LIB_AVCODEC = ['z']
32     conf.check_cfg(package='libavutil', args='--cflags', uselib_store='AVUTIL', mandatory=True)
33     conf.env.STLIB_AVUTIL = ['avutil']
34     conf.check_cfg(package='libswscale', args='--cflags', uselib_store='SWSCALE', mandatory=True)
35     conf.env.STLIB_SWSCALE = ['swscale']
36     conf.check_cfg(package='libswresample', args='--cflags', uselib_store='SWRESAMPLE', mandatory=True)
37     conf.env.STLIB_SWRESAMPLE = ['swresample']
38     conf.check_cfg(package='libpostproc', args='--cflags', uselib_store='POSTPROC', mandatory=True)
39     conf.env.STLIB_POSTPROC = ['postproc']
40
41 def dynamic_ffmpeg(conf):
42     conf.check_cfg(package='libavformat', args='--cflags --libs', uselib_store='AVFORMAT', mandatory=True)
43     conf.check_cfg(package='libavfilter', args='--cflags --libs', uselib_store='AVFILTER', mandatory=True)
44     conf.check_cfg(package='libavcodec', args='--cflags --libs', uselib_store='AVCODEC', mandatory=True)
45     conf.check_cfg(package='libavutil', args='--cflags --libs', uselib_store='AVUTIL', mandatory=True)
46     conf.check_cfg(package='libswscale', args='--cflags --libs', uselib_store='SWSCALE', mandatory=True)
47     conf.check_cfg(package='libswresample', args='--cflags --libs', uselib_store='SWRESAMPLE', mandatory=True)
48     conf.check_cfg(package='libpostproc', args='--cflags --libs', uselib_store='POSTPROC', mandatory=True)
49
50 def static_openjpeg(conf):
51     conf.check_cfg(package='libopenjpeg', args='--cflags', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
52     conf.check_cfg(package='libopenjpeg', args='--cflags', max_version='1.5.2', mandatory=True)
53     conf.env.STLIB_OPENJPEG = ['openjpeg']
54
55 def dynamic_openjpeg(conf):
56     conf.check_cfg(package='libopenjpeg', args='--cflags --libs', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
57     conf.check_cfg(package='libopenjpeg', args='--cflags --libs', max_version='1.5.2', mandatory=True)
58
59 def static_dcp(conf, static_boost, static_xmlpp, static_xmlsec, static_ssh):
60     conf.check_cfg(package='libdcp', atleast_version='0.96', args='--cflags', uselib_store='DCP', mandatory=True)
61     conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
62     conf.env.STLIB_DCP = ['dcp', 'asdcp-libdcp', 'kumu-libdcp']
63     conf.env.LIB_DCP = ['glibmm-2.4', 'ssl', 'crypto', 'bz2', 'xslt']
64
65     if static_boost:
66         conf.env.STLIB_DCP.append('boost_system')
67
68     if static_xmlpp:
69         conf.env.STLIB_DCP.append('xml++-2.6')
70     else:
71         conf.env.LIB_DCP.append('xml++-2.6')
72
73     if static_xmlsec:
74         conf.env.STLIB_DCP.append('xmlsec1-openssl')
75         conf.env.STLIB_DCP.append('xmlsec1')
76     else:
77         conf.env.LIB_DCP.append('xmlsec1-openssl')
78         conf.env.LIB_DCP.append('xmlsec1')
79
80     if static_ssh:
81         conf.env.STLIB_DCP.append('ssh')
82     else:
83         conf.env.LIB_DCP.append('ssh')
84
85 def dynamic_dcp(conf):
86     conf.check_cfg(package='libdcp', atleast_version='0.95.0', args='--cflags --libs', uselib_store='DCP', mandatory=True)
87     conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
88
89 def dynamic_ssh(conf):
90     conf.check_cc(fragment="""
91                            #include <libssh/libssh.h>\n
92                            int main () {\n
93                            ssh_session s = ssh_new ();\n
94                            return 0;\n
95                            }
96                            """, msg='Checking for library libssh', mandatory=True, lib='ssh', uselib_store='SSH')
97
98 def dynamic_boost(conf, lib_suffix, thread):
99     conf.check_cxx(fragment="""
100                             #include <boost/version.hpp>\n
101                             #if BOOST_VERSION < 104500\n
102                             #error boost too old\n
103                             #endif\n
104                             int main(void) { return 0; }\n
105                             """,
106                    mandatory=True,
107                    msg='Checking for boost library >= 1.45',
108                    okmsg='yes',
109                    errmsg='too old\nPlease install boost version 1.45 or higher.')
110
111     conf.check_cxx(fragment="""
112                             #include <boost/thread.hpp>\n
113                             int main() { boost::thread t (); }\n
114                             """, msg='Checking for boost threading library',
115                             libpath='/usr/local/lib',
116                             lib=[thread, 'boost_system%s' % lib_suffix],
117                             uselib_store='BOOST_THREAD')
118
119     conf.check_cxx(fragment="""
120                             #include <boost/filesystem.hpp>\n
121                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
122                             """, msg='Checking for boost filesystem library',
123                             libpath='/usr/local/lib',
124                             lib=['boost_filesystem%s' % lib_suffix, 'boost_system%s' % lib_suffix],
125                             uselib_store='BOOST_FILESYSTEM')
126
127     conf.check_cxx(fragment="""
128                             #include <boost/date_time.hpp>\n
129                             int main() { boost::gregorian::day_clock::local_day(); }\n
130                             """, msg='Checking for boost datetime library',
131                             libpath='/usr/local/lib',
132                             lib=['boost_date_time%s' % lib_suffix, 'boost_system%s' % lib_suffix],
133                             uselib_store='BOOST_DATETIME')
134
135     conf.check_cxx(fragment="""
136                             #include <boost/signals2.hpp>\n
137                             int main() { boost::signals2::signal<void (int)> x; }\n
138                             """,
139                             msg='Checking for boost signals2 library',
140                             uselib_store='BOOST_SIGNALS2')
141
142 def static_boost(conf, lib_suffix):
143     conf.env.STLIB_BOOST_THREAD = ['boost_thread']
144     conf.env.STLIB_BOOST_FILESYSTEM = ['boost_filesystem%s' % lib_suffix]
145     conf.env.STLIB_BOOST_DATETIME = ['boost_date_time%s' % lib_suffix, 'boost_system%s' % lib_suffix]
146     conf.env.STLIB_BOOST_SIGNALS2 = ['boost_signals2']
147
148 def dynamic_quickmail(conf):
149     conf.check_cxx(fragment="""
150                             #include <quickmail.h>
151                             int main(void) { quickmail_initialize (); }
152                             """,
153                    mandatory=True,
154                    msg='Checking for libquickmail',
155                    libpath='/usr/local/lib',
156                    lib=['quickmail', 'curl'],
157                    uselib_store='QUICKMAIL')
158
159 def configure(conf):
160     conf.load('compiler_cxx')
161     if conf.options.target_windows:
162         conf.load('winres')
163
164     # conf.options -> conf.env
165     conf.env.TARGET_WINDOWS = conf.options.target_windows
166     conf.env.DISABLE_GUI = conf.options.disable_gui
167     conf.env.TARGET_DEBIAN = conf.options.target_debian
168     conf.env.DEBIAN_UNSTABLE = conf.options.debian_unstable
169     conf.env.TARGET_CENTOS_6 = conf.options.target_centos_6
170     conf.env.TARGET_CENTOS_7 = conf.options.target_centos_7
171     conf.env.VERSION = VERSION
172     conf.env.TARGET_OSX = sys.platform == 'darwin'
173     conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
174     # true if we should build dcpomatic/libdcpomatic/libdcpomatic-wx statically
175     conf.env.BUILD_STATIC = conf.options.target_debian or conf.options.target_centos_6 or conf.options.target_centos_7
176     if conf.options.install_prefix is None:
177         conf.env.INSTALL_PREFIX = conf.env.PREFIX
178     else:
179         conf.env.INSTALL_PREFIX = conf.options.install_prefix
180
181     # Common CXXFLAGS
182     conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS', '-D__STDC_LIMIT_MACROS', '-msse', '-ffast-math', '-fno-strict-aliasing',
183                                        '-Wall', '-Wno-attributes', '-Wextra', '-D_FILE_OFFSET_BITS=64'])
184
185     if conf.options.enable_debug:
186         conf.env.append_value('CXXFLAGS', ['-g', '-DDCPOMATIC_DEBUG'])
187     else:
188         conf.env.append_value('CXXFLAGS', '-O2')
189
190     if conf.options.address_sanitizer:
191         conf.env.append_value('CXXFLAGS', ['-fsanitize=address', '-fno-omit-frame-pointer'])
192         conf.env.append_value('LINKFLAGS', ['-fsanitize=address'])
193
194     #
195     # Platform-specific CFLAGS hacks and other tinkering
196     #
197
198     # Windows
199     if conf.env.TARGET_WINDOWS:
200         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_WINDOWS')
201         conf.env.append_value('CXXFLAGS', '-DWIN32_LEAN_AND_MEAN')
202         conf.env.append_value('CXXFLAGS', '-DBOOST_USE_WINDOWS_H')
203         conf.env.append_value('CXXFLAGS', '-DUNICODE')
204         conf.env.append_value('CXXFLAGS', '-DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN')
205         conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
206         wxrc = os.popen('wx-config --rescomp').read().split()[1:]
207         conf.env.append_value('WINRCFLAGS', wxrc)
208         if conf.options.enable_debug:
209             conf.env.append_value('CXXFLAGS', ['-mconsole'])
210             conf.env.append_value('LINKFLAGS', ['-mconsole'])
211         conf.check(lib='ws2_32', uselib_store='WINSOCK2', msg="Checking for library winsock2")
212         conf.check(lib='bfd', uselib_store='BFD', msg="Checking for library bfd")
213         conf.check(lib='dbghelp', uselib_store='DBGHELP', msg="Checking for library dbghelp")
214         conf.check(lib='iberty', uselib_store='IBERTY', msg="Checking for library iberty")
215         conf.check(lib='shlwapi', uselib_store='SHLWAPI', msg="Checking for library shlwapi")
216         conf.check(lib='mswsock', uselib_store='MSWSOCK', msg="Checking for library mswsock")
217         boost_lib_suffix = '-mt'
218         boost_thread = 'boost_thread_win32-mt'
219
220     # POSIX
221     if conf.env.TARGET_LINUX or conf.env.TARGET_OSX:
222         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_POSIX')
223         conf.env.append_value('CXXFLAGS', '-DPOSIX_LOCALE_PREFIX="%s/share/locale"' % conf.env['INSTALL_PREFIX'])
224         conf.env.append_value('CXXFLAGS', '-DPOSIX_ICON_PREFIX="%s/share/dcpomatic"' % conf.env['INSTALL_PREFIX'])
225         boost_lib_suffix = ''
226         boost_thread = 'boost_thread'
227         conf.env.append_value('LINKFLAGS', '-pthread')
228
229     # Linux
230     if conf.env.TARGET_LINUX:
231         conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
232         conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_LINUX')
233
234     if conf.env.TARGET_DEBIAN:
235         # libxml2 seems to be linked against this on Ubuntu but it doesn't mention it in its .pc file
236         conf.check_cfg(package='liblzma', args='--cflags --libs', uselib_store='LZMA', mandatory=True)
237         
238     if not conf.env.DISABLE_GUI and conf.env.TARGET_LINUX:
239         conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='GTK', mandatory=True)
240
241     # OSX
242     if conf.env.TARGET_OSX:
243         conf.env.append_value('CXXFLAGS', ['-DDCPOMATIC_OSX', '-Wno-unused-function', '-Wno-unused-parameter'])
244         conf.env.append_value('LINKFLAGS', '-headerpad_max_install_names')
245
246     #
247     # Dependencies.
248     # There's probably a neater way of expressing these, but I've gone for brute force for now.
249     #
250
251     if conf.env.TARGET_DEBIAN:
252         conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags', uselib_store='CXML', mandatory=True)
253         conf.env.STLIB_CXML = ['cxml']
254         conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
255         conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
256         conf.env.STLIB_QUICKMAIL = ['quickmail']
257         static_ffmpeg(conf)
258         static_openjpeg(conf)
259         static_dcp(conf, False, False, False, False)
260         dynamic_boost(conf, boost_lib_suffix, boost_thread)
261
262     if conf.env.TARGET_CENTOS_6:
263         # Centos 6.5's boost is too old, so we build a new version statically in the chroot
264         conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs-only-L', uselib_store='CXML', mandatory=True)
265         conf.env.STLIB_CXML = ['cxml', 'boost_filesystem']
266         conf.check_cfg(package='libcurl', args='--cflags --libs-only-L', uselib_store='CURL', mandatory=True)
267         conf.env.STLIB_CURL = ['curl']
268         conf.env.LIB_CURL = ['ssh2', 'idn']
269         conf.env.STLIB_QUICKMAIL = ['quickmail', 'curl']
270         conf.env.LIB_QUICKMAIL = ['ssh2', 'idn']
271         static_ffmpeg(conf)
272         static_openjpeg(conf)
273         static_dcp(conf, True, True, True, True)
274         static_boost(conf, boost_lib_suffix)
275
276     if conf.env.TARGET_CENTOS_7:
277         # Centos 7's boost is ok so we link it dynamically
278         conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags', uselib_store='CXML', mandatory=True)
279         conf.env.STLIB_CXML = ['cxml']
280         conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
281         conf.env.STLIB_QUICKMAIL = ['quickmail']
282         conf.env.LIB_SSH = ['gssapi_krb5']
283         conf.env.LIB_XMLPP = ['xml2']
284         conf.env.LIB_XMLSEC = ['ltdl']
285         static_ffmpeg(conf)
286         static_openjpeg(conf)
287         static_dcp(conf, False, True, True, True)
288         dynamic_boost(conf, boost_lib_suffix, boost_thread)
289
290     if conf.env.TARGET_WINDOWS:
291         conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
292         conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
293         conf.check_cxx(fragment="""
294                                 #include <boost/locale.hpp>\n
295                                 int main() { std::locale::global (boost::locale::generator().generate ("")); }\n
296                                 """, msg='Checking for boost locale library',
297                                 libpath='/usr/local/lib',
298                                 lib=['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
299                                 uselib_store='BOOST_LOCALE')
300         dynamic_quickmail(conf)
301         dynamic_boost(conf, boost_lib_suffix, boost_thread)
302         dynamic_ffmpeg(conf)
303         dynamic_openjpeg(conf)
304         dynamic_dcp(conf)
305         dynamic_ssh(conf)
306
307     # Not packaging; just a straight build
308     if not conf.env.TARGET_WINDOWS and not conf.env.TARGET_DEBIAN and not conf.env.TARGET_CENTOS_6 and not conf.env.TARGET_CENTOS_7:
309         conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs', uselib_store='CXML', mandatory=True)
310         conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
311         conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
312         dynamic_quickmail(conf)
313         dynamic_boost(conf, boost_lib_suffix, boost_thread)
314         dynamic_ffmpeg(conf)
315         dynamic_dcp(conf)
316         dynamic_openjpeg(conf)
317         dynamic_ssh(conf)
318
319     # Dependencies which are always dynamically linked
320     conf.check_cfg(package='sndfile', args='--cflags --libs', uselib_store='SNDFILE', mandatory=True)
321     conf.check_cfg(package='glib-2.0', args='--cflags --libs', uselib_store='GLIB', mandatory=True)
322     conf.check_cfg(package= '', path=conf.options.magickpp_config, args='--cppflags --cxxflags --libs', uselib_store='MAGICK', mandatory=True)
323     conf.check_cfg(package='libzip', args='--cflags --libs', uselib_store='ZIP', mandatory=True)
324
325     conf.check_cc(fragment="""
326                            #include <glib.h>
327                            int main() { g_format_size (1); }
328                            """, msg='Checking for g_format_size ()',
329                            uselib='GLIB',
330                            define_name='HAVE_G_FORMAT_SIZE',
331                            mandatory=False)
332
333     conf.find_program('msgfmt', var='MSGFMT')
334     
335     datadir = conf.env.DATADIR
336     if not datadir:
337         datadir = os.path.join(conf.env.PREFIX, 'share')
338     
339     conf.define('LOCALEDIR', os.path.join(datadir, 'locale'))
340     conf.define('DATADIR', datadir)
341
342     conf.recurse('src')
343     conf.recurse('test')
344
345 def build(bld):
346     create_version_cc(VERSION, bld.env.CXXFLAGS)
347
348     bld.recurse('src')
349     bld.recurse('test')
350     if bld.env.TARGET_WINDOWS:
351         bld.recurse('platform/windows')
352     if bld.env.TARGET_LINUX:
353         bld.recurse('platform/linux')
354     if bld.env.TARGET_OSX:
355         bld.recurse('platform/osx')
356
357     for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
358         bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dcpomatic.png' % r)
359
360     if not bld.env.TARGET_WINDOWS:
361         bld.install_files('${PREFIX}/share/dcpomatic', 'icons/taskbar_icon.png')
362
363     bld.add_post_fun(post)
364
365 def git_revision():
366     if not os.path.exists('.git'):
367         return None
368
369     cmd = "LANG= git log --abbrev HEAD^..HEAD ."
370     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
371     o = output[0].decode('utf-8')
372     return o.replace("commit ", "")[0:10]
373
374 def dist(ctx):
375     r = git_revision()
376     if r is not None:
377         f = open('.git_revision', 'w')
378         print >>f,r
379     f.close()
380
381     ctx.excl = """
382                TODO core *~ src/wx/*~ src/lib/*~ builds/*~ doc/manual/*~ src/tools/*~ *.pyc .waf* build .git
383                deps alignment hacks sync *.tar.bz2 *.exe .lock* *build-windows doc/manual/pdf doc/manual/html
384                GRSYMS GRTAGS GSYMS GTAGS
385                """
386
387
388 def create_version_cc(version, cxx_flags):
389     commit = git_revision()
390     if commit is None and os.path.exists('.git_revision'):
391         f = open('.git_revision', 'r')
392         commit = f.readline().strip()
393     
394     if commit is None:
395         commit = 'release'
396
397     try:
398         text =  '#include "version.h"\n'
399         text += 'char const * dcpomatic_git_commit = \"%s\";\n' % commit
400         text += 'char const * dcpomatic_version = \"%s\";\n' % version
401
402         t = ''
403         for f in cxx_flags:
404             f = f.replace('"', '\\"')
405             t += f + ' '
406         text += 'char const * dcpomatic_cxx_flags = \"%s\";\n' % t[:-1]
407
408         print('Writing version information to src/lib/version.cc')
409         o = open('src/lib/version.cc', 'w')
410         o.write(text)
411         o.close()
412     except IOError:
413         print('Could not open src/lib/version.cc for writing\n')
414         sys.exit(-1)
415     
416 def post(ctx):
417     if ctx.cmd == 'install':
418         ctx.exec_command('/sbin/ldconfig')
419
420 def pot(bld):
421     bld.recurse('src')
422
423 def pot_merge(bld):
424     bld.recurse('src')
425
426 def tags(bld):
427     os.system('etags src/lib/*.cc src/lib/*.h src/wx/*.cc src/wx/*.h src/tools/*.cc src/tools/*.h')