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