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