Fix missing build_depends.
[dcpomatic.git] / cscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 #
5 #    This file is part of DCP-o-matic.
6 #
7 #    DCP-o-matic is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    DCP-o-matic is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from __future__ import print_function
22 import glob
23 import shutil
24 import os
25 import copy
26
27 deb_build_depends = dict()
28
29 deb_build_depends_base = ['debhelper', 'python', 'g++', 'pkg-config', 'libsndfile1-dev', 'libgtk2.0-dev']
30
31 deb_build_depends['12.04'] = copy.deepcopy(deb_build_depends_base)
32 deb_build_depends['12.04'].extend(['libssh-dev'])
33 deb_build_depends['14.04'] = copy.deepcopy(deb_build_depends_base)
34 deb_build_depends['14.04'].extend(['libssh-dev'])
35 deb_build_depends['16.04'] = copy.deepcopy(deb_build_depends_base)
36 deb_build_depends['16.04'].extend(['libssh-dev'])
37 deb_build_depends['16.10'] = copy.deepcopy(deb_build_depends_base)
38 deb_build_depends['16.10'].extend(['libssh-dev'])
39 deb_build_depends['7'] = copy.deepcopy(deb_build_depends_base)
40 deb_build_depends['7'].extend(['libssh-dev'])
41 deb_build_depends['8'] = copy.deepcopy(deb_build_depends_base)
42 deb_build_depends['8'].extend(['libssh-dev'])
43 deb_build_depends['unstable'] = copy.deepcopy(deb_build_depends_base)
44
45 deb_depends = dict()
46
47 deb_depends_base = ['libc6', 'libssh-4', 'libsndfile1', 'libsamplerate0', 'libxmlsec1', 'libxmlsec1-openssl', 'libcurl3', 'libgtk2.0-0']
48
49 deb_depends['12.04'] = copy.deepcopy(deb_depends_base)
50 deb_depends['12.04'].extend(['libboost-filesystem1.48.0',
51                              'libboost-thread1.48.0',
52                              'libboost-regex1.48.0',
53                              'libmagick++4',
54                              'libxml++2.6-2',
55                              'libboost-date-time1.48.0',
56                              'libzip2',
57                              'libicu48',
58                              'libnettle4'])
59
60 deb_depends['14.04'] = copy.deepcopy(deb_depends_base)
61 deb_depends['14.04'].extend(['libboost-filesystem1.54.0',
62                              'libboost-thread1.54.0',
63                              'libboost-regex1.54.0',
64                              'libmagick++5',
65                              'libxml++2.6-2',
66                              'libboost-date-time1.54.0',
67                              'libzip2',
68                              'libcairomm-1.0-1',
69                              'libpangomm-1.4-1',
70                              'libicu52',
71                              'libnettle4'])
72
73 deb_depends['16.04'] = copy.deepcopy(deb_depends_base)
74 deb_depends['16.04'].extend(['libboost-filesystem1.58.0',
75                              'libboost-thread1.58.0',
76                              'libboost-regex1.58.0',
77                              'libmagick++-6.q16-5v5',
78                              'libxml++2.6-2v5',
79                              'libboost-date-time1.58.0',
80                              'libzip4',
81                              'libwxgtk3.0-0v5',
82                              'libicu55',
83                              'libnettle6'])
84
85 deb_depends['16.10'] = copy.deepcopy(deb_depends_base)
86 deb_depends['16.10'].extend(['libboost-filesystem1.61.0',
87                              'libboost-thread1.61.0',
88                              'libboost-regex1.61.0',
89                              'libmagick++-6.q16-5v5',
90                              'libxml++2.6-2v5',
91                              'libboost-date-time1.61.0',
92                              'libzip4',
93                              'libwxgtk3.0-0v5',
94                              'libicu57',
95                              'libnettle6'])
96
97 deb_depends['7'] = copy.deepcopy(deb_depends_base)
98 deb_depends['7'].extend(['libboost-filesystem1.49.0',
99                              'libboost-thread1.49.0',
100                              'libboost-regex1.49.0',
101                              'libmagick++5',
102                              'libxml++2.6-2',
103                              'libboost-date-time1.49.0',
104                              'libzip2',
105                              'libcairomm-1.0-1',
106                              'libpangomm-1.4-1',
107                              'libicu48',
108                              'libnettle4',
109                              'libnotify4'])
110
111 deb_depends['8'] = copy.deepcopy(deb_depends_base)
112 deb_depends['8'].extend(['libboost-filesystem1.55.0',
113                          'libboost-thread1.55.0',
114                          'libboost-date-time1.55.0',
115                          'libboost-regex1.55.0',
116                          'libmagick++-6.q16-5',
117                          'libxml++2.6-2',
118                          'libzip2',
119                          'libwxgtk3.0-0',
120                          'libxcb-xfixes0',
121                          'libxcb-shape0',
122                          'libicu52',
123                          'libnettle4'])
124
125 deb_depends['unstable'] = copy.deepcopy(deb_depends_base)
126 deb_depends['unstable'].extend(['libboost-filesystem1.58.0',
127                                 'libboost-thread1.58.0',
128                                 'libboost-regex1.58.0',
129                                 'libmagick++-6.q16-5v5',
130                                 'libxml++2.6-2v5',
131                                 'libgtk2.0-0',
132                                 'libboost-date-time1.58.0',
133                                 'libzip2',
134                                 'libicu52',
135                                 'libnettle6'])
136
137 def packages(name, packages, f):
138     s = '%s: ' % name
139     for p in packages:
140         s += str(p) + ', '
141     print(s[:-2], file=f)
142
143 def make_control(debian_version, bits, filename, debug):
144     f = open(filename, 'w')
145     print('Source: dcpomatic', file=f)
146     print('Section: video', file=f)
147     print('Priority: extra', file=f)
148     print('Maintainer: Carl Hetherington <carl@dcpomatic.com>', file=f)
149     packages('Build-Depends', deb_build_depends[debian_version], f)
150     print('Standards-Version: 3.9.3', file=f)
151     print('Homepage: http://dcpomatic.com/', file=f)
152     print('', file=f)
153     print('Package: dcpomatic', file=f)
154     if bits == 32:
155         print('Architecture: i386', file=f)
156     else:
157         print('Architecture: amd64', file=f)
158
159     packages('Depends', deb_depends[debian_version], f)
160
161     print('Description: Generator of Digital Cinema Packages (DCPs)', file=f)
162     print('  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio', file=f)
163     print('  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant', file=f)
164     print('  digital projectors.', file=f)
165
166     if debug:
167         print('', file=f)
168         print('Package: dcpomatic-dbg', file=f)
169         if bits == 32:
170             print('Architecture: i386', file=f)
171         else:
172             print('Architecture: amd64', file=f)
173         print('Section: debug', file=f)
174         print('Priority: extra', file=f)
175         packages('Depends', deb_depends[debian_version], f)
176         print('Description: debugging symbols for dcpomatic', file=f)
177         print('  This package contains the debugging symbols for dcpomatic.', file=f)
178         print('', file=f)
179
180 def make_spec(filename, version, target):
181     """Make a .spec file for a RPM build"""
182     f = open(filename, 'w')
183     print('Summary:A program that generates Digital Cinema Packages (DCPs) from video and audio files', file=f)
184     print('Name:dcpomatic2', file=f)
185     print('Version:%s' % version, file=f)
186     print('Release:1%{?dist}', file=f)
187     print('License:GPL', file=f)
188     print('Group:Applications/Multimedia', file=f)
189     print('URL:http://dcpomatic.com/', file=f)
190     print('Requires: ImageMagick-c++, glibmm24, libzip', file=f)
191     print('', file=f)
192     print('%description', file=f)
193     print('DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio ', file=f)
194     print('files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant ', file=f)
195     print('digital projectors.', file=f)
196     print('', file=f)
197     print('%files', file=f)
198     print('%{_bindir}/dcpomatic2', file=f)
199     print('%{_bindir}/dcpomatic2_batch', file=f)
200     print('%{_bindir}/dcpomatic2_cli', file=f)
201     print('%{_bindir}/dcpomatic2_create', file=f)
202     print('%{_bindir}/dcpomatic2_kdm', file=f)
203     print('%{_bindir}/dcpomatic2_server', file=f)
204     print('%{_bindir}/dcpomatic2_server_cli', file=f)
205     print('%{_bindir}/dcpomatic2_kdm_cli', file=f)
206     print('%{_datadir}/applications/dcpomatic2.desktop', file=f)
207     print('%{_datadir}/applications/dcpomatic2_batch.desktop', file=f)
208     print('%{_datadir}/applications/dcpomatic2_server.desktop', file=f)
209     print('%{_datadir}/applications/dcpomatic2_kdm.desktop', file=f)
210     print('%{_datadir}/dcpomatic2/dcpomatic2_server_small.png', file=f)
211     print('%{_datadir}/dcpomatic2/LiberationSans-Regular.ttf', file=f)
212     print('%{_datadir}/dcpomatic2/LiberationSans-Italic.ttf', file=f)
213     print('%{_datadir}/dcpomatic2/LiberationSans-Bold.ttf', file=f)
214     print('%{_datadir}/dcpomatic2/splash.png', file=f)
215     for r in ['128x128', '16x16', '22x22', '256x256', '32x32', '48x48', '512x512', '64x64']:
216         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2.png' % r, file=f)
217         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_batch.png' % r, file=f)
218         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_kdm.png' % r, file=f)
219         print('%%{_datadir}/icons/hicolor/%s/apps/dcpomatic2_server.png' % r, file=f)
220     for l in ['de_DE', 'es_ES', 'fr_FR', 'it_IT', 'sv_SE', 'nl_NL', 'ru_RU', 'pl_PL', 'da_DK', 'pt_PT', 'pt_BR', 'sk_SK', 'cs_CZ', 'uk_UA', 'zh_CN']:
221         print('%%{_datadir}/locale/%s/LC_MESSAGES/dcpomatic2.mo' % l, file=f)
222         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2-wx.mo' % l, file=f)
223         print('%%{_datadir}/locale/%s/LC_MESSAGES/libdcpomatic2.mo' % l, file=f)
224     print('', file=f)
225     print('%prep', file=f)
226     print('rm -rf $RPM_BUILD_DIR/dcpomatic-%s' % version, file=f)
227     print('tar xjf $RPM_SOURCE_DIR/dcpomatic-%s.tar.bz2' % version, file=f)
228     print('%build', file=f)
229     print('cd dcpomatic-%s' % version, file=f)
230     print('export PKG_CONFIG_PATH=%s/lib/pkgconfig:%s/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig' % (target.directory, target.directory), file=f)
231
232     if target.distro == 'centos' and target.version == '5':
233         prefix = 'BUILDROOT/usr'
234     else:
235         prefix = '%{buildroot}/usr'
236
237     print('CXXFLAGS="-I%s/include" LDFLAGS="-L%s/lib" ./waf configure --prefix=%s --install-prefix=/usr %s' %
238           (target.directory, target.directory, prefix, configure_options(target)), file=f)
239     print('./waf', file=f)
240     print('%install', file=f)
241     print('cd dcpomatic-%s' % version, file=f)
242     print('./waf install', file=f)
243     print('', file=f)
244     print('%post', file=f)
245     print('/bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
246     print('', file=f)
247     print('%postun', file=f)
248     print('if [ $1 -eq 0 ] ; then', file=f)
249     print('    /bin/touch --no-create %{_datadir}/icons/hicolor &>/dev/null', file=f)
250     print('    /usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
251     print('fi', file=f)
252     print('', file=f)
253     print('%posttrans', file=f)
254     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
255
256 def dependencies(target):
257
258     if target.platform == 'linux':
259         ffmpeg_options = { 'shared': False }
260     else:
261         ffmpeg_options = {}
262
263     return (('ffmpeg-cdist', 'c7df8d5', ffmpeg_options),
264             ('libdcp', '71f5d09'),
265             ('libsub', 'v1.2.4'))
266
267 def configure_options(target):
268     opt = ''
269     if target.debug:
270         opt += ' --enable-debug'
271     if target.platform == 'windows':
272         opt += ' --target-windows'
273     elif target.platform == 'linux':
274         opt += ' --static-dcpomatic --static-wxwidgets --static-ffmpeg --static-dcp --static-sub --static-cxml'
275         if target.distro == 'centos':
276             opt += ' --static-xmlsec --static-ssh --disable-tests'
277             if target.version == '6.5':
278                 opt += ' --static-boost --static-xmlpp'
279             elif target.version == '7':
280                 opt += ' --workaround-gssapi --static-xmlpp'
281
282     # Build Windows debug versions with static linking as I think gdb works better then
283     if target.debug and target.platform == 'windows':
284         opt += ' --static-dcpomatic'
285
286     return opt
287
288 def build(target, options):
289     target.command('./waf configure --prefix=%s %s' % (target.directory, configure_options(target)))
290     target.command('./waf')
291
292     if target.platform == 'linux' or target.platform == 'osx':
293         target.command('./waf install')
294
295 def package_windows(target):
296     identifier = ''
297     if target.version is not None:
298         identifier = '%s.' % target.version
299     identifier += '%d' % target.bits
300     shutil.copyfile('build/platform/windows/installer.%s.nsi' % identifier, 'build/platform/windows/installer2.%s.nsi' % identifier)
301     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
302     target.command('sed -i "s~%%graphics%%~%s/graphics~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
303     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, identifier))
304     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, identifier))
305     target.command('sed -i "s~%%mingw%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.mingw_path, identifier))
306     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), identifier))
307     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % identifier)
308     target.command('makensis build/platform/windows/installer2.%s.nsi' % identifier)
309     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
310
311 def package_debian(target, cpu, version):
312     make_control(target.version, target.bits, 'debian/control', target.debug)
313     target.command('./waf dist')
314     f = open('debian/files', 'w')
315     print('dcpomatic_%s-1_%s.deb video extra' % (version, cpu), file=f)
316     shutil.rmtree('build/deb', ignore_errors=True)
317
318     os.makedirs('build/deb')
319     os.chdir('build/deb')
320     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
321     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
322     os.chdir('dcpomatic-%s' % version)
323     target.command('dch -b -v %s-1 "New upstream release."' % version)
324     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
325     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
326     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
327
328     target.set('CDIST_CONFIGURE', '"' + configure_options(target) + '"')
329     if target.debug:
330         target.set('CDIST_DEBUG_PACKAGE', '--dbg-package=dcpomatic-dbg')
331     if target.version in ['15.04', '15.10', '16.04', '16.10', '8', 'unstable']:
332         target.set('CDIST_LOCALE_PREFIX', '/usr/share/locale')
333     else:
334         target.set('CDIST_LOCALE_PREFIX', '/usr/local/share/locale')
335
336     target.command('dpkg-buildpackage -uc -us')
337
338     debs = []
339     for p in glob.glob('../*.deb'):
340         debs.append(os.path.abspath(p))
341
342     return debs
343
344 def package_rpm(target, cpu, version):
345     topdir = os.path.realpath('build/rpmbuild')
346     os.makedirs('%s/BUILD' % topdir)
347     os.makedirs('%s/RPMS' % topdir)
348     os.makedirs('%s/SOURCES' % topdir)
349     os.makedirs('%s/SPECS' % topdir)
350     os.makedirs('%s/SRPMS' % topdir)
351
352     target.command('./waf dist')
353     shutil.copyfile(
354         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
355         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
356         )
357
358     make_spec('build/platform/linux/dcpomatic2.spec', version, target)
359     cmd = 'rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir
360     if target.distro == 'centos' and target.version == '5':
361         cmd += ' --buildroot %s/BUILD/dcpomatic-%s/BUILDROOT' % (topdir, version)
362     target.command(cmd)
363     rpms = []
364
365     if cpu == "amd64":
366         cpu = "x86_64"
367     else:
368         if target.distro == 'centos' and target.version == '5':
369             cpu = "i386"
370         else:
371             cpu = "i686"
372
373     print('Looking in %s/RPMS/%s/*.rpm' % (topdir, cpu))
374     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
375         print('found %s' % p)
376         rpms.append(os.path.abspath(p))
377
378     return rpms
379
380 def package(target, version):
381     if target.platform == 'windows':
382         return package_windows(target)
383     elif target.platform == 'linux':
384         if target.bits == 32:
385             cpu = 'i386'
386         else:
387             cpu = 'amd64'
388
389         if target.distro == 'debian' or target.distro == 'ubuntu':
390             return package_debian(target, cpu, version)
391         elif target.distro == 'centos' or target.distro == 'fedora':
392             return package_rpm(target, cpu, version)
393     elif target.platform == 'osx':
394         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
395         return [os.path.abspath(x) for x in glob.glob('build/platform/osx/DCP-o-matic*.dmg')]
396
397 def make_pot(target):
398     target.command('./waf pot')
399     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
400             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
401             os.path.abspath('build/src/tools/dcpomatic.pot')]
402
403 def make_manual(target):
404     os.chdir('doc/manual')
405     target.command('make')
406     target.command('pdflatex colour.tex')
407     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
408
409 def test(target, test):
410     if target.platform != 'windows':
411         target.set('LC_ALL', 'C')
412         cmd = 'run/tests '
413         if target.debug:
414             cmd += '--backtrace '
415         if test is not None:
416             cmd += '--run_test=%s' % test
417         target.command(cmd)