-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
187 lines (151 loc) · 6.45 KB
/
fabfile.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
from fabric.api import local, lcd, task
import os
import os.path
import stupeflix.deployment.ios as ios
HERE = os.path.dirname(__file__)
DEVEL = os.path.abspath(os.path.join(HERE, ".."))
FRAMEWORK_PATH=os.path.join(HERE, "frameworks")
FRAMEWORK_NAME="fontatlas"
PROJECT_NAME = "fontatlas"
INCLUDES="include/*"
LIBRARIES = ["fontatlas"]
BUILD_SUFFIX="-lagunas"
FREETYPE_FLAGS="""-D FREETYPE_INCLUDE_DIR_freetype2:PATH=%(devel)s/freetype2-ios/include/freetype \
-D FREETYPE_INCLUDE_DIR_ft2build:PATH=%(devel)s/freetype2-ios/include \
-D FREETYPE_LIBRARY:PATH=%(devel)s/ios/apps/dependencies/lib/ios/libfreetype.a \
""" % {"devel": DEVEL}
PNG_FLAGS="""-D PNG_PNG_INCLUDE_DIR:PATH=%(devel)s/libpng-ios/include/ \
-D PNG_LIBRARIES:PATH=%(devel)s/libpng-ios/build/libpng.a \
""" % {"devel": DEVEL}
LIB_FLAGS = PNG_FLAGS + FREETYPE_FLAGS
COMMON_FLAGS="""-D CMAKE_C_COMPILER_FORCED:BOOL=ON \
-D CMAKE_CXX_COMPILER_FORCED:BOOL=ON \
-D FABFILE_COMPILATION:BOOL=ON \
"""
CMAKE_CXX_FLAGS=" -stdlib=libstdc++ -std=c++11 -ftree-vectorize -fvisibility-inlines-hidden -pipe -no-cpp-precomp "
def sdkroot_get(type):
if type == "iPhoneOS":
PRINT_INDEX=2
elif type == "iPhoneSimulator":
PRINT_INDEX=4
else:
raise Exception("Unknown type")
SDKVER = local("""xcodebuild -showsdks | fgrep %s | tail -n 1 | awk '{print $%d}'""" % (type.lower(), PRINT_INDEX), capture = True)
DEVROOT = local("xcode-select -print-path", capture = True) + "/Platforms/%s.platform/Developer" % type
return os.path.join(DEVROOT, "SDKs/%s%s.sdk" % (type, SDKVER))
DEVICE_FLAGS="""-D CMAKE_CXX_FLAGS:STRING=" %s -mno-thumb -arch arm64 -arch armv7 -arch armv7s -miphoneos-version-min=7.0 " \
-D CMAKE_OSX_SYSROOT:STRING=%s \
-D CMAKE_XCODE_ATTRIBUTE_CLANG_C_LIBRARY:STRING=libstdc++ \
-D CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY:STRING=libstdc++ \
-D CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD:STRING=c++11 \
-D CMAKE_XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD:STRING=c99 \
-D CMAKE_XCODE_ATTRIBUTE_CLANG_C_LIBRARY:STRING= \
-D CMAKE_DEBUG_POSTFIX:STRING='' \
-D CMAKE_OSX_ARCHITECTURES:STRING="arm64;armv7;armv7s" \
""" % (CMAKE_CXX_FLAGS, sdkroot_get("iPhoneOS"))
SIMULATOR_FLAGS="""-D CMAKE_CXX_FLAGS:STRING=" %s -arch i386 -arch x86_64 -mios-simulator-version-min=7.0" \
-D CMAKE_OSX_SYSROOT:STRING=%s \
-D CMAKE_OSX_ARCHITECTURES:STRING="i386" \
""" % (CMAKE_CXX_FLAGS, sdkroot_get("iPhoneSimulator"))
def run_cmake(BUILD):
flags = COMMON_FLAGS + LIB_FLAGS
if BUILD == "device":
flags += DEVICE_FLAGS
elif BUILD == "simulator":
flags += SIMULATOR_FLAGS
else:
raise Exception("BUILD %s not supported yet." % BUILD)
local("cmake -G Xcode %s .." % flags)
PATCH_SRC='"/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk"'
PATCH_DEST='iphoneos'
def replace_in_file(filename, src, dest):
s = open(filename).read()
s = s.replace(src, dest)
f = open(filename, "w")
f.write(s)
@task
def build(BUILD, release="true", reset="true", target=None):
if release.lower() == "true":
CONFIG_TYPE = "Release"
else:
CONFIG_TYPE= "Debug"
BUILD_TYPES = ["simulator", "device", "android"]
if BUILD not in BUILD_TYPES:
raise Exception("Unknown build type %s, should be in [%s]" % (build, ", ".join(BUILD_TYPES)))
if BUILD != "android":
BUILD_PREFIX="ios-"
else:
BUILD_PREFIX=""
BUILD_PATH = "build-%s%s%s" % (BUILD_PREFIX, BUILD, BUILD_SUFFIX)
local("mkdir -p %s" % BUILD_PATH)
if target == None:
TARGETS = LIBRARIES
else:
TARGETS = [target]
if reset == "true":
local("rm -fr %s" % BUILD_PATH)
local("mkdir -p %s" % BUILD_PATH)
with lcd(BUILD_PATH):
if target == None:
run_cmake(BUILD)
proj_file = os.path.join(BUILD_PATH, PROJECT_NAME + ".xcodeproj/project.pbxproj")
replace_in_file(proj_file, PATCH_SRC, PATCH_DEST)
replace_in_file(proj_file, "-miphoneos-version-min=3.1", "")
replace_in_file(proj_file, "-arch armv6", "")
for TARGET in TARGETS:
if BUILD == "simulator":
typeInfo = "-sdk iphonesimulator -arch i386 -arch x86_64"
elif BUILD == "device":
typeInfo = "-sdk iphoneos -arch arm64 -arch armv7 -arch armv7s "
if BUILD in ["simulator", "device"]:
local("xcodebuild -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=8 -project " + PROJECT_NAME + ".xcodeproj %s -configuration %s -target %s" % (typeInfo, CONFIG_TYPE, TARGET))
else:
local("%s/ndk-build -j 8 NDK_APPLICATION_MK=Application.mk" % NDK)
@task
def create_framework(platform="ios", release = "true"):
if release.lower() == "true":
CONFIG_TYPE = "Release"
else:
CONFIG_TYPE= "Debug"
if not platform == "ios":
raise Exception("Platform should be ios")
# Create structure
path = ios.create_framework_structure(FRAMEWORK_PATH, FRAMEWORK_NAME)
targets = ["device", "simulator"]
# Build big fatlib
command = "xcrun libtool -static -o "+os.path.join(path,"Versions/Current/",FRAMEWORK_NAME)
for name in LIBRARIES:
for target in targets:
src_name = "lib%s.a" % name
command += " " + os.path.join(HERE, "build-ios-%s%s/%s-iphone%s" % (target, BUILD_SUFFIX, CONFIG_TYPE, "os" if target == "device" else target), src_name)
local(command)
# Copy headers
local("cp -r %s %s" % (os.path.join(HERE, INCLUDES), os.path.join(path, "Headers")))
ios.finalize_framework_structure(FRAMEWORK_PATH, FRAMEWORK_NAME)
@task
def copy_framework(platform="ios", release = "release"):
if release.lower() == "true":
CONFIG_TYPE = "Release"
else:
CONFIG_TYPE= "Debug"
DESTS = ["../iosframeworks/frameworks/%s/" % CONFIG_TYPE]
for framework in [FRAMEWORK_NAME]:
frameworkPath = os.path.join(HERE, "frameworks/%s.framework" % framework)
for d in DESTS:
local("rm -fr %s " % os.path.join(HERE, d, "%s.framework" % framework))
local("rsync -av %s %s" % (frameworkPath, d))
@task
def all_(release = "true"):
build("device", release)
build("simulator", release)
create_framework(release = release)
copy_framework(release = release)
@task
def all(release = "true"):
all_("true")
all_("false")
@task
def clean():
build_path = "build-*%s" % (BUILD_SUFFIX,)
local("rm -rf %s" % build_path)
local("rm -rf %s" % FRAMEWORK_PATH)