Some manual updates.
[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.04'] = copy.deepcopy(deb_build_depends_base)
36 deb_build_depends['17.04'].extend(['libssh-dev'])
37 deb_build_depends['17.10'] = copy.deepcopy(deb_build_depends_base)
38 deb_build_depends['17.10'].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
49 deb_depends_base = ['libc6', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libcurl3', 'libgtk2.0-0']
50
51 deb_depends['14.04'] = copy.deepcopy(deb_depends_base)
52 deb_depends['14.04'].extend(['libboost-filesystem1.54.0',
53                              'libboost-thread1.54.0',
54                              'libboost-regex1.54.0',
55                              'libmagick++5',
56                              'libxml++2.6-2',
57                              'libboost-date-time1.54.0',
58                              'libzip2',
59                              'libcairomm-1.0-1',
60                              'libpangomm-1.4-1,'
61                              'libicu52',
62                              'libnettle4',
63                              'libssh-4',
64                              'libx264-142'])
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                              'libcairomm-1.0-1v5',
75                              'libpangomm-1.4-1v5',
76                              'libwxgtk3.0-0v5',
77                              'libicu55',
78                              'libnettle6',
79                              'libssh-4',
80                              'libx264-148'])
81
82 deb_depends['17.04'] = copy.deepcopy(deb_depends_base)
83 deb_depends['17.04'].extend(['libboost-filesystem1.62.0',
84                              'libboost-thread1.62.0',
85                              'libboost-regex1.62.0',
86                              'libmagick++-6.q16-7',
87                              'libxml++2.6-2v5',
88                              'libboost-date-time1.62.0',
89                              'libzip4',
90                              'libwxgtk3.0-0v5',
91                              'libicu57',
92                              'libnettle6',
93                              'libssh-4',
94                              'libx264-148'])
95
96 deb_depends['17.10'] = copy.deepcopy(deb_depends_base)
97 deb_depends['17.10'].extend(['libboost-filesystem1.62.0',
98                              'libboost-thread1.62.0',
99                              'libboost-regex1.62.0',
100                              'libmagick++-6.q16-7',
101                              'libxml++2.6-2v5',
102                              'libboost-date-time1.62.0',
103                              'libzip4',
104                              'libwxgtk3.0-0v5',
105                              'libicu57',
106                              'libnettle6',
107                              'libssh-4',
108                              'libx264-148'])
109
110 deb_depends['7'] = copy.deepcopy(deb_depends_base)
111 deb_depends['7'].extend(['libboost-filesystem1.49.0',
112                              'libboost-thread1.49.0',
113                              'libboost-regex1.49.0',
114                              'libmagick++5',
115                              'libxml++2.6-2',
116                              'libboost-date-time1.49.0',
117                              'libzip2',
118                              'libcairomm-1.0-1',
119                              'libpangomm-1.4-1',
120                              'libicu48',
121                              'libnettle4',
122                              'libnotify4',
123                              'libx264-123'])
124
125 deb_depends['8'] = copy.deepcopy(deb_depends_base)
126 deb_depends['8'].extend(['libboost-filesystem1.55.0',
127                          'libboost-thread1.55.0',
128                          'libboost-date-time1.55.0',
129                          'libboost-regex1.55.0',
130                          'libmagick++-6.q16-5',
131                          'libxml++2.6-2',
132                          'libzip2',
133                          'libcairomm-1.0-1',
134                          'libpangomm-1.4-1',
135                          'libwxgtk3.0-0',
136                          'libxcb-xfixes0',
137                          'libxcb-shape0',
138                          'libicu52',
139                          'libnettle4',
140                          'libssh-4',
141                          'libx264-142'])
142
143 deb_depends['9'] = copy.deepcopy(deb_depends_base)
144 deb_depends['9'].extend(['libboost-filesystem1.62.0',
145                          'libboost-thread1.62.0',
146                          'libboost-regex1.62.0',
147                          'libboost-date-time1.62.0',
148                          'libmagick++-6.q16-7',
149                          'libxml++2.6-2v5',
150                          'libgtk2.0-0',
151                          'libzip4',
152                          'libicu57',
153                          'libnettle6',
154                          'libx264-148'])
155
156 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
157 deb_depends['unstable'].extend(['libboost-filesystem1.62.0',
158                                 'libboost-thread1.62.0',
159                                 'libboost-regex1.62.0',
160                                 'libboost-date-time1.62.0',
161                                 'libmagick++-6.q16-7',
162                                 'libxml++2.6-2v5',
163                                 'libgtk2.0-0',
164                                 'libzip4',
165                                 'libicu57',
166                                 'libnettle6',
167                                 'libx264-148'])
168
169 def packages(name, packages, f):
170     s = '%s: ' % name
171     for p in packages:
172         s += str(p) + ', '
173     print(s[:-2], file=f)
174
175 def make_control(debian_version, bits, filename, debug):
176     f = open(filename, 'w')
177     print('Source: dcpomatic', file=f)
178     print('Section: video', file=f)
179     print('Priority: extra', file=f)
180     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
181     packages('Build-Depends', deb_build_depends[debian_version], f)
182     print('Standards-Version: 3.9.3', file=f)
183     print('Homepage: http://dcpomatic.com/', file=f)
184     print('', file=f)
185     print('Package: dcpomatic', file=f)
186     if bits == 32:
187         print('Architecture: i386', file=f)
188     else:
189         print('Architecture: amd64', file=f)
190
191     packages('Depends', deb_depends[debian_version], f)
192
193     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
194     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from videos, images,', file=f)
195     print('  sound and subtitle files.  You can use it to make content for playback on DCI-compliant', file=f)
196     print('  cinema projectors.', file=f)
197
198     if debug:
199         print('', file=f)
200         print('Package: dcpomatic-dbg', file=f)
201         if bits == 32:
202             print('Architecture: i386', file=f)
203         else:
204             print('Architecture: amd64', file=f)
205         print('Section: debug', file=f)
206         print('Priority: extra', file=f)
207         packages('Depends', deb_depends[debian_version], f)
208         print('Description: debugging symbols for dcpomatic', file=f)
209         print('  This package contains the debugging symbols for dcpomatic.', file=f)
210         print('', file=f)
211
212 def make_spec(filename, version, target):
213     """Make a .spec file for a RPM build"""
214     f = open(filename, 'w')
215     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
216     print('Name:dcpomatic2', file=f)
217     print('Version:%s' % version, file=f)
218     print('Release:1%{?dist}', file=f)
219     print('License:GPL', file=f)
220     print('Group:Applications/Multimedia', file=f)
221     print('URL:http://dcpomatic.com/', file=f)
222     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
223     print('', file=f)
224     print('%description', file=f)
225     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
226     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
227     print('digital projectors.', file=f)
228     print('', file=f)
229     print('%files', file=f)
230     print('%{_bindir}/dcpomatic2', file=f)
231     print('%{_bindir}/dcpomatic2_batch', file=f)
232     print('%{_bindir}/dcpomatic2_cli', file=f)
233     print('%{_bindir}/dcpomatic2_create', file=f)
234     print('%{_bindir}/dcpomatic2_kdm', file=f)
235     print('%{_bindir}/dcpomatic2_server', file=f)
236     print('%{_bindir}/dcpomatic2_server_cli', file=f)
237     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
238     print('%{_bindir}/dcpomatic2_player', file=f)
239     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
240     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
241     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
242     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
243     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
244     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
245     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
246     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
247     print('%{_datadir}/dcpomatic2/splash.png', file=f)
248     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
249         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
250         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
251         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
252         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
253         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_player.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     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%%{buildroot}/usr --install-prefix=/usr %s' %
267           (target.directory, target.directory, configure_options(target)), file=f)
268     print('./waf', file=f)
269     print('%install', file=f)
270     print('cd dcpomatic-%s' % version, file=f)
271     print('./waf install', file=f)
272     print('', file=f)
273     print('%post', file=f)
274     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
275     print('', file=f)
276     print('%postun', file=f)
277     print('if [ $1 -eq 0 ] ; then', file=f)
278     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
279     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
280     print('fi', file=f)
281     print('', file=f)
282     print('%posttrans', file=f)
283     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
284
285 def dependencies(target):
286
287     if target.platform == 'linux':
288         ffmpeg_options = { 'shared': False }
289     else:
290         ffmpeg_options = {}
291
292     return (('ffmpeg-cdist', '5fce90f', ffmpeg_options),
293             ('libdcp', '4bdc3a8'),
294             ('libsub', '3b9dd0a'),
295             ('rtaudio-cdist', None))
296
297 def configure_options(target):
298     opt = ''
299     if target.debug:
300         opt += ' --enable-debug'
301     if target.platform == 'windows':
302         opt += ' --target-windows'
303     elif target.platform == 'linux':
304         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
305         if target.distro == 'centos':
306             opt += ' --disable-tests'
307             if target.version == '6.5':
308                 opt += ' --static-boost --static-xmlpp'
309             elif target.version == '7':
310                 opt += ' --workaround-gssapi'
311                 # Centos 7 ships with glibmm 2.50.0 which requires C++11
312                 # but its compiler (gcc 4.8.5) defaults to C++97.  Go figure.
313                 # I worry that this will cause ABI problems but I don't have
314                 # a better solution.
315                 opt += ' --force-cpp11'
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     print('package_rpm %s %s %s' % (target, cpu, version))
381     topdir = os.path.realpath('build/rpmbuild')
382     os.makedirs('%s/BUILD' % topdir)
383     os.makedirs('%s/RPMS' % topdir)
384     os.makedirs('%s/SOURCES' % topdir)
385     os.makedirs('%s/SPECS' % topdir)
386     os.makedirs('%s/SRPMS' % topdir)
387
388     target.command('./waf dist')
389     shutil.copyfile(
390         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
391         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
392         )
393
394     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
395     cmd = 'rpmbuild --define "_topdir %s" -bb build/platform/linux/dcpomatic2.spec' % topdir
396     target.command(cmd)
397     rpms = []
398
399     if cpu == "amd64":
400         cpu = "x86_64"
401     else:
402         cpu = "i686"
403
404     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
405     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
406         print('found %s' % p)
407         rpms.append(os.path.abspath(p))
408
409     return rpms
410
411 def package(target, version):
412     if target.platform == 'windows':
413         return package_windows(target)
414     elif target.platform == 'linux':
415         if target.bits == 32:
416             cpu = 'i386'
417         else:
418             cpu = 'amd64'
419
420         if target.distro == 'debian' or target.distro == 'ubuntu':
421             return package_debian(target, cpu, version)
422         elif target.distro == 'centos' or target.distro == 'fedora' or target.distro == 'mageia':
423             return package_rpm(target, cpu, version)
424     elif target.platform == 'osx':
425         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
426         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
427     elif target.platform == 'docker':
428         shutil.copyfile(target.deb, 'build/platform/docker')
429         f = open('build/platform/docker/Dockerfile', 'w')
430         print('FROM debian:jessie', file=f)
431         print('MAINTAINER carl@dcpomatic.com', file=f)
432         print('ADD build/platform/docker/dcpomatic_%s-1_amd64.deb /tmp' % (version, version), file=f)
433         print('RUN apt-get -o Acquire:http::Timeout="5" update; exit 0', file=f)
434         print('RUN dpkg -i /tmp/dcpomatic_*.deb; exit 0', file=f)
435         print('RUN apt-get -y -f install', file=f)
436         print('RUN apt-get clean', file=f)
437         print('EXPOSE 6192', file=f)
438         print('CMD ["/usr/bin/dcpomatic2_server_cli", "--verbose"]', file=f)
439         f.close()
440         target.command('docker build build/platform/docker -t dcpomatic-server:%s' % version)
441         target.command('docker save dcpomatic-server:%s -o dcpomatic-server-%s-docker.tar' % (version, version))
442
443 def make_pot(target):
444     target.command('./waf pot')
445     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
446             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
447             os.path.abspath('build/src/tools/dcpomatic.pot')]
448
449 def make_manual(target):
450     os.chdir('doc/manual')
451     target.command('make')
452     target.command('pdflatex colour.tex')
453     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
454
455 def test(target, test):
456     if target.platform != 'windows':
457         target.set('LC_ALL', 'C')
458         cmd = 'run/tests '
459         if target.debug:
460             cmd += '--backtrace '
461         if test is not None:
462             cmd += '--run_test=%s' % test
463         target.command(cmd)