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