Add "build" environment lib to local run script.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2022 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 datetime
23 import glob
24 import shutil
25 import os
26 import copy
27 import json
28
29 def dmg_prefix(variant):
30     return 'DCP-o-matic'
31
32 def debian_name(variant):
33     return 'dcpomatic'
34
35 deb_build_depends = dict()
36
37 deb_build_depends_base = ['debhelper', 'g++', 'pkg-config', 'libsndfile1-dev', 'libgtk2.0-dev', 'libx264-dev']
38
39 for v in ['16.04', '18.04', '20.04']:
40     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
41     deb_build_depends[v].extend(['libssh-dev', 'python'])
42 for v in ['22.04']:
43     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
44     deb_build_depends[v].extend(['libssh-dev', 'python3.10'])
45 for v in ['23.04', '23.10']:
46     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
47     deb_build_depends[v].extend(['libssh-dev', 'python3.11'])
48 for v in ['24.04']:
49     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
50     deb_build_depends[v].extend(['libssh-dev', 'python3.12'])
51 for v in ['9', '10']:
52     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
53     deb_build_depends[v].extend(['libssh-gcrypt-dev', 'python'])
54 for v in ['11']:
55     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
56     deb_build_depends[v].extend(['libssh-gcrypt-dev', 'python3.9'])
57 for v in ['12']:
58     deb_build_depends[v] = copy.deepcopy(deb_build_depends_base)
59     deb_build_depends[v].extend(['libssh-gcrypt-dev', 'python3.11'])
60 deb_build_depends['unstable'] = copy.deepcopy(deb_build_depends_base)
61 deb_build_depends['unstable'].extend(['python3'])
62
63 deb_depends = dict()
64 deb_depends_gui = dict()
65
66 deb_depends_base = ['libc6', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libgtk2.0-0']
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                              'libxml++2.6-2v5',
73                              'libboost-date-time1.58.0',
74                              'libzip4',
75                              'libcairomm-1.0-1v5',
76                              'libpangomm-1.4-1v5',
77                              'libicu55',
78                              'libnettle6',
79                              'libssh-4',
80                              'libx264-148',
81                              'libcurl3',
82                              'libxerces-c3.1'])
83
84 deb_depends['18.04'] = copy.deepcopy(deb_depends_base)
85 deb_depends['18.04'].extend(['libboost-filesystem1.65.1',
86                              'libboost-thread1.65.1',
87                              'libboost-regex1.65.1',
88                              'libboost-date-time1.65.1',
89                              'libcairomm-1.0-1v5',
90                              'libpangomm-1.4-1v5',
91                              'libxml++2.6-2v5',
92                              'libzip4',
93                              'libicu60',
94                              'libnettle6',
95                              'libssh-4',
96                              'libx264-152',
97                              'libcurl4',
98                              'libpulse0',
99                              'libxerces-c3.2',
100                              'libnanomsg4'])
101
102 deb_depends['20.04'] = copy.deepcopy(deb_depends_base)
103 deb_depends['20.04'].extend(['libboost-filesystem1.71.0',
104                              'libboost-thread1.71.0',
105                              'libboost-regex1.71.0',
106                              'libboost-date-time1.71.0',
107                              'libcairomm-1.0-1v5',
108                              'libpangomm-1.4-1v5',
109                              'libxml++2.6-2v5',
110                              'libzip5',
111                              'libicu66',
112                              'libnettle7',
113                              'libssh-4',
114                              'libx264-155',
115                              'libcurl4',
116                              'libpulse0',
117                              'libxerces-c3.2',
118                              'libnanomsg5'])
119
120 deb_depends['21.10'] = copy.deepcopy(deb_depends_base)
121 deb_depends['21.10'].extend(['libboost-filesystem1.74.0',
122                              'libboost-thread1.74.0',
123                              'libboost-regex1.74.0',
124                              'libboost-date-time1.74.0',
125                              'libcairomm-1.0-1v5',
126                              'libpangomm-1.4-1v5',
127                              'libxml++2.6-2v5',
128                              'libzip4',
129                              'libicu67',
130                              'libnettle8',
131                              'libssh-4',
132                              'libx264-160',
133                              'libcurl4',
134                              'libpulse0',
135                              'libxerces-c3.2',
136                              'libnanomsg5',
137                              'libdav1d4'])
138
139 deb_depends['22.04'] = copy.deepcopy(deb_depends_base)
140 deb_depends['22.04'].extend(['libboost-filesystem1.74.0',
141                              'libboost-thread1.74.0',
142                              'libboost-regex1.74.0',
143                              'libboost-date-time1.74.0',
144                              'libcairomm-1.0-1v5',
145                              'libpangomm-1.4-1v5',
146                              'libxml++2.6-2v5',
147                              'libzip4',
148                              'libicu70',
149                              'libnettle8',
150                              'libssh-4',
151                              'libx264-163',
152                              'libcurl4',
153                              'libpulse0',
154                              'libxerces-c3.2',
155                              'libnanomsg5',
156                              'libdav1d5'])
157
158 deb_depends['23.04'] = copy.deepcopy(deb_depends_base)
159 deb_depends['23.04'].extend(['libboost-filesystem1.74.0',
160                              'libboost-thread1.74.0',
161                              'libboost-regex1.74.0',
162                              'libboost-date-time1.74.0',
163                              'libcairomm-1.0-1v5',
164                              'libpangomm-1.4-1v5',
165                              'libxml++2.6-2v5',
166                              'libzip4',
167                              'libicu72',
168                              'libnettle8',
169                              'libssh-4',
170                              'libx264-164',
171                              'libcurl4',
172                              'libpulse0',
173                              'libxerces-c3.2',
174                              'libnanomsg5',
175                              'libwxgtk3.2-1',
176                              'libwxgtk-gl3.2-1'])
177
178 deb_depends['23.10'] = copy.deepcopy(deb_depends_base)
179 deb_depends['23.10'].extend(['libboost-filesystem1.74.0',
180                              'libboost-thread1.74.0',
181                              'libboost-regex1.74.0',
182                              'libboost-date-time1.74.0',
183                              'libcairomm-1.0-1v5',
184                              'libpangomm-1.4-1v5',
185                              'libxml++2.6-2v5',
186                              'libzip4',
187                              'libicu72',
188                              'libnettle8',
189                              'libssh-4',
190                              'libx264-164',
191                              'libcurl4',
192                              'libpulse0',
193                              'libxerces-c3.2',
194                              'libnanomsg5',
195                              'libwxgtk3.2-1',
196                              'libwxgtk-gl3.2-1'])
197
198 def debs(boost, icu, x264):
199     output = copy.deepcopy(deb_depends_base)
200     output.extend(['libboost-filesystem' + boost,
201                    'libboost-thread' + boost,
202                    'libboost-regex' + boost,
203                    'libboost-date-time' + boost,
204                    'libcairomm-1.0-1v5',
205                    'libpangomm-1.4-1v5',
206                    'libxml++2.6-2v5',
207                    'libzip4',
208                    'libicu' + icu,
209                    'libnettle8',
210                    'libssh-4',
211                    'libx264-' + x264,
212                    'libcurl4',
213                    'libpulse0',
214                    'libxerces-c3.2',
215                    'libnanomsg5',
216                    'libwxgtk3.2-1',
217                    'libwxgtk-gl3.2-1'])
218     return output
219
220 deb_depends['24.04'] = debs(boost='1.83.0', icu='74', x264='164')
221
222 deb_depends['9'] = copy.deepcopy(deb_depends_base)
223 deb_depends['9'].extend(['libboost-filesystem1.62.0',
224                          'libboost-thread1.62.0',
225                          'libboost-regex1.62.0',
226                          'libboost-date-time1.62.0',
227                          'libxml++2.6-2v5',
228                          'libgtk2.0-0',
229                          'libzip4',
230                          'libcairomm-1.0-1v5',
231                          'libpangomm-1.4-1v5',
232                          'libicu57',
233                          'libssh-4',
234                          'libssh-gcrypt-4',
235                          'libnettle6',
236                          'libx264-148',
237                          'libcurl3',
238                          'libxerces-c3.1'])
239
240 deb_depends_gui['9'] = [ 'libxcb-xfixes0',
241                          'libxcb-shape0',
242                          'libasound2',
243                          'libpulse0' ]
244
245 deb_depends['10'] = copy.deepcopy(deb_depends_base)
246 deb_depends['10'].extend(['libboost-filesystem1.67.0',
247                           'libboost-thread1.67.0',
248                           'libboost-regex1.67.0',
249                           'libboost-date-time1.67.0',
250                           'libxml++2.6-2v5',
251                           'libgtk2.0-0',
252                           'libzip4',
253                           'libcairomm-1.0-1v5',
254                           'libpangomm-1.4-1v5',
255                           'libicu63',
256                           'libssh-4',
257                           'libssh-gcrypt-4',
258                           'libnettle6',
259                           'libx264-155',
260                           'libcurl4',
261                           'libxerces-c3.2',
262                           'libnanomsg5'])
263
264 deb_depends_gui['10'] = [ 'libxcb-xfixes0',
265                           'libxcb-shape0',
266                           'libasound2',
267                           'libpulse0' ]
268
269 deb_depends['11'] = copy.deepcopy(deb_depends_base)
270 deb_depends['11'].extend(['libboost-filesystem1.74.0',
271                           'libboost-thread1.74.0',
272                           'libboost-regex1.74.0',
273                           'libboost-date-time1.74.0',
274                           'libxml++2.6-2v5',
275                           'libzip4',
276                           'libcairomm-1.0-1v5',
277                           'libpangomm-1.4-1v5',
278                           'libicu67',
279                           'libssh-4',
280                           'libssh-gcrypt-4',
281                           'libnettle8',
282                           'libx264-160',
283                           'libcurl4',
284                           'libxerces-c3.2',
285                           'libnanomsg5',
286                           'libdav1d4'])
287
288 deb_depends_gui['11'] = [ 'libxcb-xfixes0',
289                           'libxcb-shape0',
290                           'libasound2',
291                           'libpulse0' ]
292
293 deb_depends['12'] = copy.deepcopy(deb_depends_base)
294 deb_depends['12'].extend(['libboost-filesystem1.74.0',
295                           'libboost-thread1.74.0',
296                           'libboost-regex1.74.0',
297                           'libboost-date-time1.74.0',
298                           'libxml++2.6-2v5',
299                           'libzip4',
300                           'libcairomm-1.0-1v5',
301                           'libpangomm-1.4-1v5',
302                           'libicu72',
303                           'libssh-4',
304                           'libssh-gcrypt-4',
305                           'libnettle8',
306                           'libx264-164',
307                           'libcurl4',
308                           'libxerces-c3.2',
309                           'libnanomsg5'])
310
311 deb_depends_gui['12'] = [ 'libxcb-xfixes0',
312                           'libxcb-shape0',
313                           'libasound2',
314                           'libpulse0' ]
315
316 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
317 deb_depends['unstable'].extend(['libboost-filesystem1.67.0',
318                                 'libboost-thread1.67.0',
319                                 'libboost-regex1.67.0',
320                                 'libboost-date-time1.67.0',
321                                 'libxml++2.6-2v5',
322                                 'libgtk2.0-0',
323                                 'libzip4',
324                                 'libicu63',
325                                 'libnettle6',
326                                 'libx264-155',
327                                 'libcurl4',
328                                 'libxerces-c3.2',
329                                 'libdav1d4'])
330
331 def can_build_disk(target):
332     # We can build dcpomatic2_disk on platforms that have Boost process and can build the lwext4
333     # library.  For now, just whitelist good ones here.
334     #
335     # - Lots of Linux distros (including Ubuntu 16.04) don't have a new enough boost (1.64 or above)
336     # - On Centos 6 we can't build lwext4 because it needs a new CMake which Centos 6's g++ is not new enough to build.
337     # - On Centos 7 there is a build error in lwext4 related to __unused
338     if target.platform == 'windows':
339         return True
340     if target.platform == 'osx':
341         return True
342     if target.platform == 'linux':
343         if target.distro == 'ubuntu' and target.version != '16.04':
344             return True
345         if target.distro == 'debian' and target.version != '9':
346             return True
347         if target.detail == 'appimage':
348             return True 
349         if target.distro == 'fedora' and int(target.version) >= 31:
350             return True
351         if target.distro == 'centos' and target.version != '7':
352             return True
353         if target.distro == 'mageia':
354             return True
355     return False
356
357 def packages(name, packages, f):
358     s = '%s: ' % name
359     for p in packages:
360         s += str(p) + ', '
361     print(s[:-2], file=f)
362
363 def make_control(debian_version, bits, filename, debug, gui, name):
364     f = open(filename, 'w')
365     print(f'Source: {name}', file=f)
366     print('Section: video', file=f)
367     print('Priority: extra', file=f)
368     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
369     packages('Build-Depends', deb_build_depends[debian_version], f)
370     print('Standards-Version: 3.9.3', file=f)
371     print('Homepage: https://dcpomatic.com/', file=f)
372     print('', file=f)
373     suffix = '' if gui else '-cli'
374     print(f'Package: {name}{suffix}', file=f)
375     if gui:
376         print(f'Replaces: {name}-cli', file=f)
377     if bits == 32:
378         print('Architecture: i386', file=f)
379     else:
380         print('Architecture: amd64', file=f)
381
382     pkg = deb_depends[debian_version]
383     if gui and debian_version in deb_depends_gui:
384         pkg.extend(deb_depends_gui[debian_version])
385
386     packages('Depends', pkg, f)
387
388     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
389     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from videos, images,', file=f)
390     print('  sound and subtitle files.  You can use it to make content for playback on DCI-compliant', file=f)
391     print('  cinema projectors.', file=f)
392     if not gui:
393         print('  This package contains the command-line tools only.', file=f)
394
395     if debug:
396         print('', file=f)
397         print(f'Package: {name}{suffix}-dbg', file=f)
398         if bits == 32:
399             print('Architecture: i386', file=f)
400         else:
401             print('Architecture: amd64', file=f)
402         print('Section: debug', file=f)
403         print('Priority: extra', file=f)
404         packages('Depends', pkg, f)
405         print(f'Description: debugging symbols for {name}', file=f)
406         print(f'  This package contains the debugging symbols for {name}.', file=f)
407         print('', file=f)
408
409 def make_spec(filename, version, target, options, requires=None):
410     """Make a .spec file for a RPM build"""
411     f = open(filename, 'w')
412     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
413     print('Name:dcpomatic2', file=f)
414     print('Version:%s' % version, file=f)
415     print('Release:1%{?dist}', file=f)
416     print('License:GPL', file=f)
417     print('Group:Applications/Multimedia', file=f)
418     print('URL:https://dcpomatic.com/', file=f)
419     if requires is not None:
420         print('Requires:%s' % requires, file=f)
421     print('', file=f)
422     print('%description', file=f)
423     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
424     print('files for presentation on DCI-compliant digital projectors.', file=f)
425     print('', file=f)
426     print('%files', file=f)
427     print('%{_bindir}/dcpomatic2', file=f)
428     print('%{_bindir}/dcpomatic2_batch', file=f)
429     print('%{_bindir}/dcpomatic2_cli', file=f)
430     print('%{_bindir}/dcpomatic2_create', file=f)
431     print('%{_bindir}/dcpomatic2_editor', file=f)
432     print('%{_bindir}/dcpomatic2_kdm', file=f)
433     print('%{_bindir}/dcpomatic2_server', file=f)
434     print('%{_bindir}/dcpomatic2_server_cli', file=f)
435     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
436     print('%{_bindir}/dcpomatic2_player', file=f)
437     print('%{_bindir}/dcpomatic2_playlist', file=f)
438     print('%{_bindir}/dcpomatic2_openssl', file=f)
439     print('%{_bindir}/dcpomatic2_combiner', file=f)
440     print('%{_bindir}/dcpomatic2_verify_cli', file=f)
441     print('%{_bindir}/dcpomatic2_verifier', file=f)
442     print('%{_bindir}/dcpomatic2_kdm_inspect', file=f)
443     print('%{_bindir}/dcpomatic2_map', file=f)
444     if can_build_disk(target):
445         print('%{_bindir}/dcpomatic2_disk', file=f)
446         print('%caps(cap_dac_override=ep) %{_bindir}/dcpomatic2_disk_writer', file=f)
447     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
448     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
449     print('%{_datadir}/applications/dcpomatic2_editor.desktop', file=f)
450     print('%{_datadir}/applications/dcpomatic2_verifier.desktop', file=f)
451     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
452     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
453     print('%{_datadir}/applications/dcpomatic2_player.desktop', file=f)
454     print('%{_datadir}/applications/dcpomatic2_playlist.desktop', file=f)
455     print('%{_datadir}/applications/dcpomatic2_combiner.desktop', file=f)
456     if can_build_disk(target):
457         print('%{_datadir}/applications/dcpomatic2_disk.desktop', file=f)
458     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
459     print('%{_datadir}/dcpomatic2/select_white.png', file=f)
460     print('%{_datadir}/dcpomatic2/select_black.png', file=f)
461     print('%{_datadir}/dcpomatic2/sequence_white.png', file=f)
462     print('%{_datadir}/dcpomatic2/sequence_black.png', file=f)
463     print('%{_datadir}/dcpomatic2/snap_white.png', file=f)
464     print('%{_datadir}/dcpomatic2/snap_black.png', file=f)
465     print('%{_datadir}/dcpomatic2/zoom_white.png', file=f)
466     print('%{_datadir}/dcpomatic2/zoom_black.png', file=f)
467     print('%{_datadir}/dcpomatic2/zoom_all_white.png', file=f)
468     print('%{_datadir}/dcpomatic2/zoom_all_black.png', file=f)
469     print('%{_datadir}/dcpomatic2/link_black.png', file=f)
470     print('%{_datadir}/dcpomatic2/link_white.png', file=f)
471     print('%{_datadir}/dcpomatic2/me.jpg', file=f)
472     print('%{_datadir}/dcpomatic2/add_black.png', file=f)
473     print('%{_datadir}/dcpomatic2/add_white.png', file=f)
474     print('%{_datadir}/dcpomatic2/pause_black.png', file=f)
475     print('%{_datadir}/dcpomatic2/pause_white.png', file=f)
476     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
477     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
478     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
479     print('%{_datadir}/dcpomatic2/splash.png', file=f)
480     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
481         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
482         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
483         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_editor.png' % r, file=f)
484         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_verifier.png' % r, file=f)
485         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
486         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
487         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_player.png' % r, file=f)
488         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_playlist.png' % r, file=f)
489         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_disk.png' % r, file=f)
490         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_combiner.png' % r, file=f)
491     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL', 'ru_RU', 'pl_PL', 'da_DK',
492               'pt_PT', 'pt_BR', 'sk_SK', 'cs_CZ', 'uk_UA', 'zh_CN', 'tr_TR', 'sl_SI', 'hu_HU',
493               'ka_KA', 'fa_IR']:
494         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
495         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
496         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
497     print('%{_datadir}/libdcp/tags/*', file=f)
498     print('%{_datadir}/libdcp/xsd/*', file=f)
499     print('%{_datadir}/libdcp/ratings', file=f)
500     print('%{_datadir}/polkit-1/actions/com.dcpomatic.write-drive.policy', file=f)
501     print('', file=f)
502     print('%prep', file=f)
503     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
504     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
505     print('%build', file=f)
506     print('cd dcpomatic-%s' % version, file=f)
507     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)
508     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%%{buildroot}/usr --destdir=/usr %s' %
509           (target.directory, target.directory, configure_options(target, options, for_package=True)), file=f)
510     print('./waf', file=f)
511     print('%install', file=f)
512     print('cd dcpomatic-%s' % version, file=f)
513     print('./waf install', file=f)
514     print('/bin/cp %s/src/openssl/apps/openssl %%{buildroot}/usr/bin/dcpomatic2_openssl' % target.directory, file=f)
515     print('/bin/mkdir -p %{buildroot}/usr/share/libdcp', file=f)
516     print('/bin/cp -r %s/src/libdcp/tags %%{buildroot}/usr/share/libdcp' % target.directory, file=f)
517     print('/bin/cp -r %s/src/libdcp/xsd %%{buildroot}/usr/share/libdcp' % target.directory, file=f)
518     print('/bin/cp %s/src/libdcp/ratings %%{buildroot}/usr/share/libdcp' % target.directory, file=f)
519     print('/bin/mv %s/bin/dcpverify %%{buildroot}/usr/bin/dcpomatic2_verify_cli' % target.directory, file=f)
520     print('/bin/mv %s/bin/dcpkdm %%{buildroot}/usr/bin/dcpomatic2_kdm_inspect' % target.directory, file=f)
521     print('', file=f)
522     print('%post', file=f)
523     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
524     print('setcap "cap_dac_override+ep cap_sys_admin+ep" /usr/bin/dcpomatic2_disk_writer', file=f)
525     print('', file=f)
526     print('%postun', file=f)
527     print('if [ $1 -eq 0 ] ; then', file=f)
528     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
529     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
530     print('fi', file=f)
531     print('', file=f)
532     print('%posttrans', file=f)
533     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
534
535 def dependencies(target, options):
536
537     if target.platform == 'linux':
538         ffmpeg_options = { 'shared': False }
539     else:
540         ffmpeg_options = {}
541
542     if target.platform != 'linux' or target.distro != 'arch':
543         deps = [('ffmpeg', '0b73d2f5e70a04a67aa902902c42e3025ef3bb77', ffmpeg_options)]
544     else:
545         # Use distro-provided FFmpeg on Arch
546         deps = []
547
548     deps.append(('libdcp', '816365d20e0c6ef37b6bf499a42a0d3ecad22c05', {'c++17': target.platform == 'osx'}))
549     deps.append(('libsub', 'v1.6.47'))
550     deps.append(('leqm-nrt', '30dcaea1373ac62fba050e02ce5b0c1085797a23'))
551     deps.append(('rtaudio', 'f619b76'))
552     # We get our OpenSSL libraries from the environment, but we
553     # also need a patched openssl binary to make certificates.
554     # This dependency is to get that binary, which is added into
555     # the appropriate place later
556     deps.append(('openssl', '54298369cacfe0ae01c5aa42ace8a463fd2e7a2e'))
557     if can_build_disk(target):
558         deps.append(('lwext4', 'ab082923a791b58478d1d9939d65a0583566ac1f'))
559     deps.append(('ffcmp', '5ab6ed3b75d8ca7cf1f66bb9fb08792b92f4b419'))
560
561     return deps
562
563 option_defaults = { "gui": True, "variant": None }
564
565 def configure_options(target, options, for_package=False):
566     opt = ' --warnings-are-errors'
567
568     if for_package or not (
569             (target.platform == 'linux' and target.distro == 'ubuntu' and target.version in ['18.04', '22.04']) or
570             (target.platform == 'osx') or
571             (target.platform == 'windows')
572         ):
573         # Currently we only build tests on macOS, Windows, and some Ubuntu versions
574         opt += ' --disable-tests'
575
576     if target.debug:
577         opt += ' --enable-debug'
578     if target.platform == 'windows':
579         opt += f' --target-windows-{target.bits}'
580     elif target.platform == 'linux':
581         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
582         if target.distro == 'centos':
583             if target.version == '6.5':
584                 opt += ' --static-boost --static-xmlpp'
585             elif target.version == '7':
586                 opt += ' --workaround-gssapi'
587
588     if not options['gui']:
589         opt += ' --disable-gui'
590
591     if options['variant']:
592         opt += ' --variant=%s' % options['variant']
593
594     # Build Windows debug versions with static linking as I think gdb works better then
595     if target.debug and target.platform == 'windows':
596         opt += ' --static-dcpomatic'
597
598     if can_build_disk(target):
599         opt += ' --enable-disk'
600
601     if target.platform == 'osx':
602         opt += ' --c++17'
603         if target.arch == 'arm64':
604             opt += ' --wx-config=%s/wx-config' % target.bin
605
606     if target.platform == 'linux' and target.distro == 'ubuntu' and target.version in ['22.04']:
607         opt += ' --enable-grok'
608
609     return opt
610
611 def build(target, options, for_package):
612     if target.platform == 'flatpak':
613         target.checkout_dependencies()
614         prefix = 'https://dcpomatic.com/deps'
615         modules = []
616         modules.append({'name': 'libzip',
617                         'buildsystem': 'cmake',
618                         'sources': [{'type': 'archive',
619                                      'url': '%s/libzip-1.4.0.tar.xz' % prefix,
620                                      'sha256': 'e508aba025f5f94b267d5120fc33761bcd98440ebe49dbfe2ed3df3afeacc7b1'}]})
621         modules.append({'name': 'libsigc++',
622                         'sources': [{'type': 'archive',
623                                      'url': '%s/libsigc++-2.10.0.tar.xz' % prefix,
624                                      'sha256': 'f843d6346260bfcb4426259e314512b99e296e8ca241d771d21ac64f28298d81'}]})
625         modules.append({'name': 'glibmm',
626                         'sources': [{'type': 'archive',
627                                      'url': '%s/glibmm-2.48.1.tar.xz' % prefix,
628                                      'sha256': 'dc225f7d2f466479766332483ea78f82dc349d59399d30c00de50e5073157cdf'}]})
629         modules.append({'name': 'cairomm',
630                         'sources': [{'type': 'archive',
631                                      'url': '%s/cairomm-1.12.2.tar.gz' % prefix,
632                                      'sha256': '45c47fd4d0aa77464a75cdca011143fea3ef795c4753f6e860057da5fb8bd599'}]})
633         modules.append({'name': 'pangomm',
634                         'sources': [{'type': 'archive',
635                                      'url': '%s/pangomm-2.40.1.tar.xz' % prefix,
636                                      'sha256': '9762ee2a2d5781be6797448d4dd2383ce14907159b30bc12bf6b08e7227be3af'}]})
637         modules.append({'name': 'libxml++',
638                         'sources': [{'type': 'archive',
639                                      'url': '%s/libxml++-2.40.1.tar.xz' % prefix,
640                                      'sha256': '4ad4abdd3258874f61c2e2a41d08e9930677976d303653cd1670d3e9f35463e9'}]})
641         modules.append({'name': 'xmlsec1',
642                         'sources': [{'type': 'archive',
643                                      'url': '%s/xmlsec1-1.2.25.tar.gz' % prefix,
644                                      'sha256': '967ca83edf25ccb5b48a3c4a09ad3405a63365576503bf34290a42de1b92fcd2'}]})
645         modules.append({'name': 'openjpeg2',
646                         'buildsystem': 'cmake',
647                         'sources': [{'type': 'dir', 'path': os.path.abspath('../openjpeg2-cdist')}]})
648         modules.append({'name': 'boost',
649                         'buildsystem': 'simple',
650                         'build-commands': [
651                             './bootstrap.sh --prefix=/app',
652                             './b2 install'
653                         ],
654                         'sources': [{'type': 'archive',
655                                      'url': '%s/boost_1_66_0.tar.bz2' % prefix,
656                                      'sha256': '5721818253e6a0989583192f96782c4a98eb6204965316df9f5ad75819225ca9'}]})
657         modules.append({'name': 'asdcplib',
658                         'buildsystem': 'simple',
659                         'build-commands': [
660                             './waf configure --prefix=/app  --libdir=/app/lib build install'
661                         ],
662                         'sources': [{'type': 'dir', 'path': os.path.abspath('../asdcplib-carl')}]})
663         modules.append({'name': 'locked_sstream',
664                         'buildsystem': 'simple',
665                         'build-commands': [
666                             './waf configure --prefix=/app build install'
667                         ],
668                         'sources': [{'type': 'dir', 'path': os.path.abspath('../locked_sstream')}]})
669         modules.append({'name': 'libcxml',
670                         'buildsystem': 'simple',
671                         'build-commands': [
672                             './waf configure --prefix=/app  --libdir=/app/lib build install'
673                         ],
674                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libcxml')}]})
675         modules.append({'name': 'libdcp',
676                         'buildsystem': 'simple',
677                         'build-commands': [
678                             './waf configure --prefix=/app --libdir=/app/lib build install'
679                         ],
680                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libdcp')}]})
681         modules.append({'name': 'libsub',
682                         'buildsystem': 'simple',
683                         'build-commands': [
684                             './waf configure --prefix=/app --libdir=/app/lib build install'
685                         ],
686                         'sources': [{'type': 'dir', 'path': os.path.abspath('../libsub')}]})
687         modules.append({'name': 'rtaudio',
688                         'build-options': {
689                         'config-opts': [
690                             '--prefix=/app',
691                             '--with-pulse',
692                             '--with-alsa'
693                         ]
694                         },
695                         'sources': [{'type': 'dir', 'path': os.path.abspath('../rtaudio-cdist')}]})
696         modules.append({'name': 'wxwidgets',
697                         'sources': [{'type': 'archive',
698                                      'url': '%s/wxWidgets-3.0.3.tar.bz2' % prefix,
699                                      'sha256': '08c8033f48ec1b23520f036cde37b5ae925a6a65f137ded665633ca159b9307b'}]})
700         modules.append({'name': 'libssh',
701                         'buildsystem': 'cmake',
702                         'builddir': True,
703                         'sources': [{'type': 'archive',
704                                      'url': '%s/libssh-0.7.5.tar.xz' % prefix,
705                                      'sha256': '54e86dd5dc20e5367e58f3caab337ce37675f863f80df85b6b1614966a337095'}]})
706         modules.append({'name': 'dcpomatic',
707                         'buildsystem': 'simple',
708                         'build-commands': [
709                             './waf configure --prefix=/app build install'
710                          ],
711                         'build-options': {
712                            'build-args': ['--share=network']
713                         },
714                         'sources': [{'type': 'dir', 'path': os.path.abspath('.')}]})
715         desc = {'app-id': 'com.dcpomatic.DCP-o-matic',
716                 'runtime': 'org.gnome.Sdk',
717                 'runtime-version': '3.26',
718                 'sdk': 'org.gnome.Sdk',
719                 'command': 'dcpomatic2',
720                 'finish-args': ['--socket=x11', '--share=ipc', '--share=network', '--socket=pulseaudio', '--filesystem=host'],
721                 'modules': modules}
722         os.makedirs('build/platform')
723         with open('build/com.dcpomatic.DCP-o-matic.json', 'w') as outfile:
724             json.dump(desc, outfile)
725         target.command('%s --repo=build/platform/repo build/platform/flatpak build/com.dcpomatic.DCP-o-matic.json' % target.flatpak_builder())
726     elif target.platform != 'linux' or target.detail == 'appimage' or not for_package:
727         target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target, options, for_package)))
728         target.command('./waf')
729         target.command('./waf install')
730
731 def package_windows(target):
732     identifier = ''
733     if target.version is not None:
734         identifier = '%s.' % target.version
735     identifier += '%d' % target.bits
736     shutil.copyfile('build/platform/windows/installer.%s.nsi' % identifier, 'build/platform/windows/installer2.%s.nsi' % identifier)
737     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
738     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
739     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, identifier))
740     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, identifier))
741     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.environment_prefix, identifier))
742     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
743     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % identifier)
744     target.command('makensis build/platform/windows/installer2.%s.nsi' % identifier)
745     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
746
747 def package_debian(target, cpu, version, options):
748     name = debian_name(options['variant'])
749     make_control(target.version, target.bits, 'debian/control', target.debug, options['gui'], name)
750     if target.version != '9' and target.version != '16.04' and options['gui']:
751         with open('debian/postinst', 'w') as f:
752             print('#!/bin/sh', file=f)
753             # Get the required capability to write to disks
754             print('setcap "cap_dac_override+ep cap_sys_admin+ep" /usr/bin/dcpomatic2_disk_writer', file=f)
755     target.command('./waf dist')
756     f = open('debian/files', 'w')
757     suffix = '' if options['gui'] else '-cli'
758     print(f'{name}{suffix}_{version}-1_{cpu}.deb video extra', file=f)
759     shutil.rmtree('build/deb', ignore_errors=True)
760
761     os.makedirs('build/deb')
762     os.chdir('build/deb')
763     shutil.move(f'../../dcpomatic-{version}.tar.bz2', f'{name}_{version}.orig.tar.bz2')
764     target.command(f'tar xjf {name}_{version}.orig.tar.bz2')
765     os.chdir(f'dcpomatic-{version}')
766
767     with open('debian/changelog', 'w') as f:
768         print(f'{name} ({version}-1) unstable; urgency=medium', file=f)
769         print('', file=f)
770         print('  * New upstream release.', file=f)
771         print('', file=f)
772         print(f" -- Carl Hetherington <carl@dcpomatic.com>  {datetime.datetime.now().astimezone().strftime('%a, %d %b %Y %H:%M:%S %z')}", file=f)
773
774     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
775     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
776     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
777     target.set('CDIST_DIRECTORY', target.directory)
778
779     target.set('CDIST_CONFIGURE', '"' + configure_options(target, options, for_package=True) + '"')
780     target.set('CDIST_PACKAGE', f'{name}{suffix}')
781     target.set('CDIST_WX_VERSION', "3.2" if target.version in ("23.04", "23.10", "24.04") else "3.1")
782     if not target.debug:
783         target.set('CDIST_DEBUG_PACKAGE_FLAG', '--no-ddebs')
784
785     target.command('dpkg-buildpackage -uc -us')
786
787     debs = []
788     for p in glob.glob('../*.deb'):
789         debs.append(os.path.abspath(p))
790
791     return debs
792
793 def package_rpm(target, cpu, version, options):
794     topdir = os.path.realpath('build/rpmbuild')
795     os.makedirs('%s/BUILD' % topdir)
796     os.makedirs('%s/RPMS' % topdir)
797     os.makedirs('%s/SOURCES' % topdir)
798     os.makedirs('%s/SPECS' % topdir)
799     os.makedirs('%s/SRPMS' % topdir)
800
801     target.command('./waf dist')
802     shutil.copyfile(
803         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
804         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
805         )
806
807     requires = None
808     if target.distro == 'mageia':
809         requires = "lib64xmlsec1-devel lib64canberra-gtk0 libcap-utils"
810
811     make_spec('dcpomatic2.spec', version, target, options, requires)
812     cmd = 'rpmbuild --define "_topdir %s" -bb dcpomatic2.spec' % topdir
813     target.command(cmd)
814     rpms = []
815
816     if cpu == "amd64":
817         cpu = "x86_64"
818     else:
819         cpu = "i686"
820
821     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
822         rpms.append(os.path.abspath(p))
823
824     return rpms
825
826 def make_appimage(target, nice_name, internal_name, version, extra_binaries=None):
827     nice_filename = nice_name.replace(' ', '_')
828     appdir = f'build/{nice_filename}.AppDir'
829     os.makedirs(f'{appdir}/usr/bin')
830     target.command(f'cp {target.directory}/bin/{internal_name} {appdir}/usr/bin')
831     target.command(f'cp {target.directory}/src/openssl/apps/openssl {appdir}/usr/bin/dcpomatic2_openssl')
832     target.command(f'cp {target.directory}/bin/dcpverify {appdir}/usr/bin/dcpomatic2_verify_cli')
833     target.command(f'cp {target.directory}/bin/dcpkdm {appdir}/usr/bin/dcpomatic2_kdm_inspect')
834     if extra_binaries:
835         for bin in extra_binaries:
836             target.command(f'cp {target.directory}/bin/{bin} {appdir}/usr/bin')
837     target.command(f'mkdir -p {appdir}/usr/share/libdcp')
838     target.command(f'cp -r {target.directory}/share/dcpomatic2 {appdir}/usr/share/')
839     target.command(f'cp -r {target.directory}/share/libdcp/xsd {appdir}/usr/share/libdcp/')
840     target.command(f'cp -r {target.directory}/share/libdcp/tags {appdir}/usr/share/libdcp/')
841     target.command(f'cp {target.directory}/share/libdcp/ratings {appdir}/usr/share/libdcp/')
842     lib = 'usr/lib/x86_64-linux-gnu'
843     target.command(f'mkdir -p build/{nice_filename}.AppDir/{lib}/gdk-pixbuf-2.0/2.10.0')
844     target.command(f'cp -a /{lib}/gdk-pixbuf-2.0 build/{nice_filename}.AppDir/usr/lib/x86_64-linux-gnu/')
845     target.command('sudo apt update')
846     for package in ['libc6', 'libglib2.0-0', 'gnome-settings-daemon-schemas', 'librsvg2-common', 'libgdk-pixbuf2.0-0', 'libpango-1.0-0', 'libpangoft2-1.0-0', 'libpangocairo-1.0-0', 'libthai0']:
847         target.command(f'apt download {package}')
848         target.command(f'dpkg-deb -x {package}*.deb {appdir}')
849     target.command(f'glib-compile-schemas {appdir}/usr/share/glib-2.0/schemas')
850     target.command(f'sed -i -e "s|/usr/lib/x86_64-linux-gnu/gdk-pixbuf-.*/.*/loaders/||g" {appdir}/usr/lib/x86_64-linux-gnu/gdk-pixbuf-*/*/loaders.cache')
851     # Stop anything loading from outside the AppImage
852     target.command(f'sed -i -e "s|/usr|/xxx|g" {appdir}/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2')
853
854     if internal_name == 'dcpomatic2_disk':
855         target.command(f'mkdir -p {appdir}/usr/share/polkit-1/actions')
856         target.command(f'cp {target.directory}/share/polkit-1/actions/com.dcpomatic.write-drive.policy {appdir}/usr/share/polkit-1/actions')
857
858     with open(f'{appdir}/AppRun', 'w') as f:
859         print('#!/bin/bash', file=f)
860         print('export PATH=$APPDIR/usr/bin:$PATH', file=f)
861         print('export XDG_DATA_DIRS="$APPDIR/usr/share/:/usr/share/:$XDG_DATA_DIRS"', file=f)
862         print('export GDK_PIXBUF_MODULEDIR=$(readlink -f "$APPDIR"/usr/lib/x86_64-linux-gnu/gdk-pixbuf-*/*/loaders/ )', file=f)
863         print('export GDK_PIXBUF_MODULE_FILE=$(readlink -f "$APPDIR"/usr/lib/x86_64-linux-gnu/gdk-pixbuf-*/*/loaders.cache )', file=f)
864         print('export LD_LIBRARY_PATH=$GDK_PIXBUF_MODULEDIR:$APPDIR/usr/lib:$APPDIR/usr/lib/x86_64-linux-gnu', file=f)
865         print(f'"$APPDIR"/usr/bin/{internal_name} $@', file=f)
866     target.command(f'chmod a+rx {appdir}/AppRun')
867     with open(f'{appdir}/{internal_name}.desktop', 'w') as f:
868         print('[Desktop Entry]', file=f)
869         print('Type=Application', file=f)
870         print('Categories=AudioVideo;', file=f)
871         print(f'Name={nice_name}', file=f)
872         print(f'Icon={internal_name}', file=f)
873     target.command(f'cp graphics/linux/256/{internal_name}.png {appdir}')
874     target.command(f'linuxdeploy-x86_64.AppImage --appdir {appdir}')
875     target.command(f'appimagetool-x86_64.AppImage {appdir}')
876     target.command(f'mv {nice_filename}-x86_64.AppImage build/{nice_filename}-{version}-x86_64.AppImage')
877     return os.path.abspath(f'build/{nice_filename}-{version}-x86_64.AppImage')
878
879 def package(target, version, options):
880     """version: DCP-o-matic version string"""
881     if target.platform == 'windows':
882         return package_windows(target)
883     elif target.platform == 'linux':
884         if target.detail == 'appimage':
885             out = []
886             out.append(make_appimage(target, 'DCP-o-matic', 'dcpomatic2', version, ('dcpomatic2_map', 'dcpomatic2_cli')))
887             out.append(make_appimage(target, 'DCP-o-matic Player', 'dcpomatic2_player', version))
888             out.append(make_appimage(target, 'DCP-o-matic Playlist Editor', 'dcpomatic2_playlist', version))
889             out.append(make_appimage(target, 'DCP-o-matic KDM Creator', 'dcpomatic2_kdm', version))
890             out.append(make_appimage(target, 'DCP-o-matic Batch Converter', 'dcpomatic2_batch', version))
891             out.append(make_appimage(target, 'DCP-o-matic Encode Server', 'dcpomatic2_server', version))
892             out.append(make_appimage(target, 'DCP-o-matic Combiner', 'dcpomatic2_combiner', version))
893             out.append(make_appimage(target, 'DCP-o-matic Editor', 'dcpomatic2_editor', version))
894             out.append(make_appimage(target, 'DCP-o-matic Verifier', 'dcpomatic2_verifier', version))
895             return out
896         else:
897             if target.bits == 32:
898                 cpu = 'i386'
899             else:
900                 cpu = 'amd64'
901
902             if target.distro == 'debian' or target.distro == 'ubuntu':
903                 return package_debian(target, cpu, version, options)
904             elif target.distro == 'centos' or target.distro == 'fedora' or target.distro == 'mageia':
905                 return package_rpm(target, cpu, version, options)
906     elif target.platform == 'osx':
907         archs = '-a ' + ' -a '.join(f'{t.arch}/{t.deployment}' for t in target.sub_targets)
908         cmd = 'bash platform/osx/make_dmg.sh -e %s -r %s -i %s -p %s %s' % (target.environment_prefix, target.directory, target.apple_id, target.apple_password, archs)
909         if 'part' in options:
910             cmd += ' -b ' + options['part']
911         if options['variant']:
912             cmd += ' -v ' + options['variant']
913         target.command(cmd)
914         return glob.glob('build/platform/osx/' + dmg_prefix(options['variant']) + '*.dmg')
915     elif target.platform == 'docker':
916         shutil.copyfile(target.deb, 'build/platform/docker')
917         f = open('build/platform/docker/Dockerfile', 'w')
918         print('FROM debian:jessie', file=f)
919         print('MAINTAINER carl@dcpomatic.com', file=f)
920         print('ADD build/platform/docker/dcpomatic_%s-1_amd64.deb /tmp' % (version, version), file=f)
921         print('RUN apt-get -o Acquire:http::Timeout="5" update; exit 0', file=f)
922         print('RUN dpkg -i /tmp/dcpomatic_*.deb; exit 0', file=f)
923         print('RUN apt-get -y -f install', file=f)
924         print('RUN apt-get clean', file=f)
925         print('EXPOSE 6192', file=f)
926         print('CMD ["/usr/bin/dcpomatic2_server_cli", "--verbose"]', file=f)
927         f.close()
928         target.command('docker build build/platform/docker -t dcpomatic-server:%s' % version)
929         target.command('docker save dcpomatic-server:%s -o dcpomatic-server-%s-docker.tar' % (version, version))
930     elif target.platform == 'flatpak':
931         target.command('%s build-bundle build/platform/repo build/dcpomatic_%s.flatpak com.dcpomatic.DCP-o-matic' % (target.flatpak(), version))
932         return os.path.abspath('build/dcpomatic_%s.flatpak' % version)
933
934 def make_pot(target):
935     target.command('./waf pot')
936     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
937             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
938             os.path.abspath('build/src/tools/dcpomatic.pot')]
939
940 def make_manual(target):
941     target.command('make -C doc/manual LIBDCP=../../../libdcp')
942     os.chdir('doc/manual')
943     target.command('pdflatex colour.tex')
944     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
945
946 def test(target, options, test):
947     target.set('LC_ALL', 'C')
948     if target.platform == 'windows':
949         cmd = 'run\\tests '
950     else:
951         cmd = 'run/tests --check --log_level=test_suite '
952     if target.debug:
953         cmd += '--backtrace '
954     if test is not None:
955         cmd += '-t %s' % test
956     target.command(cmd)