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 def packages(name, packages, f):
101     s = '%s: ' % name
102     for p in packages:
103         s += str(p) + ', '
104     print >>f,s[:-2]
105
106 def make_control(debian_version, bits, filename, debug):
107     f = open(filename, 'w')
108     print >>f,'Source: dcpomatic'
109     print >>f,'Section: video'
110     print >>f,'Priority: extra'
111     print >>f,'Maintainer: Carl Hetherington <carl@dcpomatic.com>'
112     packages('Build-Depends', deb_build_depends, f)
113     print >>f,'Standards-Version: 3.9.3'
114     print >>f,'Homepage: http://dcpomatic.com/'
115     print >>f,''
116     print >>f,'Package: dcpomatic'
117     if bits == 32:
118         print >>f,'Architecture: i386'
119     else:
120         print >>f,'Architecture: amd64'
121
122     packages('Depends', deb_depends[debian_version], f)
123
124     print >>f,'Description: Generator of Digital Cinema Packages (DCPs)'
125     print >>f,'  DCP-o-matic generates Digital Cinema Packages (DCPs) from video and audio'
126     print >>f,'  files (such as those from DVDs or Blu-Rays) for presentation on DCI-compliant'
127     print >>f,'  digital projectors.'
128
129     if debug:
130         print >>f,''
131         print >>f,'Package: dcpomatic-dbg'
132         if bits == 32:
133             print >>f,'Architecture: i386'
134         else:
135             print >>f,'Architecture: amd64'
136         print >>f,'Section: debug'
137         print >>f,'Priority: extra'
138         packages('Depends', deb_depends[debian_version], f)
139         print >>f,'Description: debugging symbols for dcpomatic'
140         print >>f,'  This package contains the debugging symbols for dcpomatic.'
141         print >>f,''
142
143 def dependencies(target):
144     return (('ffmpeg-cdist', 'bba68a5'),
145             ('libdcp', '1.0'))
146
147 def build(target, options):
148     cmd = './waf configure --prefix=%s' % target.work_dir_cscript()
149     if target.platform == 'windows':
150         cmd += ' --target-windows'
151     elif target.platform == 'linux':
152         if target.distro == 'debian' or target.distro == 'ubuntu':
153             cmd += ' --target-debian'
154         elif target.distro == 'centos':
155             cmd += ' --target-centos'
156
157     target.command(cmd)
158     target.command('./waf')
159
160     if target.platform == 'linux' or target.platform == 'osx':
161         target.command('./waf install')
162
163 def package_windows(target):
164     shutil.copyfile('build/platform/windows/installer.%s.nsi' % target.bits, 'build/platform/windows/installer2.%s.nsi' % target.bits)
165     target.command('sed -i "s~%%resources%%~%s/platform/windows~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
166     target.command('sed -i "s~%%static_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.windows_prefix, target.bits))
167     target.command('sed -i "s~%%cdist_deps%%~%s~g" build/platform/windows/installer2.%s.nsi' % (target.work_dir_cscript(), target.bits))
168     target.command('sed -i "s~%%binaries%%~%s/build~g" build/platform/windows/installer2.%s.nsi' % (os.getcwd(), target.bits))
169     target.command('sed -i "s~%%bits%%~32~g" build/platform/windows/installer2.%s.nsi' % target.bits)
170     target.command('makensis build/platform/windows/installer2.%s.nsi' % target.bits)
171     return os.path.abspath(glob.glob('build/platform/windows/*%s*.exe' % target.bits)[0])
172
173 def package_debian(target, cpu, version):
174     make_control(target.version, target.bits, 'debian/control', target.debug)
175     target.command('./waf dist')
176     f = open('debian/files', 'w')
177     print >>f,'dcpomatic_%s-1_%s.deb video extra' % (version, cpu)
178     shutil.rmtree('build/deb', ignore_errors=True)
179     
180     os.makedirs('build/deb')
181     os.chdir('build/deb')
182     shutil.move('../../dcpomatic-%s.tar.bz2' % version, 'dcpomatic_%s.orig.tar.bz2' % version)
183     target.command('tar xjf dcpomatic_%s.orig.tar.bz2' % version)
184     os.chdir('dcpomatic-%s' % version)
185     target.command('dch -b -v %s-1 "New upstream release."' % version)
186     target.set('CDIST_LINKFLAGS', target.get('LINKFLAGS'))
187     target.set('CDIST_CXXFLAGS', target.get('CXXFLAGS'))
188     target.set('CDIST_PKG_CONFIG_PATH', target.get('PKG_CONFIG_PATH'))
189     target.command('dpkg-buildpackage')
190     
191     debs = []
192     for p in glob.glob('../*.deb'):
193         debs.append(os.path.abspath(p))
194     
195     return debs
196
197 def package_centos(target, cpu, version):
198     os.makedirs('%s/rpmbuild/BUILD' % target.work_dir_cdist())
199     os.makedirs('%s/rpmbuild/RPMS' % target.work_dir_cdist())
200     os.makedirs('%s/rpmbuild/SOURCES' % target.work_dir_cdist())
201     os.makedirs('%s/rpmbuild/SPECS' % target.work_dir_cdist())
202     os.makedirs('%s/rpmbuild/SRPMS' % target.work_dir_cdist())
203
204     f = open('%s/.rpmmacros' % target.dir_in_chroot, 'w')
205     print >>f,"%%_topdir %srpmbuild" % target.dir_in_chroot
206     f.close()
207
208     target.command('./waf dist')
209     shutil.copyfile(
210         "%s/src/dcpomatic/dcpomatic-%s.tar.bz2" % (target.work_dir_cdist(), version),
211         "%s/rpmbuild/SOURCES/dcpomatic-%s.tar.bz2" % (target.work_dir_cdist(), version)
212         )
213
214     target.command('rpmbuild -bb build/platform/linux/dcpomatic.spec')
215     rpms = []
216
217     if cpu == "amd64":
218         cpu = "x86_64"
219
220     for p in glob.glob('%s/rpmbuild/RPMS/%s/*.rpm' % (target.work_dir_cdist(), cpu)):
221         rpms.append(os.path.abspath(p))
222
223     return rpms
224
225 def package(target, version):
226     if target.platform == 'windows':
227         return package_windows(target)
228     elif target.platform == 'linux':
229         if target.bits == 32:
230             cpu = 'i386'
231         else:   
232             cpu = 'amd64'
233
234         if target.distro == 'debian' or target.distro == 'ubuntu':
235             return package_debian(target, cpu, version)
236         elif target.distro == 'centos':
237             return package_centos(target, cpu, version)
238     elif target.platform == 'osx':
239         target.command('bash platform/osx/make_dmg.sh %s' % target.work_dir_cscript())
240         return os.path.abspath(glob.glob('build/platform/osx/DCP-o-matic*.dmg')[0])
241
242 def make_pot(target):
243     target.command('./waf pot')
244     return [os.path.abspath('build/src/lib/libdcpomatic.pot'),
245             os.path.abspath('build/src/wx/libdcpomatic-wx.pot'),
246             os.path.abspath('build/src/tools/dcpomatic.pot')]
247
248 def make_manual(target):
249     os.chdir('doc/manual')
250     target.command('make')
251     target.command('pdflatex colour.tex')
252     return [os.path.abspath('pdf'), os.path.abspath('html'), os.path.abspath('colour.pdf')]
253
254 def test(target):
255     if target.platform != 'windows':
256         target.set('LC_ALL', 'C')
257         target.command('run/tests')