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