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