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