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