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