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