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