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