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