Merge master.
[dcpomatic.git] / cscript
1 import glob
2 import shutil
3 import os
4
5 deb_build_depends = {'debhelper': '8.0.0',
6                      'python': '2.7.3',
7                      'g++': '4:4.6.3',
8                      'pkg-config': '0.26',
9                      'libssh-dev': '0.5.2',
10                      'libsndfile1-dev': '1.0.25',
11                      'libgtk2.0-dev': '2.24.10'}
12
13 deb_depends = dict()
14
15 deb_depends['12.04'] = {'libc6': '2.15',
16                         'libssh-4': '0.5.2',
17                         'libboost-filesystem1.48.0': '1.48.0-3',
18                         'libboost-thread1.48.0': '1.48.0-3',
19                         'libsndfile1': '1.0.25',
20                         'libmagick++4': '8:6.6.9.7',
21                         'libxml++2.6-2': '2.34.1',
22                         'libgtk2.0-0': '2.24.10',
23                         'libxmlsec1': '1.2.14-1.2build1',
24                         'libxmlsec1-openssl': '1.2.14-1.2build1',
25                         'libboost-date-time1.48.0': '1.48.0-3',
26                         'libcurl3': '7.22.0-3ubuntu4',
27                         'libzip2': '0.10-1ubuntu1'}
28
29 deb_depends['12.10'] = {'libc6': '2.15',
30                         'libssh-4': '0.5.2',
31                         'libboost-filesystem1.49.0': '1.49.0',
32                         'libboost-thread1.49.0': '1.49.0',
33                         'libsndfile1': '1.0.25',
34                         'libmagick++5': '8:6.7.7.10',
35                         'libxml++2.6-2': '2.34.2',
36                         'libgtk2.0-0': '2.24.13',
37                         'libxmlsec1': '1.2.18-2',
38                         'libxmlsec1-openssl': '1.2.18-2',
39                         'libboost-date-time1.49.0': '1.49.0',
40                         'libcurl3': '7.27.0-1ubuntu1',
41                         'libzip2': '0.10.1-1.1'}
42
43 deb_depends['13.04'] = {'libc6': '2.15',
44                         'libssh-4': '0.5.2',
45                         'libboost-filesystem1.49.0': '1.49.0',
46                         'libboost-thread1.49.0': '1.49.0',
47                         'libsndfile1': '1.0.25',
48                         'libmagick++5': '8:6.7.7.10',
49                         'libxml++2.6-2': '2.34.2',
50                         'libgtk2.0-0': '2.24.13',
51                         'libxmlsec1': '1.2.18-2',
52                         'libxmlsec1-openssl': '1.2.18-2',
53                         'libboost-date-time1.49.0': '1.49.0',
54                         'libcurl3': '7.29.0-1ubuntu3',
55                         'libzip2': '0.10.1-1.1'}
56
57 deb_depends['13.10'] = {'libc6': '2.17-93',
58                         'libssh-4': '0.5.4',
59                         'libboost-filesystem1.53.0': '1.53.0',
60                         'libboost-thread1.53.0': '1.53.0',
61                         'libsndfile1': '1.0.25',
62                         'libmagick++5': '8:6.7.7.10',
63                         'libxml++2.6-2': '2.36.0',
64                         'libgtk2.0-0': '2.24.20',
65                         'libxmlsec1': '1.2.18-2',
66                         'libxmlsec1-openssl': '1.2.18-2',
67                         'libboost-date-time1.49.0': '1.49.0',
68                         'libcurl3': '7.29.0-1ubuntu3',
69                         'libzip2': '0.10.1-1.1'}
70
71 deb_depends['14.04'] = {'libc6': '2.19-0ubuntu6',
72                         'libssh-4': '0.6.1-0ubuntu3',
73                         'libboost-filesystem1.54.0': '1.54.0-4ubuntu3',
74                         'libboost-thread1.54.0': '1.54.0-4ubuntu3',
75                         'libsndfile1': '1.0.25-7ubuntu2',
76                         'libmagick++5': '8:6.7.7.10-6ubuntu3',
77                         'libxml++2.6-2': '2.36.0-2ubuntu1',
78                         'libgtk2.0-0': '2.24.23-0ubuntu1',
79                         'libxmlsec1': '1.2.18-2ubuntu1',
80                         'libxmlsec1-openssl': '1.2.18-2ubuntu1',
81                         'libboost-date-time1.54.0': '1.54.0-4ubuntu3',
82                         'libcurl3': '7.35.0-1ubuntu2',
83                         'libzip2': '0.10.1-1.2'}
84
85 deb_depends['7'] = {'libc6': '2.13',
86                     'libssh-4': '0.5.4',
87                     'libboost-filesystem1.49.0': '1.49.0',
88                     'libboost-thread1.49.0': '1.49.0',
89                     'libsndfile1': '1.0.25',
90                     'libmagick++5': '8:6.7.7.10',
91                     'libxml++2.6-2': '2.34.2',
92                     'libgtk2.0-0': '2.24.10',
93                     'libxmlsec1': '1.2.18',
94                     'libboost-date-time1.49.0': '1.49.0',
95                     'libxmlsec1-openssl': '1.2.18',
96                     'libcurl3': '7.26.0',
97                     'libzip2': '0.10.1'}
98
99 deb_depends['unstable'] = {'libc6': '2.13',
100                     'libssh-4': '0.5.4',
101                     'libboost-filesystem1.55.0': '1.55.0',
102                     'libboost-thread1.55.0': '1.55.0',
103                     'libsndfile1': '1.0.25',
104                     'libmagick++5': '8:6.7.7.10',
105                     'libxml++2.6-2': '2.34.2',
106                     'libgtk2.0-0': '2.24.10',
107                     'libxmlsec1': '1.2.18',
108                     'libboost-date-time1.55.0': '1.55.0',
109                     'libxmlsec1-openssl': '1.2.18',
110                     'libcurl3': '7.26.0',
111                     'libzip2': '0.10.1'}
112
113
114 def packages(name, packages, f):
115     s = '%s: ' % name
116     for p in packages:
117         s += str(p) + ', '
118     print >>f,s[:-2]
119
120 def make_control(debian_version, bits, filename, debug):
121     f = open(filename, 'w')
122     print >>f,'Source: dcpomatic'
123     print >>f,'Section: video'
124     print >>f,'Priority: extra'
125     print >>f,'Maintainer: Carl Hetherington <carl@dcpomatic.com>'
126     packages('Build-Depends', deb_build_depends, f)
127     print >>f,'Standards-Version: 3.9.3'
128     print >>f,'Homepage: http://dcpomatic.com/'
129     print >>f,''
130     print >>f,'Package: dcpomatic'
131     if bits == 32:
132         print >>f,'Architecture: i386'
133     else:
134         print >>f,'Architecture: amd64'
135
136     packages('Depends', deb_depends[debian_version], f)
137
138     print >>f,'Description: Generator of Digital Cinema Packages (DCPs)'
139     print >>f,'  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio'
140     print >>f,'  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant'
141     print >>f,'  digital projectors.'
142
143     if debug:
144         print >>f,''
145         print >>f,'Package: dcpomatic-dbg'
146         if bits == 32:
147             print >>f,'Architecture: i386'
148         else:
149             print >>f,'Architecture: amd64'
150         print >>f,'Section: debug'
151         print >>f,'Priority: extra'
152         packages('Depends', deb_depends[debian_version], f)
153         print >>f,'Description: debugging symbols for dcpomatic'
154         print >>f,'  This package contains the debugging symbols for dcpomatic.'
155         print >>f,''
156
157 def dependencies(target):
158     return (('ffmpeg-cdist', '2dffa11'),
159             ('libdcp', '1.0'),
160             ('libsub', None))
161
162 def build(target, options):
163     cmd = './waf configure --prefix=%s' % target.directory
164     if target.platform == 'windows':
165         cmd += ' --target-windows'
166     elif target.platform == 'linux':
167         if target.distro == 'debian' or target.distro == 'ubuntu':
168             cmd += ' --target-debian'
169             if target.version == 'unstable':
170                 cmd += ' --debian-unstable'
171         elif target.distro == 'centos':
172             if target.version == '6.5':
173                 cmd += ' --target-centos-6 --disable-tests'
174             elif target.version == '7':
175                 cmd += ' --target-centos-7 --disable-tests'
176
177     target.command(cmd)
178     target.command('./waf')
179
180     if target.platform == 'linux' or target.platform == 'osx':
181         target.command('./waf install')
182
183 def package_windows(target):
184     shutil.copyfile('build/platform/windows/installer.%s.nsi' % target.bits, 'build/platform/windows/installer2.%s.nsi' % target.bits)
185     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
186     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, target.bits))
187     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.directory, target.bits))
188     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
189     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % target.bits)
190     target.command('makensis build/platform/windows/installer2.%s.nsi' % target.bits)
191     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
192
193 def package_debian(target, cpu, version):
194     make_control(target.version, target.bits, 'debian/control', target.debug)
195     target.command('./waf dist')
196     f = open('debian/files', 'w')
197     print >>f,'dcpomatic_%s-1_%s.deb video extra' % (version, cpu)
198     shutil.rmtree('build/deb', ignore_errors=True)
199     
200     os.makedirs('build/deb')
201     os.chdir('build/deb')
202     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
203     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
204     os.chdir('dcpomatic-%s' % version)
205     target.command('dch -b -v %s-1 "New upstream release."' % version)
206     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
207     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
208     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
209     if target.version == 'unstable':
210         target.set('CDIST_EXTRA_CONFIGURE', '--debian-unstable')
211     target.command('dpkg-buildpackage -uc -us')
212     
213     debs = []
214     for p in glob.glob('../*.deb'):
215         debs.append(os.path.abspath(p))
216     
217     return debs
218
219 def package_centos(target, cpu, version):
220     topdir = os.path.realpath('build/rpmbuild')
221     os.makedirs('%s/BUILD' % topdir)
222     os.makedirs('%s/RPMS' % topdir)
223     os.makedirs('%s/SOURCES' % topdir)
224     os.makedirs('%s/SPECS' % topdir)
225     os.makedirs('%s/SRPMS' % topdir)
226
227     target.command('./waf dist')
228     shutil.copyfile(
229         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.directory, version),
230         "%s/SOURCES/dcpomatic-%s.tar.bz2" % (topdir, version)
231         )
232
233     target.command('rpmbuild --define \'_topdir %s\' -bb build/platform/linux/dcpomatic2.spec' % topdir)
234     rpms = []
235
236     if cpu == "amd64":
237         cpu = "x86_64"
238
239     for p in glob.glob('%s/RPMS/%s/*.rpm' % (topdir, cpu)):
240         rpms.append(os.path.abspath(p))
241
242     return rpms
243
244 def package(target, version):
245     if target.platform == 'windows':
246         return package_windows(target)
247     elif target.platform == 'linux':
248         if target.bits == 32:
249             cpu = 'i386'
250         else:   
251             cpu = 'amd64'
252
253         if target.distro == 'debian' or target.distro == 'ubuntu':
254             return package_debian(target, cpu, version)
255         elif target.distro == 'centos':
256             return package_centos(target, cpu, version)
257     elif target.platform == 'osx':
258         target.command('bash platform/osx/make_dmg.sh %s' % target.directory)
259         return os.path.abspath(glob.glob('build/platform/osx/DCP-o-matic*.dmg')[0])
260
261 def make_pot(target):
262     target.command('./waf pot')
263     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
264             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
265             os.path.abspath('build/src/tools/dcpomatic.pot')]
266
267 def make_manual(target):
268     os.chdir('doc/manual')
269     target.command('make')
270     target.command('pdflatex colour.tex')
271     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
272
273 def test(target):
274     if target.platform != 'windows':
275         target.set('LC_ALL', 'C')
276         target.command('run/tests')