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