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