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