Remove unused version numbers from deb dependencies.
[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', 'python', 'g++', 'pkg-config', 'libssh-dev', 'libsndfile1-dev', 'libgtk2.0-dev'}
26
27 deb_depends = dict()
28
29 deb_depends['12.04'] = {'libc6',
30                         'libssh-4',
31                         'libboost-filesystem1.48.0',
32                         'libboost-thread1.48.0',
33                         'libboost-regex1.48.0',
34                         'libsndfile1',
35                         'libmagick++4',
36                         'libxml++2.6-2',
37                         'libgtk2.0-0',
38                         'libxmlsec1',
39                         'libxmlsec1-openssl',
40                         'libboost-date-time1.48.0',
41                         'libcurl3',
42                         'libzip2',
43                         'libsamplerate0',
44                         'libicu48'}
45
46 deb_depends['14.04'] = {'libc6',
47                         'libssh-4',
48                         'libboost-filesystem1.54.0',
49                         'libboost-thread1.54.0',
50                         'libboost-regex1.54.0',
51                         'libsndfile1',
52                         'libmagick++5',
53                         'libxml++2.6-2',
54                         'libgtk2.0-0',
55                         'libxmlsec1',
56                         'libxmlsec1-openssl',
57                         'libboost-date-time1.54.0',
58                         'libcurl3',
59                         'libzip2',
60                         'libsamplerate0',
61                         'libcairomm-1.0-1',
62                         'libpangomm-1.4-1',
63                         'libicu52'}
64
65 deb_depends['15.10'] = {'libc6',
66                         'libssh-4',
67                         'libboost-filesystem1.58.0',
68                         'libboost-thread1.58.0',
69                         'libboost-regex1.58.0',
70                         'libsndfile1',
71                         'libmagick++-6.q16-5v5',
72                         'libxml++2.6-2v5',
73                         'libgtk2.0-0',
74                         'libxmlsec1',
75                         'libxmlsec1-openssl',
76                         'libboost-date-time1.58.0',
77                         'libcurl3',
78                         'libzip4',
79                         'libwxgtk3.0-0v5',
80                         'libsamplerate0',
81                         'libicu55'}
82
83 deb_depends['7'] = {'libc6',
84                     'libssh-4',
85                     'libboost-filesystem1.49.0',
86                     'libboost-thread1.49.0',
87                     'libboost-regex1.49.0',
88                     'libsndfile1',
89                     'libmagick++5',
90                     'libxml++2.6-2',
91                     'libgtk2.0-0',
92                     'libxmlsec1',
93                     'libboost-date-time1.49.0',
94                     'libxmlsec1-openssl',
95                     'libcurl3',
96                     'libzip2',
97                     'libcairomm-1.0-1',
98                     'libpangomm-1.4-1',
99                     'libsamplerate0',
100                     'libicu48'}
101
102 deb_depends['8'] = {'libc6',
103                     'libssh-4',
104                     'libboost-filesystem1.55.0',
105                     'libboost-thread1.55.0',
106                     'libboost-date-time1.55.0',
107                     'libboost-regex1.55.0',
108                     'libsndfile1',
109                     'libmagick++-6.q16-5',
110                     'libxml++2.6-2',
111                     'libgtk2.0-0',
112                     'libxmlsec1',
113                     'libxmlsec1-openssl',
114                     'libcurl3',
115                     'libzip2',
116                     'libwxgtk3.0-0',
117                     'libxcb-xfixes0',
118                     'libxcb-shape0',
119                     'libsamplerate0',
120                     'libicu52'}
121
122 deb_depends['unstable'] = {'libc6',
123                            'libssh-4',
124                            'libboost-filesystem1.58.0',
125                            'libboost-thread1.58.0',
126                            'libboost-regex1.58.0',
127                            'libsndfile1',
128                            'libmagick++-6.q16-5v5',
129                            'libxml++2.6-2v5',
130                            'libgtk2.0-0',
131                            'libxmlsec1',
132                            'libboost-date-time1.58.0',
133                            'libxmlsec1-openssl',
134                            'libcurl3',
135                            'libzip2',
136                            'libsamplerate0',
137                            'libicu52'}
138
139 def packages(name, packages, f):
140     s = '%s: ' % name
141     for p in packages:
142         s += str(p) + ', '
143     print(s[:-2], file=f)
144
145 def make_control(debian_version, bits, filename, debug):
146     f = open(filename, 'w')
147     print('Source: dcpomatic', file=f)
148     print('Section: video', file=f)
149     print('Priority: extra', file=f)
150     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
151     packages('Build-Depends', deb_build_depends, f)
152     print('Standards-Version: 3.9.3', file=f)
153     print('Homepage: http://dcpomatic.com/', file=f)
154     print('', file=f)
155     print('Package: dcpomatic', file=f)
156     if bits == 32:
157         print('Architecture: i386', file=f)
158     else:
159         print('Architecture: amd64', file=f)
160
161     packages('Depends', deb_depends[debian_version], f)
162
163     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
164     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio', file=f)
165     print('  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant', file=f)
166     print('  digital projectors.', file=f)
167
168     if debug:
169         print('', file=f)
170         print('Package: dcpomatic-dbg', file=f)
171         if bits == 32:
172             print('Architecture: i386', file=f)
173         else:
174             print('Architecture: amd64', file=f)
175         print('Section: debug', file=f)
176         print('Priority: extra', file=f)
177         packages('Depends', deb_depends[debian_version], f)
178         print('Description: debugging symbols for dcpomatic', file=f)
179         print('  This package contains the debugging symbols for dcpomatic.', file=f)
180         print('', file=f)
181
182 def make_spec(filename, version, target):
183     """Make a .spec file for a RPM build"""
184     f = open(filename, 'w')
185     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
186     print('Name:dcpomatic2', file=f)
187     print('Version:%s' % version, file=f)
188     print('Release:1%{?dist}', file=f)
189     print('License:GPL', file=f)
190     print('Group:Applications/Multimedia', file=f)
191     print('URL:http://dcpomatic.com/', file=f)
192     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
193     print('', file=f)
194     print('%description', file=f)
195     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
196     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
197     print('digital projectors.', file=f)
198     print('', file=f)
199     print('%files', file=f)
200     print('%{_bindir}/dcpomatic2', file=f)
201     print('%{_bindir}/dcpomatic2_batch', file=f)
202     print('%{_bindir}/dcpomatic2_cli', file=f)
203     print('%{_bindir}/dcpomatic2_create', file=f)
204     print('%{_bindir}/dcpomatic2_kdm', file=f)
205     print('%{_bindir}/dcpomatic2_server', file=f)
206     print('%{_bindir}/dcpomatic2_server_cli', file=f)
207     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
208     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
209     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
210     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
211     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
212     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
213     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
214     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
215     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
216     print('%{_datadir}/dcpomatic2/splash.png', file=f)
217     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
218         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
219         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
220         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
221         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
222     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']:
223         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
224         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
225         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
226     print('', file=f)
227     print('%prep', file=f)
228     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
229     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
230     print('%build', file=f)
231     print('cd dcpomatic-%s' % version, file=f)
232     print('export PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig' % (target.directory, target.directory), file=f)
233     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)
234     print('./waf', file=f)
235     print('%install', file=f)
236     print('cd dcpomatic-%s' % version, file=f)
237     print('./waf install', file=f)
238     print('', file=f)
239     print('%post', file=f)
240     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
241     print('', file=f)
242     print('%postun', file=f)
243     print('if [ $1 -eq 0 ] ; then', file=f)
244     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
245     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
246     print('fi', file=f)
247     print('', file=f)
248     print('%posttrans', file=f)
249     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
250
251 def dependencies(target):
252
253     if target.platform == 'linux':
254         ffmpeg_options = { 'shared': False }
255     else:
256         ffmpeg_options = {}
257
258     return (('ffmpeg-cdist', 'f2952f3', ffmpeg_options),
259             ('libdcp', 'v1.3.2'),
260             ('libsub', 'b9fb00d'))
261
262 def configure_options(target):
263     opt = ''
264     if target.debug:
265         opt += ' --enable-debug'
266     if target.platform == 'windows':
267         opt += ' --target-windows'
268     elif target.platform == 'linux':
269         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
270         if target.distro == 'centos':
271             opt += ' --static-xmlsec --static-ssh --disable-tests'
272             if target.version == '6.5':
273                 opt += ' --static-boost --static-xmlpp'
274             elif target.version == '7':
275                 opt += ' --workaround-gssapi --static-xmlpp'
276
277     return opt
278
279 def build(target, options):
280     target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target)))
281     target.command('./waf')
282
283     if target.platform == 'linux' or target.platform == 'osx':
284         target.command('./waf install')
285
286 def package_windows(target):
287     shutil.copyfile('build/platform/windows/installer.%s.nsi' % target.bits, 'build/platform/windows/installer2.%s.nsi' % target.bits)
288     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
289     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
290     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, target.bits))
291     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, target.bits))
292     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.mingw_path, target.bits))
293     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
294     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % target.bits)
295     target.command('makensis build/platform/windows/installer2.%s.nsi' % target.bits)
296     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
297
298 def package_debian(target, cpu, version):
299     make_control(target.version, target.bits, 'debian/control', target.debug)
300     target.command('./waf dist')
301     f = open('debian/files', 'w')
302     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
303     shutil.rmtree('build/deb', ignore_errors=True)
304
305     os.makedirs('build/deb')
306     os.chdir('build/deb')
307     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
308     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
309     os.chdir('dcpomatic-%s' % version)
310     target.command('dch -b -v %s-1 "New upstream release."' % version)
311     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
312     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
313     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
314
315     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
316     if target.debug:
317         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
318     if target.version in ['15.04', '15.10', '8']:
319         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
320     else:
321         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
322
323     target.command('dpkg-buildpackage -uc -us')
324
325     debs = []
326     for p in glob.glob('../*.deb'):
327         debs.append(os.path.abspath(p))
328
329     return debs
330
331 def package_rpm(target, cpu, version):
332     topdir = os.path.realpath('build/rpmbuild')
333     os.makedirs('%s/BUILD' % topdir)
334     os.makedirs('%s/RPMS' % topdir)
335     os.makedirs('%s/SOURCES' % topdir)
336     os.makedirs('%s/SPECS' % topdir)
337     os.makedirs('%s/SRPMS' % topdir)
338
339     target.command('./waf dist')
340     shutil.copyfile(
341         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
342         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
343         )
344
345     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
346     target.command('rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir)
347     rpms = []
348
349     if cpu == "amd64":
350         cpu = "x86_64"
351     else:
352         cpu = "i686"
353
354     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
355     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
356         print('found %s' % p)
357         rpms.append(os.path.abspath(p))
358
359     return rpms
360
361 def package(target, version):
362     if target.platform == 'windows':
363         return package_windows(target)
364     elif target.platform == 'linux':
365         if target.bits == 32:
366             cpu = 'i386'
367         else:
368             cpu = 'amd64'
369
370         if target.distro == 'debian' or target.distro == 'ubuntu':
371             return package_debian(target, cpu, version)
372         elif target.distro == 'centos' or target.distro == 'fedora':
373             return package_rpm(target, cpu, version)
374     elif target.platform == 'osx':
375         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
376         return os.path.abspath(glob.glob('build/platform/osx/DCP-o-matic*.dmg')[0])
377
378 def make_pot(target):
379     target.command('./waf pot')
380     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
381             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
382             os.path.abspath('build/src/tools/dcpomatic.pot')]
383
384 def make_manual(target):
385     os.chdir('doc/manual')
386     target.command('make')
387     target.command('pdflatex colour.tex')
388     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
389
390 def test(target):
391     if target.platform != 'windows':
392         target.set('LC_ALL', 'C')
393         target.command('run/tests')