Bump libdcp for various fixes to Interop subtitle time parsing.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 #
5 #    This file is part of DCP-o-matic.
6 #
7 #    DCP-o-matic is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    DCP-o-matic is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from __future__ import print_function
22 import glob
23 import shutil
24 import os
25 import copy
26
27 deb_build_depends = {'debhelper', 'python', 'g++', 'pkg-config', 'libssh-dev', 'libsndfile1-dev', 'libgtk2.0-dev'}
28
29 deb_depends = dict()
30
31 deb_depends_base = ['libc6', 'libssh-4', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libcurl3', 'libgtk2.0-0']
32
33 deb_depends['12.04'] = copy.deepcopy(deb_depends_base)
34 deb_depends['12.04'].extend(['libboost-filesystem1.48.0',
35                              'libboost-thread1.48.0',
36                              'libboost-regex1.48.0',
37                              'libmagick++4',
38                              'libxml++2.6-2',
39                              'libboost-date-time1.48.0',
40                              'libzip2',
41                              'libicu48'])
42
43 deb_depends['14.04'] = copy.deepcopy(deb_depends_base)
44 deb_depends['14.04'].extend(['libboost-filesystem1.54.0',
45                              'libboost-thread1.54.0',
46                              'libboost-regex1.54.0',
47                              'libmagick++5',
48                              'libxml++2.6-2',
49                              'libboost-date-time1.54.0',
50                              'libzip2',
51                              'libcairomm-1.0-1',
52                              'libpangomm-1.4-1',
53                              'libicu52'])
54
55 deb_depends['15.10'] = copy.deepcopy(deb_depends_base)
56 deb_depends['15.10'].extend(['libboost-filesystem1.58.0',
57                              'libboost-thread1.58.0',
58                              'libboost-regex1.58.0',
59                              'libmagick++-6.q16-5v5',
60                              'libxml++2.6-2v5',
61                              'libboost-date-time1.58.0',
62                              'libzip4',
63                              'libwxgtk3.0-0v5',
64                              'libicu55'])
65
66 deb_depends['16.04'] = copy.deepcopy(deb_depends_base)
67 deb_depends['16.04'].extend(['libboost-filesystem1.58.0',
68                              'libboost-thread1.58.0',
69                              'libboost-regex1.58.0',
70                              'libmagick++-6.q16-5v5',
71                              'libxml++2.6-2v5',
72                              'libboost-date-time1.58.0',
73                              'libzip4',
74                              'libwxgtk3.0-0v5',
75                              'libicu55'])
76
77 deb_depends['7'] = copy.deepcopy(deb_depends_base)
78 deb_depends['7'].extend(['libboost-filesystem1.49.0',
79                              'libboost-thread1.49.0',
80                              'libboost-regex1.49.0',
81                              'libmagick++5',
82                              'libxml++2.6-2',
83                              'libboost-date-time1.49.0',
84                              'libzip2',
85                              'libcairomm-1.0-1',
86                              'libpangomm-1.4-1',
87                              'libicu48'])
88
89 deb_depends['8'] = copy.deepcopy(deb_depends_base)
90 deb_depends['8'].extend(['libboost-filesystem1.55.0',
91                          'libboost-thread1.55.0',
92                          'libboost-date-time1.55.0',
93                          'libboost-regex1.55.0',
94                          'libmagick++-6.q16-5',
95                          'libxml++2.6-2',
96                          'libzip2',
97                          'libwxgtk3.0-0',
98                          'libxcb-xfixes0',
99                          'libxcb-shape0',
100                          'libicu52'])
101
102 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
103 deb_depends['unstable'].extend(['libboost-filesystem1.58.0',
104                                 'libboost-thread1.58.0',
105                                 'libboost-regex1.58.0',
106                                 'libmagick++-6.q16-5v5',
107                                 'libxml++2.6-2v5',
108                                 'libgtk2.0-0',
109                                 'libboost-date-time1.58.0',
110                                 'libzip2',
111                                 'libicu52'])
112
113 def packages(name, packages, f):
114     s = '%s: ' % name
115     for p in packages:
116         s += str(p) + ', '
117     print(s[:-2], file=f)
118
119 def make_control(debian_version, bits, filename, debug):
120     f = open(filename, 'w')
121     print('Source: dcpomatic', file=f)
122     print('Section: video', file=f)
123     print('Priority: extra', file=f)
124     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
125     packages('Build-Depends', deb_build_depends, f)
126     print('Standards-Version: 3.9.3', file=f)
127     print('Homepage: http://dcpomatic.com/', file=f)
128     print('', file=f)
129     print('Package: dcpomatic', file=f)
130     if bits == 32:
131         print('Architecture: i386', file=f)
132     else:
133         print('Architecture: amd64', file=f)
134
135     packages('Depends', deb_depends[debian_version], f)
136
137     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
138     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio', file=f)
139     print('  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant', file=f)
140     print('  digital projectors.', file=f)
141
142     if debug:
143         print('', file=f)
144         print('Package: dcpomatic-dbg', file=f)
145         if bits == 32:
146             print('Architecture: i386', file=f)
147         else:
148             print('Architecture: amd64', file=f)
149         print('Section: debug', file=f)
150         print('Priority: extra', file=f)
151         packages('Depends', deb_depends[debian_version], f)
152         print('Description: debugging symbols for dcpomatic', file=f)
153         print('  This package contains the debugging symbols for dcpomatic.', file=f)
154         print('', file=f)
155
156 def make_spec(filename, version, target):
157     """Make a .spec file for a RPM build"""
158     f = open(filename, 'w')
159     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
160     print('Name:dcpomatic2', file=f)
161     print('Version:%s' % version, file=f)
162     print('Release:1%{?dist}', file=f)
163     print('License:GPL', file=f)
164     print('Group:Applications/Multimedia', file=f)
165     print('URL:http://dcpomatic.com/', file=f)
166     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
167     print('', file=f)
168     print('%description', file=f)
169     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
170     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
171     print('digital projectors.', file=f)
172     print('', file=f)
173     print('%files', file=f)
174     print('%{_bindir}/dcpomatic2', file=f)
175     print('%{_bindir}/dcpomatic2_batch', file=f)
176     print('%{_bindir}/dcpomatic2_cli', file=f)
177     print('%{_bindir}/dcpomatic2_create', file=f)
178     print('%{_bindir}/dcpomatic2_kdm', file=f)
179     print('%{_bindir}/dcpomatic2_server', file=f)
180     print('%{_bindir}/dcpomatic2_server_cli', file=f)
181     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
182     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
183     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
184     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
185     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
186     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
187     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
188     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
189     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
190     print('%{_datadir}/dcpomatic2/splash.png', file=f)
191     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
192         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
193         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
194         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
195         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
196     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL', 'ru_RU', 'pl_PL', 'da_DK', 'pt_PT', 'pt_BR', 'sk_SK', 'cs_CZ', 'uk_UA', 'zh_CN']:
197         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
198         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
199         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
200     print('', file=f)
201     print('%prep', file=f)
202     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
203     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
204     print('%build', file=f)
205     print('cd dcpomatic-%s' % version, file=f)
206     print('export PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (target.directory, target.directory), file=f)
207
208     if target.distro == 'centos' and target.version == '5':
209         prefix = 'BUILDROOT/usr'
210     else:
211         prefix = '%{buildroot}/usr'
212
213     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%s --install-prefix=/usr %s' %
214           (target.directory, target.directory, prefix, configure_options(target)), file=f)
215     print('./waf', file=f)
216     print('%install', file=f)
217     print('cd dcpomatic-%s' % version, file=f)
218     print('./waf install', file=f)
219     print('', file=f)
220     print('%post', file=f)
221     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
222     print('', file=f)
223     print('%postun', file=f)
224     print('if [ $1 -eq 0 ] ; then', file=f)
225     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
226     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
227     print('fi', file=f)
228     print('', file=f)
229     print('%posttrans', file=f)
230     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
231
232 def dependencies(target):
233
234     if target.platform == 'linux':
235         ffmpeg_options = { 'shared': False }
236     else:
237         ffmpeg_options = {}
238
239     return (('ffmpeg-cdist', 'aab2fb1', ffmpeg_options),
240             ('libdcp', '8837fe7'),
241             ('libsub', '3e299e5'))
242
243 def configure_options(target):
244     opt = ''
245     if target.debug:
246         opt += ' --enable-debug'
247     if target.platform == 'windows':
248         opt += ' --target-windows'
249     elif target.platform == 'linux':
250         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
251         if target.distro == 'centos':
252             opt += ' --static-xmlsec --static-ssh --disable-tests'
253             if target.version == '6.5':
254                 opt += ' --static-boost --static-xmlpp'
255             elif target.version == '7':
256                 opt += ' --workaround-gssapi --static-xmlpp'
257
258     return opt
259
260 def build(target, options):
261     target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target)))
262     target.command('./waf')
263
264     if target.platform == 'linux' or target.platform == 'osx':
265         target.command('./waf install')
266
267 def package_windows(target):
268     shutil.copyfile('build/platform/windows/installer.%s.nsi' % target.bits, 'build/platform/windows/installer2.%s.nsi' % target.bits)
269     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
270     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
271     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, target.bits))
272     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, target.bits))
273     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.mingw_path, target.bits))
274     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
275     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % target.bits)
276     target.command('makensis build/platform/windows/installer2.%s.nsi' % target.bits)
277     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
278
279 def package_debian(target, cpu, version):
280     make_control(target.version, target.bits, 'debian/control', target.debug)
281     target.command('./waf dist')
282     f = open('debian/files', 'w')
283     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
284     shutil.rmtree('build/deb', ignore_errors=True)
285
286     os.makedirs('build/deb')
287     os.chdir('build/deb')
288     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
289     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
290     os.chdir('dcpomatic-%s' % version)
291     target.command('dch -b -v %s-1 "New upstream release."' % version)
292     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
293     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
294     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
295
296     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
297     if target.debug:
298         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
299     if target.version in ['15.04', '15.10', '16.04', '8']:
300         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
301     else:
302         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
303
304     target.command('dpkg-buildpackage -uc -us')
305
306     debs = []
307     for p in glob.glob('../*.deb'):
308         debs.append(os.path.abspath(p))
309
310     return debs
311
312 def package_rpm(target, cpu, version):
313     topdir = os.path.realpath('build/rpmbuild')
314     os.makedirs('%s/BUILD' % topdir)
315     os.makedirs('%s/RPMS' % topdir)
316     os.makedirs('%s/SOURCES' % topdir)
317     os.makedirs('%s/SPECS' % topdir)
318     os.makedirs('%s/SRPMS' % topdir)
319
320     target.command('./waf dist')
321     shutil.copyfile(
322         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
323         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
324         )
325
326     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
327     cmd = 'rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir
328     if target.distro == 'centos' and target.version == '5':
329         cmd += ' --buildroot %s/BUILD/dcpomatic-%s/BUILDROOT' % (topdir, version)
330     target.command(cmd)
331     rpms = []
332
333     if cpu == "amd64":
334         cpu = "x86_64"
335     else:
336         cpu = "i686"
337
338     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
339     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
340         print('found %s' % p)
341         rpms.append(os.path.abspath(p))
342
343     return rpms
344
345 def package(target, version):
346     if target.platform == 'windows':
347         return package_windows(target)
348     elif target.platform == 'linux':
349         if target.bits == 32:
350             cpu = 'i386'
351         else:
352             cpu = 'amd64'
353
354         if target.distro == 'debian' or target.distro == 'ubuntu':
355             return package_debian(target, cpu, version)
356         elif target.distro == 'centos' or target.distro == 'fedora':
357             return package_rpm(target, cpu, version)
358     elif target.platform == 'osx':
359         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
360         return os.path.abspath(glob.glob('build/platform/osx/DCP-o-matic*.dmg')[0])
361
362 def make_pot(target):
363     target.command('./waf pot')
364     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
365             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
366             os.path.abspath('build/src/tools/dcpomatic.pot')]
367
368 def make_manual(target):
369     os.chdir('doc/manual')
370     target.command('make')
371     target.command('pdflatex colour.tex')
372     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
373
374 def test(target, test):
375     if target.platform != 'windows':
376         target.set('LC_ALL', 'C')
377         if test is None:
378             target.command('run/tests')
379         else:
380             target.command('run/tests --run_test=%s' % test)