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