22b13e0d021313d3b0bc6a65abf535878f45d278 from master; add test for audio analysis...
[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 make_spec(filename, version, target):
148     """Make a .spec file for a RPM build"""
149     f = open(filename, 'w')
150     print >>f,'Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files'
151     print >>f,'Name:dcpomatic2'
152     print >>f,'Version:%s' % version
153     print >>f,'Release:1%{?dist}'
154     print >>f,'License:GPL'
155     print >>f,'Group:Applications/Multimedia'
156     print >>f,'URL:http://dcpomatic.com/'
157     print >>f,'Requires: ImageMagick-c++, glibmm24, libzip'
158     print >>f,''
159     print >>f,'%description'
160     print >>f,'DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio '
161     print >>f,'files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant '
162     print >>f,'digital projectors.'
163     print >>f,''
164     print >>f,'%files'
165     print >>f,'%{_bindir}/dcpomatic2'
166     print >>f,'%{_bindir}/dcpomatic2_batch'
167     print >>f,'%{_bindir}/dcpomatic2_cli'
168     print >>f,'%{_bindir}/dcpomatic2_create'
169     print >>f,'%{_bindir}/dcpomatic2_kdm'
170     print >>f,'%{_bindir}/dcpomatic2_server'
171     print >>f,'%{_bindir}/dcpomatic2_server_cli'
172     print >>f,'%{_datadir}/applications/dcpomatic2.desktop'
173     print >>f,'%{_datadir}/applications/dcpomatic2_batch.desktop'
174     print >>f,'%{_datadir}/applications/dcpomatic2_server.desktop'
175     print >>f,'%{_datadir}/dcpomatic/taskbar_icon.png'
176     for r in ['128x128', '22x22', '32x32', '48x48', '64x64']:
177         print >>f,'%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r
178     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL']:
179         print >>f,'%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l
180         print >>f,'%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l
181         print >>f,'%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l
182     print >>f,''
183     print >>f,'%prep'
184     print >>f,'rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version
185     print >>f,'tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version
186     print >>f,'%build'
187     print >>f,'cd dcpomatic-%s' % version
188     print >>f,'export PKG_CONFIG_PATH=%s/lib/pkgconfig:/usr/local/lib/pkgconfig' % target.directory
189     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))
190     print >>f,'./waf'
191     print >>f,'%install'
192     print >>f,'cd dcpomatic-%s' % version
193     print >>f,'./waf install'
194     print >>f,''
195     print >>f,'%post'
196     print >>f,'/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :'
197     print >>f,''
198     print >>f,'%postun'
199     print >>f,'if [ $1 -eq 0 ] ; then'
200     print >>f,'    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null'
201     print >>f,'    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :'
202     print >>f,'fi'
203     print >>f,''
204     print >>f,'%posttrans'
205     print >>f,'/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :'
206
207 def dependencies(target):
208     return (('ffmpeg-cdist', '0492ad2'),
209             ('libdcp', 'b386248'),
210             ('libsub', 'f66b11f'))
211
212 def configure_options(target):
213     opt = ''
214     if target.debug:
215         opt += ' --enable-debug'
216     if target.platform == 'windows':
217         opt += ' --target-windows'
218     elif target.platform == 'linux':
219         opt += ' --static-dcpomatic --static-openjpeg --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
220         if target.distro == 'centos':
221             opt += ' --static-xmlsec --static-ssh --disable-tests'
222             if target.version == '6.5':
223                 opt += ' --static-boost --static-xmlpp'
224             elif target.version == '7':
225                 opt += ' --workaround-gssapi'
226
227     return opt
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
264     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
265     if target.debug:
266         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
267     if target.version == '15.04':
268         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
269     else:
270         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
271
272     target.command('dpkg-buildpackage -uc -us')
273     
274     debs = []
275     for p in glob.glob('../*.deb'):
276         debs.append(os.path.abspath(p))
277     
278     return debs
279
280 def package_centos(target, cpu, version):
281     topdir = os.path.realpath('build/rpmbuild')
282     os.makedirs('%s/BUILD' % topdir)
283     os.makedirs('%s/RPMS' % topdir)
284     os.makedirs('%s/SOURCES' % topdir)
285     os.makedirs('%s/SPECS' % topdir)
286     os.makedirs('%s/SRPMS' % topdir)
287
288     target.command('./waf dist')
289     shutil.copyfile(
290         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
291         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
292         )
293
294     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
295     target.command('rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir)
296     rpms = []
297
298     if cpu == "amd64":
299         cpu = "x86_64"
300
301     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
302         rpms.append(os.path.abspath(p))
303
304     return rpms
305
306 def package(target, version):
307     if target.platform == 'windows':
308         return package_windows(target)
309     elif target.platform == 'linux':
310         if target.bits == 32:
311             cpu = 'i386'
312         else:   
313             cpu = 'amd64'
314
315         if target.distro == 'debian' or target.distro == 'ubuntu':
316             return package_debian(target, cpu, version)
317         elif target.distro == 'centos':
318             return package_centos(target, cpu, version)
319     elif target.platform == 'osx':
320         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
321         return os.path.abspath(glob.glob('build/platform/osx/DCP-o-matic*.dmg')[0])
322
323 def make_pot(target):
324     target.command('./waf pot')
325     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
326             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
327             os.path.abspath('build/src/tools/dcpomatic.pot')]
328
329 def make_manual(target):
330     os.chdir('doc/manual')
331     target.command('make')
332     target.command('pdflatex colour.tex')
333     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
334
335 def test(target):
336     if target.platform != 'windows':
337         target.set('LC_ALL', 'C')
338         target.command('run/tests')