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