Support more detailed horizontal positioning coming from libsub.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2017 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 = dict()
28
29 deb_build_depends_base = ['debhelper', 'python', 'g++', 'pkg-config', 'libsndfile1-dev', 'libgtk2.0-dev', 'libx264-dev']
30
31 deb_build_depends['12.04'] = copy.deepcopy(deb_build_depends_base)
32 deb_build_depends['12.04'].extend(['libssh-dev'])
33 deb_build_depends['14.04'] = copy.deepcopy(deb_build_depends_base)
34 deb_build_depends['14.04'].extend(['libssh-dev'])
35 deb_build_depends['16.04'] = copy.deepcopy(deb_build_depends_base)
36 deb_build_depends['16.04'].extend(['libssh-dev'])
37 deb_build_depends['16.10'] = copy.deepcopy(deb_build_depends_base)
38 deb_build_depends['16.10'].extend(['libssh-dev'])
39 deb_build_depends['17.04'] = copy.deepcopy(deb_build_depends_base)
40 deb_build_depends['17.04'].extend(['libssh-dev'])
41 deb_build_depends['7'] = copy.deepcopy(deb_build_depends_base)
42 deb_build_depends['7'].extend(['libssh-dev'])
43 deb_build_depends['8'] = copy.deepcopy(deb_build_depends_base)
44 deb_build_depends['8'].extend(['libssh-gcrypt-dev'])
45 deb_build_depends['9'] = copy.deepcopy(deb_build_depends_base)
46 deb_build_depends['9'].extend(['libssh-gcrypt-dev'])
47 deb_build_depends['unstable'] = copy.deepcopy(deb_build_depends_base)
48
49 deb_depends = dict()
50
51 deb_depends_base = ['libc6', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libcurl3', 'libgtk2.0-0']
52
53 deb_depends['14.04'] = copy.deepcopy(deb_depends_base)
54 deb_depends['14.04'].extend(['libboost-filesystem1.54.0',
55                              'libboost-thread1.54.0',
56                              'libboost-regex1.54.0',
57                              'libmagick++5',
58                              'libxml++2.6-2',
59                              'libboost-date-time1.54.0',
60                              'libzip2',
61                              'libcairomm-1.0-1',
62                              'libpangomm-1.4-1,'
63                              'libicu52',
64                              'libnettle4',
65                              'libssh-4',
66                              'libx264-142'])
67
68 deb_depends['16.04'] = copy.deepcopy(deb_depends_base)
69 deb_depends['16.04'].extend(['libboost-filesystem1.58.0',
70                              'libboost-thread1.58.0',
71                              'libboost-regex1.58.0',
72                              'libmagick++-6.q16-5v5',
73                              'libxml++2.6-2v5',
74                              'libboost-date-time1.58.0',
75                              'libzip4',
76                              'libcairomm-1.0-1v5',
77                              'libpangomm-1.4-1v5',
78                              'libwxgtk3.0-0v5',
79                              'libicu55',
80                              'libnettle6',
81                              'libssh-4',
82                              'libx264-148'])
83
84 deb_depends['16.10'] = copy.deepcopy(deb_depends_base)
85 deb_depends['16.10'].extend(['libboost-filesystem1.61.0',
86                              'libboost-thread1.61.0',
87                              'libboost-regex1.61.0',
88                              'libmagick++-6.q16-5v5',
89                              'libxml++2.6-2v5',
90                              'libboost-date-time1.61.0',
91                              'libzip4',
92                              'libwxgtk3.0-0v5',
93                              'libicu57',
94                              'libnettle6',
95                              'libssh-4',
96                              'libx264-148'])
97
98 deb_depends['17.04'] = copy.deepcopy(deb_depends_base)
99 deb_depends['17.04'].extend(['libboost-filesystem1.62.0',
100                              'libboost-thread1.62.0',
101                              'libboost-regex1.62.0',
102                              'libmagick++-6.q16-7',
103                              'libxml++2.6-2v5',
104                              'libboost-date-time1.62.0',
105                              'libzip4',
106                              'libwxgtk3.0-0v5',
107                              'libicu57',
108                              'libnettle6',
109                              'libssh-4',
110                              'libx264-148'])
111
112 deb_depends['7'] = copy.deepcopy(deb_depends_base)
113 deb_depends['7'].extend(['libboost-filesystem1.49.0',
114                              'libboost-thread1.49.0',
115                              'libboost-regex1.49.0',
116                              'libmagick++5',
117                              'libxml++2.6-2',
118                              'libboost-date-time1.49.0',
119                              'libzip2',
120                              'libcairomm-1.0-1',
121                              'libpangomm-1.4-1',
122                              'libicu48',
123                              'libnettle4',
124                              'libnotify4',
125                              'libx264-123'])
126
127 deb_depends['8'] = copy.deepcopy(deb_depends_base)
128 deb_depends['8'].extend(['libboost-filesystem1.55.0',
129                          'libboost-thread1.55.0',
130                          'libboost-date-time1.55.0',
131                          'libboost-regex1.55.0',
132                          'libmagick++-6.q16-5',
133                          'libxml++2.6-2',
134                          'libzip2',
135                          'libcairomm-1.0-1',
136                          'libpangomm-1.4-1',
137                          'libwxgtk3.0-0',
138                          'libxcb-xfixes0',
139                          'libxcb-shape0',
140                          'libicu52',
141                          'libnettle4',
142                          'libssh-4',
143                          'libx264-142'])
144
145 deb_depends['9'] = copy.deepcopy(deb_depends_base)
146 deb_depends['9'].extend(['libboost-filesystem1.62.0',
147                          'libboost-thread1.62.0',
148                          'libboost-regex1.62.0',
149                          'libboost-date-time1.62.0',
150                          'libmagick++-6.q16-7',
151                          'libxml++2.6-2v5',
152                          'libgtk2.0-0',
153                          'libzip4',
154                          'libicu57',
155                          'libnettle6',
156                          'libx264-148'])
157
158 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
159 deb_depends['unstable'].extend(['libboost-filesystem1.62.0',
160                                 'libboost-thread1.62.0',
161                                 'libboost-regex1.62.0',
162                                 'libboost-date-time1.62.0',
163                                 'libmagick++-6.q16-7',
164                                 'libxml++2.6-2v5',
165                                 'libgtk2.0-0',
166                                 'libzip4',
167                                 'libicu57',
168                                 'libnettle6',
169                                 'libx264-148'])
170
171 def packages(name, packages, f):
172     s = '%s: ' % name
173     for p in packages:
174         s += str(p) + ', '
175     print(s[:-2], file=f)
176
177 def make_control(debian_version, bits, filename, debug):
178     f = open(filename, 'w')
179     print('Source: dcpomatic', file=f)
180     print('Section: video', file=f)
181     print('Priority: extra', file=f)
182     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
183     packages('Build-Depends', deb_build_depends[debian_version], f)
184     print('Standards-Version: 3.9.3', file=f)
185     print('Homepage: http://dcpomatic.com/', file=f)
186     print('', file=f)
187     print('Package: dcpomatic', file=f)
188     if bits == 32:
189         print('Architecture: i386', file=f)
190     else:
191         print('Architecture: amd64', file=f)
192
193     packages('Depends', deb_depends[debian_version], f)
194
195     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
196     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio', file=f)
197     print('  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant', file=f)
198     print('  digital projectors.', file=f)
199
200     if debug:
201         print('', file=f)
202         print('Package: dcpomatic-dbg', file=f)
203         if bits == 32:
204             print('Architecture: i386', file=f)
205         else:
206             print('Architecture: amd64', file=f)
207         print('Section: debug', file=f)
208         print('Priority: extra', file=f)
209         packages('Depends', deb_depends[debian_version], f)
210         print('Description: debugging symbols for dcpomatic', file=f)
211         print('  This package contains the debugging symbols for dcpomatic.', file=f)
212         print('', file=f)
213
214 def make_spec(filename, version, target):
215     """Make a .spec file for a RPM build"""
216     f = open(filename, 'w')
217     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
218     print('Name:dcpomatic2', file=f)
219     print('Version:%s' % version, file=f)
220     print('Release:1%{?dist}', file=f)
221     print('License:GPL', file=f)
222     print('Group:Applications/Multimedia', file=f)
223     print('URL:http://dcpomatic.com/', file=f)
224     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
225     print('', file=f)
226     print('%description', file=f)
227     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
228     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
229     print('digital projectors.', file=f)
230     print('', file=f)
231     print('%files', file=f)
232     print('%{_bindir}/dcpomatic2', file=f)
233     print('%{_bindir}/dcpomatic2_batch', file=f)
234     print('%{_bindir}/dcpomatic2_cli', file=f)
235     print('%{_bindir}/dcpomatic2_create', file=f)
236     print('%{_bindir}/dcpomatic2_kdm', file=f)
237     print('%{_bindir}/dcpomatic2_server', file=f)
238     print('%{_bindir}/dcpomatic2_server_cli', file=f)
239     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
240     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
241     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
242     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
243     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
244     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
245     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
246     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
247     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
248     print('%{_datadir}/dcpomatic2/splash.png', file=f)
249     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
250         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
251         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
252         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
253         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
254     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']:
255         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
256         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
257         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
258     print('', file=f)
259     print('%prep', file=f)
260     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
261     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
262     print('%build', file=f)
263     print('cd dcpomatic-%s' % version, file=f)
264     print('export PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig' % (target.directory, target.directory), file=f)
265
266     if target.distro == 'centos' and target.version == '5':
267         prefix = 'BUILDROOT/usr'
268     else:
269         prefix = '%{buildroot}/usr'
270
271     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%s --install-prefix=/usr %s' %
272           (target.directory, target.directory, prefix, configure_options(target)), file=f)
273     print('./waf', file=f)
274     print('%install', file=f)
275     print('cd dcpomatic-%s' % version, file=f)
276     print('./waf install', file=f)
277     print('', file=f)
278     print('%post', file=f)
279     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
280     print('', file=f)
281     print('%postun', file=f)
282     print('if [ $1 -eq 0 ] ; then', file=f)
283     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
284     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
285     print('fi', file=f)
286     print('', file=f)
287     print('%posttrans', file=f)
288     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
289
290 def dependencies(target):
291
292     if target.platform == 'linux':
293         ffmpeg_options = { 'shared': False }
294     else:
295         ffmpeg_options = {}
296
297     return (('ffmpeg-cdist', '5fce90f', ffmpeg_options),
298             ('libdcp', '047d8ff'),
299             ('libsub', 'ec880ed'),
300             ('rtaudio-cdist', None))
301
302 def configure_options(target):
303     opt = ''
304     if target.debug:
305         opt += ' --enable-debug'
306     if target.platform == 'windows':
307         opt += ' --target-windows'
308     elif target.platform == 'linux':
309         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
310         if target.distro == 'centos':
311             opt += ' --disable-tests'
312             if target.version == '6.5':
313                 opt += ' --static-boost --static-xmlpp'
314             elif target.version == '7':
315                 opt += ' --workaround-gssapi'
316
317     # Build Windows debug versions with static linking as I think gdb works better then
318     if target.debug and target.platform == 'windows':
319         opt += ' --static-dcpomatic'
320
321     return opt
322
323 def build(target, options):
324     target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target)))
325     target.command('./waf')
326
327     if target.platform == 'linux' or target.platform == 'osx':
328         target.command('./waf install')
329
330 def package_windows(target):
331     identifier = ''
332     if target.version is not None:
333         identifier = '%s.' % target.version
334     identifier += '%d' % target.bits
335     shutil.copyfile('build/platform/windows/installer.%s.nsi' % identifier, 'build/platform/windows/installer2.%s.nsi' % identifier)
336     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
337     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
338     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, identifier))
339     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, identifier))
340     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.mingw_path, identifier))
341     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
342     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % identifier)
343     target.command('makensis build/platform/windows/installer2.%s.nsi' % identifier)
344     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
345
346 def package_debian(target, cpu, version):
347     make_control(target.version, target.bits, 'debian/control', target.debug)
348     target.command('./waf dist')
349     f = open('debian/files', 'w')
350     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
351     shutil.rmtree('build/deb', ignore_errors=True)
352
353     os.makedirs('build/deb')
354     os.chdir('build/deb')
355     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
356     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
357     os.chdir('dcpomatic-%s' % version)
358     target.command('dch -b -v %s-1 "New upstream release."' % version)
359     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
360     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
361     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
362
363     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
364     if target.debug:
365         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
366     if target.version in ['7', '14.04']:
367         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
368     else:
369         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
370
371     target.command('dpkg-buildpackage -uc -us')
372
373     debs = []
374     for p in glob.glob('../*.deb'):
375         debs.append(os.path.abspath(p))
376
377     return debs
378
379 def package_rpm(target, cpu, version):
380     topdir = os.path.realpath('build/rpmbuild')
381     os.makedirs('%s/BUILD' % topdir)
382     os.makedirs('%s/RPMS' % topdir)
383     os.makedirs('%s/SOURCES' % topdir)
384     os.makedirs('%s/SPECS' % topdir)
385     os.makedirs('%s/SRPMS' % topdir)
386
387     target.command('./waf dist')
388     shutil.copyfile(
389         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
390         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
391         )
392
393     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
394     cmd = 'rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir
395     if target.distro == 'centos' and target.version == '5':
396         cmd += ' --buildroot %s/BUILD/dcpomatic-%s/BUILDROOT' % (topdir, version)
397     target.command(cmd)
398     rpms = []
399
400     if cpu == "amd64":
401         cpu = "x86_64"
402     else:
403         if target.distro == 'centos' and target.version == '5':
404             cpu = "i386"
405         else:
406             cpu = "i686"
407
408     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
409     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
410         print('found %s' % p)
411         rpms.append(os.path.abspath(p))
412
413     return rpms
414
415 def package(target, version):
416     if target.platform == 'windows':
417         return package_windows(target)
418     elif target.platform == 'linux':
419         if target.bits == 32:
420             cpu = 'i386'
421         else:
422             cpu = 'amd64'
423
424         if target.distro == 'debian' or target.distro == 'ubuntu':
425             return package_debian(target, cpu, version)
426         elif target.distro == 'centos' or target.distro == 'fedora':
427             return package_rpm(target, cpu, version)
428     elif target.platform == 'osx':
429         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
430         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
431     elif target.platform == 'docker':
432         shutil.copyfile(target.deb, 'build/platform/docker')
433         f = open('build/platform/docker/Dockerfile', 'w')
434         print('FROM debian:jessie', file=f)
435         print('MAINTAINER carl@dcpomatic.com', file=f)
436         print('ADD build/platform/docker/dcpomatic_%s-1_amd64.deb /tmp' % (version, version), file=f)
437         print('RUN apt-get -o Acquire:http::Timeout="5" update; exit 0', file=f)
438         print('RUN dpkg -i /tmp/dcpomatic_*.deb; exit 0', file=f)
439         print('RUN apt-get -y -f install', file=f)
440         print('RUN apt-get clean', file=f)
441         print('EXPOSE 6192', file=f)
442         print('CMD ["/usr/bin/dcpomatic2_server_cli", "--verbose"]', file=f)
443         f.close()
444         target.command('docker build build/platform/docker -t dcpomatic-server:%s' % version)
445         target.command('docker save dcpomatic-server:%s -o dcpomatic-server-%s-docker.tar' % (version, version))
446
447 def make_pot(target):
448     target.command('./waf pot')
449     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
450             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
451             os.path.abspath('build/src/tools/dcpomatic.pot')]
452
453 def make_manual(target):
454     os.chdir('doc/manual')
455     target.command('make')
456     target.command('pdflatex colour.tex')
457     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
458
459 def test(target, test):
460     if target.platform != 'windows':
461         target.set('LC_ALL', 'C')
462         cmd = 'run/tests '
463         if target.debug:
464             cmd += '--backtrace '
465         if test is not None:
466             cmd += '--run_test=%s' % test
467         target.command(cmd)