Prompt to recreate > ~10 year old certificates on startup.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2020 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 import json
27
28 deb_build_depends = dict()
29
30 deb_build_depends_base = ['debhelper', 'g++', 'pkg-config', 'libsndfile1-dev', 'libgtk2.0-dev', 'libx264-dev']
31
32 deb_build_depends['16.04'] = copy.deepcopy(deb_build_depends_base)
33 deb_build_depends['16.04'].extend(['libssh-dev', 'python'])
34 deb_build_depends['18.04'] = copy.deepcopy(deb_build_depends_base)
35 deb_build_depends['18.04'].extend(['libssh-dev', 'python'])
36 deb_build_depends['20.04'] = copy.deepcopy(deb_build_depends_base)
37 deb_build_depends['20.04'].extend(['libssh-dev', 'python'])
38 deb_build_depends['20.10'] = copy.deepcopy(deb_build_depends_base)
39 deb_build_depends['20.10'].extend(['libssh-dev', 'python'])
40 deb_build_depends['21.04'] = copy.deepcopy(deb_build_depends_base)
41 deb_build_depends['21.04'].extend(['libssh-dev', 'python'])
42 deb_build_depends['21.10'] = copy.deepcopy(deb_build_depends_base)
43 deb_build_depends['21.10'].extend(['libssh-dev', 'python'])
44 deb_build_depends['9'] = copy.deepcopy(deb_build_depends_base)
45 deb_build_depends['9'].extend(['libssh-gcrypt-dev', 'python'])
46 deb_build_depends['10'] = copy.deepcopy(deb_build_depends_base)
47 deb_build_depends['10'].extend(['libssh-gcrypt-dev', 'python'])
48 deb_build_depends['11'] = copy.deepcopy(deb_build_depends_base)
49 deb_build_depends['11'].extend(['libssh-gcrypt-dev', 'python3.9'])
50 deb_build_depends['unstable'] = copy.deepcopy(deb_build_depends_base)
51
52 deb_depends = dict()
53 deb_depends_gui = dict()
54
55 deb_depends_base = ['libc6', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libgtk2.0-0']
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                              'libxml++2.6-2v5',
62                              'libboost-date-time1.58.0',
63                              'libzip4',
64                              'libcairomm-1.0-1v5',
65                              'libpangomm-1.4-1v5',
66                              'libwxgtk3.0-0v5',
67                              'libicu55',
68                              'libnettle6',
69                              'libssh-4',
70                              'libx264-148',
71                              'libcurl3'])
72
73 deb_depends['18.04'] = copy.deepcopy(deb_depends_base)
74 deb_depends['18.04'].extend(['libboost-filesystem1.65.1',
75                              'libboost-thread1.65.1',
76                              'libboost-regex1.65.1',
77                              'libboost-date-time1.65.1',
78                              'libcairomm-1.0-1v5',
79                              'libpangomm-1.4-1v5',
80                              'libxml++2.6-2v5',
81                              'libzip4',
82                              'libwxgtk3.0-0v5',
83                              'libicu60',
84                              'libnettle6',
85                              'libssh-4',
86                              'libx264-152',
87                              'libcurl4',
88                              'libpulse0'])
89
90 deb_depends['20.04'] = copy.deepcopy(deb_depends_base)
91 deb_depends['20.04'].extend(['libboost-filesystem1.71.0',
92                              'libboost-thread1.71.0',
93                              'libboost-regex1.71.0',
94                              'libboost-date-time1.71.0',
95                              'libcairomm-1.0-1v5',
96                              'libpangomm-1.4-1v5',
97                              'libxml++2.6-2v5',
98                              'libzip5',
99                              'libwxgtk3.0-gtk3-0v5',
100                              'libicu66',
101                              'libnettle7',
102                              'libssh-4',
103                              'libx264-155',
104                              'libcurl4',
105                              'libpulse0',
106                              'libxerces-c3.2',
107                              'libnanomsg5'])
108
109 deb_depends['20.10'] = copy.deepcopy(deb_depends_base)
110 deb_depends['20.10'].extend(['libboost-filesystem1.71.0',
111                              'libboost-thread1.71.0',
112                              'libboost-regex1.71.0',
113                              'libboost-date-time1.71.0',
114                              'libcairomm-1.0-1v5',
115                              'libpangomm-1.4-1v5',
116                              'libxml++2.6-2v5',
117                              'libzip5',
118                              'libicu67',
119                              'libnettle8',
120                              'libssh-4',
121                              'libx264-160',
122                              'libcurl4',
123                              'libpulse0',
124                              'libxerces-c3.2',
125                              'libnanomsg5'])
126
127 deb_depends['21.04'] = copy.deepcopy(deb_depends_base)
128 deb_depends['21.04'].extend(['libboost-filesystem1.74.0',
129                              'libboost-thread1.74.0',
130                              'libboost-regex1.74.0',
131                              'libboost-date-time1.74.0',
132                              'libcairomm-1.0-1v5',
133                              'libpangomm-1.4-1v5',
134                              'libxml++2.6-2v5',
135                              'libzip4',
136                              'libicu67',
137                              'libnettle8',
138                              'libssh-4',
139                              'libx264-160',
140                              'libcurl4',
141                              'libpulse0',
142                              'libxerces-c3.2',
143                              'libnanomsg5'])
144
145 deb_depends['21.10'] = copy.deepcopy(deb_depends_base)
146 deb_depends['21.10'].extend(['libboost-filesystem1.74.0',
147                              'libboost-thread1.74.0',
148                              'libboost-regex1.74.0',
149                              'libboost-date-time1.74.0',
150                              'libcairomm-1.0-1v5',
151                              'libpangomm-1.4-1v5',
152                              'libxml++2.6-2v5',
153                              'libzip4',
154                              'libicu67',
155                              'libnettle8',
156                              'libssh-4',
157                              'libx264-160',
158                              'libcurl4',
159                              'libpulse0',
160                              'libxerces-c3.2',
161                              'libnanomsg5'])
162
163 deb_depends['9'] = copy.deepcopy(deb_depends_base)
164 deb_depends['9'].extend(['libboost-filesystem1.62.0',
165                          'libboost-thread1.62.0',
166                          'libboost-regex1.62.0',
167                          'libboost-date-time1.62.0',
168                          'libxml++2.6-2v5',
169                          'libgtk2.0-0',
170                          'libzip4',
171                          'libcairomm-1.0-1v5',
172                          'libpangomm-1.4-1v5',
173                          'libicu57',
174                          'libssh-4',
175                          'libssh-gcrypt-4',
176                          'libnettle6',
177                          'libx264-148',
178                          'libcurl3'])
179
180 deb_depends_gui['9'] = [ 'libwxgtk3.0-0v5',
181                          'libxcb-xfixes0',
182                          'libxcb-shape0',
183                          'libasound2',
184                          'libpulse0' ]
185
186 deb_depends['10'] = copy.deepcopy(deb_depends_base)
187 deb_depends['10'].extend(['libboost-filesystem1.67.0',
188                           'libboost-thread1.67.0',
189                           'libboost-regex1.67.0',
190                           'libboost-date-time1.67.0',
191                           'libxml++2.6-2v5',
192                           'libgtk2.0-0',
193                           'libzip4',
194                           'libcairomm-1.0-1v5',
195                           'libpangomm-1.4-1v5',
196                           'libicu63',
197                           'libssh-4',
198                           'libssh-gcrypt-4',
199                           'libnettle6',
200                           'libx264-155',
201                           'libcurl4'])
202
203 deb_depends_gui['10'] = [ 'libwxgtk3.0-0v5',
204                           'libxcb-xfixes0',
205                           'libxcb-shape0',
206                           'libasound2',
207                           'libpulse0' ]
208
209 deb_depends['11'] = copy.deepcopy(deb_depends_base)
210 deb_depends['11'].extend(['libboost-filesystem1.74.0',
211                           'libboost-thread1.74.0',
212                           'libboost-regex1.74.0',
213                           'libboost-date-time1.74.0',
214                           'libxml++2.6-2v5',
215                           'libzip4',
216                           'libcairomm-1.0-1v5',
217                           'libpangomm-1.4-1v5',
218                           'libicu67',
219                           'libssh-4',
220                           'libssh-gcrypt-4',
221                           'libnettle8',
222                           'libx264-160',
223                           'libcurl4',
224                           'libxerces-c3.2',
225                           'libnanomsg5'])
226
227 deb_depends_gui['11'] = [ 'libwxgtk3.0-gtk3-0v5',
228                           'libxcb-xfixes0',
229                           'libxcb-shape0',
230                           'libasound2',
231                           'libpulse0' ]
232
233 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
234 deb_depends['unstable'].extend(['libboost-filesystem1.67.0',
235                                 'libboost-thread1.67.0',
236                                 'libboost-regex1.67.0',
237                                 'libboost-date-time1.67.0',
238                                 'libxml++2.6-2v5',
239                                 'libgtk2.0-0',
240                                 'libzip4',
241                                 'libicu63',
242                                 'libnettle6',
243                                 'libx264-155',
244                                 'libcurl4'])
245
246 def packages(name, packages, f):
247     s = '%s: ' % name
248     for p in packages:
249         s += str(p) + ', '
250     print(s[:-2], file=f)
251
252 def make_control(debian_version, bits, filename, debug, gui):
253     f = open(filename, 'w')
254     print('Source: dcpomatic', file=f)
255     print('Section: video', file=f)
256     print('Priority: extra', file=f)
257     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
258     packages('Build-Depends', deb_build_depends[debian_version], f)
259     print('Standards-Version: 3.9.3', file=f)
260     print('Homepage: https://dcpomatic.com/', file=f)
261     print('', file=f)
262     print('Package: dcpomatic', file=f)
263     if bits == 32:
264         print('Architecture: i386', file=f)
265     else:
266         print('Architecture: amd64', file=f)
267
268     pkg = deb_depends[debian_version]
269     if gui and debian_version in deb_depends_gui:
270         pkg.extend(deb_depends_gui[debian_version])
271
272     packages('Depends', pkg, f)
273
274     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
275     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from videos, images,', file=f)
276     print('  sound and subtitle files.  You can use it to make content for playback on DCI-compliant', file=f)
277     print('  cinema projectors.', file=f)
278
279     if debug:
280         print('', file=f)
281         print('Package: dcpomatic-dbg', file=f)
282         if bits == 32:
283             print('Architecture: i386', file=f)
284         else:
285             print('Architecture: amd64', file=f)
286         print('Section: debug', file=f)
287         print('Priority: extra', file=f)
288         packages('Depends', pkg, f)
289         print('Description: debugging symbols for dcpomatic', file=f)
290         print('  This package contains the debugging symbols for dcpomatic.', file=f)
291         print('', file=f)
292
293 def make_spec(filename, version, target, options, requires=None):
294     """Make a .spec file for a RPM build"""
295     f = open(filename, 'w')
296     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
297     print('Name:dcpomatic2', file=f)
298     print('Version:%s' % version, file=f)
299     print('Release:1%{?dist}', file=f)
300     print('License:GPL', file=f)
301     print('Group:Applications/Multimedia', file=f)
302     print('URL:https://dcpomatic.com/', file=f)
303     if requires is not None:
304         print('Requires:%s' % requires, file=f)
305     print('', file=f)
306     print('%description', file=f)
307     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
308     print('files for presentation on DCI-compliant digital projectors.', file=f)
309     print('', file=f)
310     print('%files', file=f)
311     print('%{_bindir}/dcpomatic2', file=f)
312     print('%{_bindir}/dcpomatic2_batch', file=f)
313     print('%{_bindir}/dcpomatic2_cli', file=f)
314     print('%{_bindir}/dcpomatic2_create', file=f)
315     print('%{_bindir}/dcpomatic2_kdm', file=f)
316     print('%{_bindir}/dcpomatic2_server', file=f)
317     print('%{_bindir}/dcpomatic2_server_cli', file=f)
318     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
319     print('%{_bindir}/dcpomatic2_player', file=f)
320     print('%{_bindir}/dcpomatic2_playlist', file=f)
321     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
322     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
323     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
324     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
325     print('%{_datadir}/applications/dcpomatic2_player.desktop', file=f)
326     print('%{_datadir}/applications/dcpomatic2_playlist.desktop', file=f)
327     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
328     print('%{_datadir}/dcpomatic2/select.png', file=f)
329     print('%{_datadir}/dcpomatic2/sequence.png', file=f)
330     print('%{_datadir}/dcpomatic2/snap.png', file=f)
331     print('%{_datadir}/dcpomatic2/zoom.png', file=f)
332     print('%{_datadir}/dcpomatic2/zoom_all.png', file=f)
333     print('%{_datadir}/dcpomatic2/tick.png', file=f)
334     print('%{_datadir}/dcpomatic2/no_tick.png', file=f)
335     print('%{_datadir}/dcpomatic2/me.jpg', file=f)
336     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
337     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
338     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
339     print('%{_datadir}/dcpomatic2/splash.png', file=f)
340     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
341         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
342         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
343         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
344         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
345         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_player.png' % r, file=f)
346         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_playlist.png' % r, file=f)
347     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL', 'ru_RU', 'pl_PL', 'da_DK',
348               'pt_PT', 'pt_BR', 'sk_SK', 'cs_CZ', 'uk_UA', 'zh_CN', 'tr_TR', 'ko_KR']:
349         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
350         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
351         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
352     print('', file=f)
353     print('%prep', file=f)
354     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
355     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
356     print('%build', file=f)
357     print('cd dcpomatic-%s' % version, file=f)
358     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)
359
360     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%%{buildroot}/usr --install-prefix=/usr %s' %
361           (target.directory, target.directory, configure_options(target, options)), file=f)
362     print('./waf', file=f)
363     print('%install', file=f)
364     print('cd dcpomatic-%s' % version, file=f)
365     print('./waf install', file=f)
366     print('', file=f)
367     print('%post', file=f)
368     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
369     print('', file=f)
370     print('%postun', file=f)
371     print('if [ $1 -eq 0 ] ; then', file=f)
372     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
373     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
374     print('fi', file=f)
375     print('', file=f)
376     print('%posttrans', file=f)
377     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
378
379 def dependencies(target):
380
381     if target.platform == 'linux':
382         ffmpeg_options = { 'shared': False }
383     else:
384         ffmpeg_options = {}
385
386     if target.platform == 'windows' and target.version == 'xp':
387         deps = [('ffmpeg-cdist', '5783efa', ffmpeg_options)]
388     elif target.platform != 'linux' or target.distro != 'arch':
389         deps = [('ffmpeg-cdist', 'a820b44', ffmpeg_options)]
390     else:
391         # Use distro-provided FFmpeg on Arch
392         deps = []
393
394     deps.append(('libdcp', 'v1.6.20'))
395     deps.append(('libsub', 'v1.4.27'))
396     deps.append(('rtaudio-cdist', 'bf0fc23'))
397
398     return deps
399
400 def option_defaults():
401     return { "gui": True, "variant": None }
402
403 def configure_options(target, options):
404     opt = ''
405
406     if not (target.platform == 'linux' and target.distro == 'ubuntu' and target.version == '18.04'):
407         # Currently we only build tests on Ubuntu 18.04
408         opt += ' --disable-tests'
409
410     if target.debug:
411         opt += ' --enable-debug'
412     if target.platform == 'windows':
413         opt += ' --target-windows'
414     elif target.platform == 'linux':
415         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
416         if target.distro == 'centos':
417             if target.version == '6.5':
418                 opt += ' --static-boost --static-xmlpp'
419             elif target.version == '7':
420                 opt += ' --workaround-gssapi'
421                 # Centos 7 ships with glibmm 2.50.0 which requires C++11
422                 # but its compiler (gcc 4.8.5) defaults to C++97.  Go figure.
423                 # I worry that this will cause ABI problems but I don't have
424                 # a better solution.
425                 opt += ' --force-cpp11'
426
427     if not options['gui']:
428         opt += ' --disable-gui'
429
430     if options['variant'] is not None:
431         opt += ' --variant=%s' % options['variant']
432
433     # Build Windows debug versions with static linking as I think gdb works better then
434     if target.debug and target.platform == 'windows':
435         opt += ' --static-dcpomatic'
436
437     return opt
438
439 def build(target, options):
440     if target.platform == 'flatpak':
441         target.checkout_dependencies()
442         prefix = 'https://dcpomatic.com/deps'
443         modules = []
444         modules.append({'name': 'libzip',
445                         'buildsystem': 'cmake',
446                         'sources': [{'type': 'archive',
447                                      'url': '%s/libzip-1.4.0.tar.xz' % prefix,
448                                      'sha256': 'e508aba025f5f94b267d5120fc33761bcd98440ebe49dbfe2ed3df3afeacc7b1'}]})
449         modules.append({'name': 'libsigc++',
450                         'sources': [{'type': 'archive',
451                                      'url': '%s/libsigc++-2.10.0.tar.xz' % prefix,
452                                      'sha256': 'f843d6346260bfcb4426259e314512b99e296e8ca241d771d21ac64f28298d81'}]})
453         modules.append({'name': 'glibmm',
454                         'sources': [{'type': 'archive',
455                                      'url': '%s/glibmm-2.48.1.tar.xz' % prefix,
456                                      'sha256': 'dc225f7d2f466479766332483ea78f82dc349d59399d30c00de50e5073157cdf'}]})
457         modules.append({'name': 'cairomm',
458                         'sources': [{'type': 'archive',
459                                      'url': '%s/cairomm-1.12.2.tar.gz' % prefix,
460                                      'sha256': '45c47fd4d0aa77464a75cdca011143fea3ef795c4753f6e860057da5fb8bd599'}]})
461         modules.append({'name': 'pangomm',
462                         'sources': [{'type': 'archive',
463                                      'url': '%s/pangomm-2.40.1.tar.xz' % prefix,
464                                      'sha256': '9762ee2a2d5781be6797448d4dd2383ce14907159b30bc12bf6b08e7227be3af'}]})
465         modules.append({'name': 'libxml++',
466                         'sources': [{'type': 'archive',
467                                      'url': '%s/libxml++-2.40.1.tar.xz' % prefix,
468                                      'sha256': '4ad4abdd3258874f61c2e2a41d08e9930677976d303653cd1670d3e9f35463e9'}]})
469         modules.append({'name': 'xmlsec1',
470                         'sources': [{'type': 'archive',
471                                      'url': '%s/xmlsec1-1.2.25.tar.gz' % prefix,
472                                      'sha256': '967ca83edf25ccb5b48a3c4a09ad3405a63365576503bf34290a42de1b92fcd2'}]}) 
473         modules.append({'name': 'openjpeg2',
474                         'buildsystem': 'cmake',
475                         'sources': [{'type': 'dir', 'path': os.path.abspath('../openjpeg2-cdist')}]})
476         modules.append({'name': 'boost',
477                         'buildsystem': 'simple',
478                         'build-commands': [
479                             './bootstrap.sh --prefix=/app',
480                             './b2 install'
481                         ],
482                         'sources': [{'type': 'archive',
483                                      'url': '%s/boost_1_66_0.tar.bz2' % prefix,
484                                      'sha256': '5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9'}]})
485         modules.append({'name': 'asdcplib',
486                         'buildsystem': 'simple',
487                         'build-commands': [
488                             './waf configure --prefix=/app  --libdir=/app/lib build install'
489                         ],
490                         'sources': [{'type': 'dir', 'path': os.path.abspath('../asdcplib-cth')}]})
491         modules.append({'name': 'locked_sstream',
492                         'buildsystem': 'simple',
493                         'build-commands': [
494                             './waf configure --prefix=/app build install'
495                         ],
496                         'sources': [{'type': 'dir', 'path': os.path.abspath('../locked_sstream')}]})
497         modules.append({'name': 'libcxml',
498                         'buildsystem': 'simple',
499                         'build-commands': [
500                             './waf configure --prefix=/app  --libdir=/app/lib build install'
501                         ],
502                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libcxml')}]})
503         modules.append({'name': 'libdcp',
504                         'buildsystem': 'simple',
505                         'build-commands': [
506                             './waf configure --prefix=/app --libdir=/app/lib build install'
507                         ],
508                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libdcp')}]})
509         modules.append({'name': 'libsub',
510                         'buildsystem': 'simple',
511                         'build-commands': [
512                             './waf configure --prefix=/app --libdir=/app/lib build install'
513                         ],
514                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libsub')}]})
515         modules.append({'name': 'rtaudio',
516                         'build-options': {
517                             'config-opts': [
518                                 '--prefix=/app',
519                                 '--with-pulse',
520                                 '--with-alsa'
521                             ]
522                         },
523                         'sources': [{'type': 'dir', 'path': os.path.abspath('../rtaudio-cdist')}]})
524         modules.append({'name': 'wxwidgets',
525                         'sources': [{'type': 'archive',
526                                      'url': '%s/wxWidgets-3.0.3.tar.bz2' % prefix,
527                                      'sha256': '08c8033f48ec1b23520f036cde37b5ae925a6a65f137ded665633ca159b9307b'}]})
528         modules.append({'name': 'libssh',
529                         'buildsystem': 'cmake',
530                         'builddir': True,
531                         'sources': [{'type': 'archive',
532                                      'url': '%s/libssh-0.7.5.tar.xz' % prefix,
533                                      'sha256': '54e86dd5dc20e5367e58f3caab337ce37675f863f80df85b6b1614966a337095'}]})
534         modules.append({'name': 'dcpomatic',
535                         'buildsystem': 'simple',
536                         'build-commands': [
537                             './waf configure --prefix=/app build install'
538                         ],
539                         'build-options': {
540                             'build-args': ['--share=network']
541                         },
542                         'sources': [{'type': 'dir', 'path': os.path.abspath('.')}]})
543         desc = {'app-id': 'com.dcpomatic.DCP-o-matic',
544                 'runtime': 'org.gnome.Sdk',
545                 'runtime-version': '3.26',
546                 'sdk': 'org.gnome.Sdk',
547                 'command': 'dcpomatic2',
548                 'finish-args': ['--socket=x11', '--share=ipc', '--share=network', '--socket=pulseaudio', '--filesystem=host'],
549                 'modules': modules}
550         os.makedirs('build/platform')
551         with open('build/com.dcpomatic.DCP-o-matic.json', 'w') as outfile:
552             json.dump(desc, outfile)
553         target.command('%s --repo=build/platform/repo build/platform/flatpak build/com.dcpomatic.DCP-o-matic.json' % target.flatpak_builder())
554     else:
555         target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target, options)))
556         target.command('./waf')
557
558         if target.platform == 'linux' or target.platform == 'osx':
559             target.command('./waf install')
560
561 def package_windows(target):
562     identifier = ''
563     if target.version is not None:
564         identifier = '%s.' % target.version
565     identifier += '%d' % target.bits
566     shutil.copyfile('build/platform/windows/installer.%s.nsi' % identifier, 'build/platform/windows/installer2.%s.nsi' % identifier)
567     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
568     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
569     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, identifier))
570     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, identifier))
571     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.environment_prefix, identifier))
572     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
573     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % identifier)
574     target.command('makensis build/platform/windows/installer2.%s.nsi' % identifier)
575     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
576
577 def package_debian(target, cpu, version, options):
578     make_control(target.version, target.bits, 'debian/control', target.debug, options['gui'])
579     target.command('./waf dist')
580     f = open('debian/files', 'w')
581     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
582     shutil.rmtree('build/deb', ignore_errors=True)
583
584     os.makedirs('build/deb')
585     os.chdir('build/deb')
586     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
587     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
588     os.chdir('dcpomatic-%s' % version)
589     target.set('EMAIL', 'carl@dcpomatic.com')
590     target.command('dch -b -v %s-1 "New upstream release."' % version)
591     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
592     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
593     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
594
595     target.set('CDIST_CONFIGURE', '"' + configure_options(target, options) + '"')
596     if target.debug:
597         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
598     if target.version in ['7', '14.04']:
599         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
600     else:
601         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
602
603     target.command('dpkg-buildpackage -uc -us')
604
605     debs = []
606     for p in glob.glob('../*.deb'):
607         debs.append(os.path.abspath(p))
608
609     return debs
610
611 def package_rpm(target, cpu, version, options):
612     topdir = os.path.realpath('build/rpmbuild')
613     os.makedirs('%s/BUILD' % topdir)
614     os.makedirs('%s/RPMS' % topdir)
615     os.makedirs('%s/SOURCES' % topdir)
616     os.makedirs('%s/SPECS' % topdir)
617     os.makedirs('%s/SRPMS' % topdir)
618
619     target.command('./waf dist')
620     shutil.copyfile(
621         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
622         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
623         )
624
625     requires = None
626     if target.distro == 'mageia':
627         requires = "lib64xmlsec1-devel"
628
629     make_spec('build/platform/linux/dcpomatic2.spec', version, target, options, requires)
630     cmd = 'rpmbuild --define "_topdir %s" -bb build/platform/linux/dcpomatic2.spec' % topdir
631     target.command(cmd)
632     rpms = []
633
634     if cpu == "amd64":
635         cpu = "x86_64"
636     else:
637         cpu = "i686"
638
639     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
640         rpms.append(os.path.abspath(p))
641
642     return rpms
643
644 def make_appimage(target, nice_name, internal_name, version):
645     nice_filename = nice_name.replace(' ', '_')
646     os.makedirs('build/%s.AppDir/usr/bin' % nice_filename)
647     target.command('cp %s/bin/%s build/%s.AppDir/usr/bin' % (target.directory, internal_name, nice_filename))
648     with open('build/%s.AppDir/AppRun' % nice_filename, 'w') as f:
649         print('#!/bin/bash', file=f)
650         print('export APPDIR="$(dirname "$(readlink -f "$0")")"', file=f)
651         print('export PATH=$APPDIR/usr/bin:$PATH', file=f)
652         print('export XDG_DATA_DIRS="$APPDIR/usr/share/:/usr/share/:$XDG_DATA_DIRS"', file=f)
653         print('"$APPDIR"/usr/bin/%s $@' % internal_name, file=f)
654     target.command('chmod a+rx build/%s.AppDir/AppRun' % nice_filename)
655     with open('build/%s.AppDir/%s.desktop' % (nice_filename, internal_name), 'w') as f:
656         print('[Desktop Entry]', file=f)
657         print('Type=Application', file=f)
658         print('Categories=AudioVideo;', file=f)
659         print('Name=%s' % nice_name, file=f)
660         print('Icon=%s' % internal_name, file=f)
661     target.command('cp graphics/linux/256/%s.png build/%s.AppDir' % (internal_name, nice_filename))
662     target.command('linuxdeploy-x86_64.AppImage --appdir build/%s.AppDir' % nice_filename)
663     target.command('appimagetool-x86_64.AppImage build/%s.AppDir' % nice_filename)
664     target.command('mv %s-x86_64.AppImage build/%s-%s-x86_64.AppImage' % (nice_filename, nice_filename, version))
665     return os.path.abspath('build/%s-%s-x86_64.AppImage' % (nice_filename, version))
666
667 def package(target, version, options):
668     """version: DCP-o-matic version string"""
669     if target.platform == 'windows':
670         return package_windows(target)
671     elif target.platform == 'linux':
672         if target.detail == 'appimage':
673             out = []
674             out.append(make_appimage(target, 'DCP-o-matic', 'dcpomatic2', version))
675             out.append(make_appimage(target, 'DCP-o-matic Player', 'dcpomatic2_player', version))
676             out.append(make_appimage(target, 'DCP-o-matic Playlist Editor', 'dcpomatic2_playlist', version))
677             out.append(make_appimage(target, 'DCP-o-matic KDM Creator', 'dcpomatic2_kdm', version))
678             out.append(make_appimage(target, 'DCP-o-matic Batch Converter', 'dcpomatic2_batch', version))
679             out.append(make_appimage(target, 'DCP-o-matic Encode Server', 'dcpomatic2_server', version))
680             return out
681         else:
682             if target.bits == 32:
683                 cpu = 'i386'
684             else:
685                 cpu = 'amd64'
686
687             if target.distro == 'debian' or target.distro == 'ubuntu':
688                 return package_debian(target, cpu, version, options)
689             elif target.distro == 'centos' or target.distro == 'fedora' or target.distro == 'mageia':
690                 return package_rpm(target, cpu, version, options)
691     elif target.platform == 'osx' and target.bits is None:
692         target.command('bash platform/osx/make_dmg.sh %s %s universal %s %s' % (target.environment_prefix, target.directory, target.apple_id, target.apple_password))
693         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
694     elif target.platform == 'osx' and target.bits == 64:
695         target.command('bash platform/osx/make_dmg.sh %s %s thin %s %s' % (target.environment_prefix, target.directory, target.apple_id, target.apple_password))
696         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
697     elif target.platform == 'docker':
698         shutil.copyfile(target.deb, 'build/platform/docker')
699         f = open('build/platform/docker/Dockerfile', 'w')
700         print('FROM debian:jessie', file=f)
701         print('MAINTAINER carl@dcpomatic.com', file=f)
702         print('ADD build/platform/docker/dcpomatic_%s-1_amd64.deb /tmp' % (version, version), file=f)
703         print('RUN apt-get -o Acquire:http::Timeout="5" update; exit 0', file=f)
704         print('RUN dpkg -i /tmp/dcpomatic_*.deb; exit 0', file=f)
705         print('RUN apt-get -y -f install', file=f)
706         print('RUN apt-get clean', file=f)
707         print('EXPOSE 6192', file=f)
708         print('CMD ["/usr/bin/dcpomatic2_server_cli", "--verbose"]', file=f)
709         f.close()
710         target.command('docker build build/platform/docker -t dcpomatic-server:%s' % version)
711         target.command('docker save dcpomatic-server:%s -o dcpomatic-server-%s-docker.tar' % (version, version))
712     elif target.platform == 'flatpak':
713         target.command('%s build-bundle build/platform/repo build/dcpomatic_%s.flatpak com.dcpomatic.DCP-o-matic' % (target.flatpak(), version))
714         return os.path.abspath('build/dcpomatic_%s.flatpak' % version)
715
716 def make_pot(target):
717     target.command('./waf pot')
718     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
719             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
720             os.path.abspath('build/src/tools/dcpomatic.pot')]
721
722 def make_manual(target):
723     os.chdir('doc/manual')
724     target.command('make')
725     target.command('pdflatex colour.tex')
726     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
727
728 def test(target, test):
729     if target.platform != 'windows':
730         target.set('LC_ALL', 'C')
731         cmd = 'run/tests '
732         if target.debug:
733             cmd += '--backtrace '
734         if test is not None:
735             cmd += '--run_test=%s' % test
736         target.command(cmd)