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