-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.py
executable file
·355 lines (297 loc) · 14.1 KB
/
prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env python
############################################################################
# prepare.py
# Copyright (C) 2015 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
############################################################################
import os
import re
import shutil
import sys
from distutils.spawn import find_executable
from logging import error, warning, info
from subprocess import Popen, PIPE
sys.dont_write_bytecode = True
sys.path.insert(0, 'submodules/cmake-builder')
try:
import prepare
except Exception as e:
error(
"Could not find prepare module: {}, probably missing submodules/cmake-builder? Try running:\n"
"git submodule sync && git submodule update --init --recursive".format(e))
exit(1)
class IOSTarget(prepare.Target):
def __init__(self, arch):
prepare.Target.__init__(self, 'ios-' + arch)
current_path = os.path.dirname(os.path.realpath(__file__))
self.config_file = 'configs/config-ios-' + arch + '.cmake'
self.toolchain_file = 'toolchains/toolchain-ios-' + arch + '.cmake'
self.output = 'liblinphone-sdk/' + arch + '-apple-darwin.ios'
self.external_source_path = os.path.join(current_path, 'submodules')
class IOSi386Target(IOSTarget):
def __init__(self):
IOSTarget.__init__(self, 'i386')
class IOSx8664Target(IOSTarget):
def __init__(self):
IOSTarget.__init__(self, 'x86_64')
class IOSarmv7Target(IOSTarget):
def __init__(self):
IOSTarget.__init__(self, 'armv7')
class IOSarm64Target(IOSTarget):
def __init__(self):
IOSTarget.__init__(self, 'arm64')
ios_targets = {
'i386': IOSi386Target(),
'x86_64': IOSx8664Target(),
'armv7': IOSarmv7Target(),
'arm64': IOSarm64Target()
}
ios_virtual_targets = {
'devices': ['armv7', 'arm64'],
'simulators': ['i386', 'x86_64'],
'all': ['i386', 'x86_64', 'armv7', 'arm64']
}
class IOSPreparator(prepare.Preparator):
def __init__(self, targets=ios_targets, virtual_targets=ios_virtual_targets):
prepare.Preparator.__init__(self, targets, default_targets=['armv7', 'arm64', 'x86_64'], virtual_targets=virtual_targets)
self.veryclean = True
self.show_gpl_disclaimer = True
self.argparser.add_argument('-ac', '--all-codecs', help="Enable all codecs, including the non-free ones. Final application must comply with their respective license (see README.md).", action='store_true')
def parse_args(self):
prepare.Preparator.parse_args(self)
self.additional_args += ["-DLINPHONE_IOS_DEPLOYMENT_TARGET=" + self.extract_deployment_target()]
self.additional_args += ["-DLINPHONE_BUILDER_DUMMY_LIBRARIES=" + ' '.join(self.extract_libs_list())]
if self.args.all_codecs:
self.additional_args += ["-DENABLE_GPL_THIRD_PARTIES=ON"]
self.additional_args += ["-DENABLE_NON_FREE_CODECS=ON"]
self.additional_args += ["-DENABLE_AMRNB=ON"]
self.additional_args += ["-DENABLE_AMRWB=ON"]
self.additional_args += ["-DENABLE_BV16=ON"]
self.additional_args += ["-DENABLE_G729=ON"]
self.additional_args += ["-DENABLE_GSM=ON"]
self.additional_args += ["-DENABLE_ILBC=ON"]
self.additional_args += ["-DENABLE_ISAC=ON"]
self.additional_args += ["-DENABLE_OPUS=ON"]
self.additional_args += ["-DENABLE_SILK=ON"]
self.additional_args += ["-DENABLE_SPEEX=ON"]
self.additional_args += ["-DENABLE_FFMPEG=ON"]
self.additional_args += ["-DENABLE_H263=ON"]
self.additional_args += ["-DENABLE_H263P=ON"]
self.additional_args += ["-DENABLE_MPEG4=ON"]
self.additional_args += ["-DENABLE_OPENH264=ON"]
self.additional_args += ["-DENABLE_VPX=ON"]
self.additional_args += ["-DENABLE_X264=ON"]
self.additional_args += ["-DENABLE_CODEC2=ON"]
def clean(self):
prepare.Preparator.clean(self)
if os.path.isfile('Makefile'):
os.remove('Makefile')
if os.path.isdir('WORK') and not os.listdir('WORK'):
os.rmdir('WORK')
if os.path.isdir('liblinphone-sdk'):
l = os.listdir('liblinphone-sdk')
if len(l) == 1 and l[0] == 'apple-darwin':
shutil.rmtree('liblinphone-sdk', ignore_errors=False)
def extract_from_xcode_project_with_regex(self, regex):
l = []
f = open('linphone.xcodeproj/project.pbxproj', 'r')
lines = f.readlines()
f.close()
for line in lines:
m = regex.search(line)
if m is not None:
l += [m.group(1)]
return list(set(l))
def extract_deployment_target(self):
regex = re.compile("IPHONEOS_DEPLOYMENT_TARGET = (.*);")
return self.extract_from_xcode_project_with_regex(regex)[0]
def extract_libs_list(self):
# name = libspeexdsp.a; path = "liblinphone-sdk/apple-darwin/lib/libspeexdsp.a"; sourceTree = "<group>"; };
regex = re.compile("name = \"*(lib\S+)\.a(\")*; path = \"liblinphone-sdk/apple-darwin/")
return self.extract_from_xcode_project_with_regex(regex)
def detect_package_manager(self):
if find_executable("brew"):
return "brew"
elif find_executable("port"):
return "sudo port"
else:
error("No package manager found. Please README or install brew using:\n\truby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\"")
return "brew"
def check_environment(self):
reterr = 0
reterr |= prepare.Preparator.check_environment(self)
package_manager_info = {"brew-pkg-config": "pkg-config",
"sudo port-pkg-config": "pkgconfig",
"brew-binary-path": "/usr/local/bin/",
"sudo port-binary-path": "/opt/local/bin/"
}
for prog in ["autoconf", "automake", "doxygen", "java", "nasm", "cmake", "wget", "yasm", "optipng"]:
reterr |= not self.check_is_installed(prog, prog)
reterr |= not self.check_is_installed("pkg-config", package_manager_info[self.detect_package_manager() + "-pkg-config"])
reterr |= not self.check_is_installed("ginstall", "coreutils")
reterr |= not self.check_is_installed("intltoolize", "intltool")
reterr |= not self.check_is_installed("convert", "imagemagick")
if find_executable("nasm"):
nasm_output = Popen("nasm -f elf32".split(" "), stderr=PIPE, stdout=PIPE).stderr.read()
if "fatal: unrecognised output format" in nasm_output:
error("Invalid version of nasm detected. Please make sure that you are NOT using Apple's binary here")
self.missing_dependencies["nasm"] = "nasm"
reterr = 1
if self.check_is_installed("libtoolize", warn=False):
if not self.check_is_installed("glibtoolize", "libtool"):
glibtoolize_path = find_executable("glibtoolize")
reterr = 1
msg = "Please do a symbolic link from glibtoolize to libtoolize:\n\tln -s {} ${}"
error(msg.format(glibtoolize_path, glibtoolize_path.replace("glibtoolize", "libtoolize")))
devnull = open(os.devnull, 'wb')
# just ensure that JDK is installed - if not, it will automatically display a popup to user
p = Popen("java -version".split(" "), stderr=devnull, stdout=devnull)
p.wait()
if p.returncode != 0:
error("Please install Java JDK (not just JRE).")
reterr = 1
p = Popen("xcrun --sdk iphoneos --show-sdk-path".split(" "), stdout=devnull, stderr=devnull)
p.wait()
if p.returncode != 0:
error("iOS SDK not found, please install Xcode from AppStore or equivalent.")
reterr = 1
else:
xcode_version = int(
Popen("xcodebuild -version".split(" "), stdout=PIPE).stdout.read().split("\n")[0].split(" ")[1].split(".")[0])
if xcode_version < 7:
if not find_executable("strings"):
sdk_strings_path = Popen("xcrun --find strings".split(" "), stdout=PIPE).stdout.read().split("\n")[0]
error("strings binary missing, please run:\n\tsudo ln -s {} {}".format(sdk_strings_path, package_manager_info[detect_package_manager() + "-binary-path"]))
reterr = 1
return reterr
def show_missing_dependencies(self):
if self.missing_dependencies:
error("The following binaries are missing: {}. Please install them using:\n\t{} install {}".format(
" ".join(self.missing_dependencies.keys()),
self.detect_package_manager(),
" ".join(self.missing_dependencies.values())))
def install_git_hook(self):
git_hook_path = ".git{sep}hooks{sep}pre-commit".format(sep=os.sep)
if os.path.isdir(".git{sep}hooks".format(sep=os.sep)) and not os.path.isfile(git_hook_path):
info("Installing Git pre-commit hook")
shutil.copyfile(".git-pre-commit", git_hook_path)
os.chmod(git_hook_path, 0755)
def generate_makefile(self, generator, project_file=''):
platforms = self.args.target
arch_targets = ""
for arch in platforms:
arch_targets += """
{arch}: {arch}-build
{arch}-build:
\t{generator} WORK/ios-{arch}/cmake/{project_file}
\t@echo "Done"
""".format(arch=arch, generator=generator, project_file=project_file)
multiarch = ""
for arch in platforms[1:]:
multiarch += \
"""\tif test -f "$${arch}_path"; then \\
\t\tall_paths=`echo $$all_paths $${arch}_path`; \\
\t\tall_archs="$$all_archs,{arch}" ; \\
\telse \\
\t\techo "WARNING: archive `basename $$archive` exists in {first_arch} tree but does not exists in {arch} tree: $${arch}_path."; \\
\tfi; \\
""".format(first_arch=platforms[0], arch=arch)
makefile = """
archs={archs}
LINPHONE_IPHONE_VERSION=$(shell git describe --always)
.PHONY: all
.SILENT: sdk
all: build
sdk:
\tarchives=`find liblinphone-sdk/{first_arch}-apple-darwin.ios -name '*.a'` && \\
\trm -rf liblinphone-sdk/apple-darwin && \\
\tmkdir -p liblinphone-sdk/apple-darwin && \\
\tcp -rf liblinphone-sdk/{first_arch}-apple-darwin.ios/include liblinphone-sdk/apple-darwin/. && \\
\tcp -rf liblinphone-sdk/{first_arch}-apple-darwin.ios/share liblinphone-sdk/apple-darwin/. && \\
\tfor archive in $$archives ; do \\
\t\tarmv7_path=`echo $$archive | sed -e "s/{first_arch}/armv7/"`; \\
\t\tarm64_path=`echo $$archive | sed -e "s/{first_arch}/arm64/"`; \\
\t\ti386_path=`echo $$archive | sed -e "s/{first_arch}/i386/"`; \\
\t\tx86_64_path=`echo $$archive | sed -e "s/{first_arch}/x86_64/"`; \\
\t\tdestpath=`echo $$archive | sed -e "s/-debug//" | sed -e "s/{first_arch}-//" | sed -e "s/\.ios//"`; \\
\t\tall_paths=`echo $$archive`; \\
\t\tall_archs="{first_arch}"; \\
\t\tmkdir -p `dirname $$destpath`; \\
\t\t{multiarch} \\
\t\techo "[{archs}] Mixing `basename $$archive` in $$destpath"; \\
\t\tlipo -create $$all_paths -output $$destpath; \\
\tdone; \\
\tif test -s WORK/ios-{first_arch}/Build/dummy_libraries/dummy_libraries.txt; then \\
\t\techo 'NOTE: the following libraries were STUBBED:'; \\
\t\tcat WORK/ios-{first_arch}/Build/dummy_libraries/dummy_libraries.txt; \\
\tfi
build: $(addsuffix -build, $(archs))
\t$(MAKE) sdk
ipa: build
\txcodebuild -configuration Release \\
\t&& xcrun -sdk iphoneos PackageApplication -v build/Release-iphoneos/linphone.app -o $$PWD/linphone-iphone.ipa
zipsdk: sdk
\techo "Generating SDK zip file for version $(LINPHONE_IPHONE_VERSION)"
\tzip -r liblinphone-iphone-sdk-$(LINPHONE_IPHONE_VERSION).zip \\
\tliblinphone-sdk/apple-darwin \\
\tliblinphone-tutorials \\
\t-x liblinphone-tutorials/hello-world/build\* \\
\t-x liblinphone-tutorials/hello-world/hello-world.xcodeproj/*.pbxuser \\
\t-x liblinphone-tutorials/hello-world/hello-world.xcodeproj/*.mode1v3
pull-transifex:
\ttx pull -af
push-transifex:
\t./Tools/i18n_generate_strings_files.sh && \\
\ttx push -s -f --no-interactive
zipres:
\t@tar -czf ios_assets.tar.gz Resources iTunesArtwork
{arch_targets}
help-prepare-options:
\t@echo "prepare.py was previously executed with the following options:"
\t@echo " {options}"
help: help-prepare-options
\t@echo ""
\t@echo "(please read the README.md file first)"
\t@echo ""
\t@echo "Available architectures: {archs}"
\t@echo ""
\t@echo "Available targets:"
\t@echo ""
\t@echo " * all or build: builds all architectures and creates the liblinphone SDK"
\t@echo " * sdk: creates the liblinphone SDK. Use this only after a full build"
\t@echo " * zipsdk: generates a ZIP archive of liblinphone-sdk/apple-darwin containing the SDK. Use this only after SDK is built."
\t@echo " * zipres: creates a tar.gz file with all the resources (images)"
\t@echo ""
""".format(archs=' '.join(platforms), arch_opts='|'.join(platforms),
first_arch=platforms[0], options=' '.join(sys.argv),
arch_targets=arch_targets,
multiarch=multiarch, generator=generator)
f = open('Makefile', 'w')
f.write(makefile)
f.close()
def main():
preparator = IOSPreparator()
preparator.parse_args()
if preparator.check_environment() != 0:
preparator.show_environment_errors()
return 1
preparator.install_git_hook()
return preparator.run()
if __name__ == "__main__":
sys.exit(main())