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