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