forked from ReadyTalk/hello-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
292 lines (240 loc) · 7.84 KB
/
makefile
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
platform = ios
mode = fast
process = compile
run-proguard = false
# Must match the deplyoment target setting of the Xcode project. Note that
# an iOS SDK 9 can target 8.0 and upwards. And this is common.
ios_deployment_target=8.0
# xcodebuild needs armv7, avian needs arm instead
arch-xcode-name = $(arch)
ifeq ($(sim),true)
target = iPhoneSimulator
sdk = iphonesimulator$(ios-version)
ifeq ($(arch),i386)
arch-flag = -arch i386
else
arch = x86_64
arch-flag = -arch x86_64
endif
release = Release-iphonesimulator
else
target = iPhoneOS
sdk = iphoneos$(ios-version)
ifeq ($(arch),arm)
arch-xcode-name = armv7
arch-flag = -arch armv7
else
arch = arm64
arch-flag = -arch arm64
endif
release = Release-iphoneos
endif
developer-dir := $(shell if test -d /Developer/Platforms/$(target).platform/Developer/SDKs; then echo /Developer; \
else echo /Applications/Xcode.app/Contents/Developer; fi)
sdk-dir = $(developer-dir)/Platforms/$(target).platform/Developer/SDKs
ios-version := $(shell \
if test -L $(sdk-dir)/$(target)9.1.sdk; then echo 9.1; \
elif test -L $(sdk-dir)/$(target)9.0.sdk; then echo 9.0; \
elif test -d $(sdk-dir)/$(target)8.3.sdk; then echo 8.3; \
elif test -d $(sdk-dir)/$(target)8.2.sdk; then echo 8.2; \
elif test -d $(sdk-dir)/$(target)8.1.sdk; then echo 8.1; \
elif test -d $(sdk-dir)/$(target)8.0.sdk; then echo 8.0; \
elif test -d $(sdk-dir)/$(target)7.1.sdk; then echo 7.1; \
elif test -d $(sdk-dir)/$(target)7.0.sdk; then echo 7.0; \
elif test -d $(sdk-dir)/$(target)6.1.sdk; then echo 6.1; \
elif test -d $(sdk-dir)/$(target)6.0.sdk; then echo 6.0; \
else echo; fi)
ifeq ($(ios-version),)
x := $(error "couldn't find SDK")
endif
cc = cc
javac = "$(JAVA_HOME)/bin/javac"
java = "$(JAVA_HOME)/bin/java"
jar = "$(JAVA_HOME)/bin/jar"
flags = -isysroot $(sdk-dir)/$(target)$(ios-version).sdk \
$(arch-flag)
# mios-version-min version now required. See:
# http://www.openradar.me/21724015
cflags = $(flags) -D__IPHONE_OS_VERSION_MIN_REQUIRED=80000 -DRESOURCES \
-fobjc-abi-version=2 -fobjc-legacy-dispatch \
-I/System/Library/Frameworks/JavaVM.framework/Headers \
-mios-version-min=$(ios-version)
ifeq ($(mode),debug)
cflags += -O0 -g3
endif
ifeq ($(mode),debug-fast)
cflags += -O0 -g3 -DNDEBUG
endif
ifeq ($(mode),fast)
cflags += -O3 -g3 -DNDEBUG
endif
ifeq ($(mode),small)
cflags += -Os -g3 -DNDEBUG
endif
lflags = $(flags) -Xlinker -objc_abi_version -Xlinker 2 \
-framework Carbon -framework Foundation -lz
objects = \
build/boot.o \
build/hello.o
ifneq ($(mode),fast)
options := -$(mode)
endif
ifneq ($(lzma),)
options := $(options)-lzma
cflags += -DUSE_LZMA
bootimage-flags += -use-lzma
endif
ifeq ($(process),compile)
options := $(options)-bootimage
bootimage = bootimage=true
cflags += -DBOOT_IMAGE
objects += \
build/bootimage-bin.o \
build/codeimage-bin.o
else
options := $(options)-interpret
objects += \
build/boot-jar.o
endif
ifneq ($(openjdk),)
ifneq ($(openjdk-src),)
options := $(options)-openjdk-src
else
options := $(options)-openjdk
endif
proguard-flags += -include $(vm)/openjdk.pro
else
proguard-flags += -overloadaggressively
endif
ifneq ($(android),)
options := $(options)-android
android-archives = \
$(android)/external/icu4c/lib/libicui18n.a \
$(android)/external/icu4c/lib/libicuuc.a \
$(android)/external/icu4c/lib/libicudata.a \
$(android)/external/fdlibm/libfdm.a \
$(android)/external/expat/.libs/libexpat.a \
$(android)/openssl-upstream/libssl.a \
$(android)/openssl-upstream/libcrypto.a
classpath-lflags = $(android-archives) -lstdc++
proguard-flags += -include $(vm)/android.pro -dontoptimize -dontobfuscate
endif
ifeq ($(process),compile)
vm-targets = \
build/$(platform)-$(arch)$(options)/bootimage-generator \
build/$(platform)-$(arch)$(options)/binaryToObject/binaryToObject \
build/$(platform)-$(arch)$(options)/classpath.jar \
build/$(platform)-$(arch)$(options)/libavian.a
endif
xcode-build = hello/build
build = build
src = src
stage1 = $(build)/stage1
stage2 = $(build)/stage2
resources = $(build)/resources
vm = ../avian
vm-build = $(vm)/build/$(platform)-$(arch)$(options)
converter = $(vm-build)/binaryToObject/binaryToObject
bootimage-generator = $(vm-build)/bootimage-generator
proguard = ../proguard4.11/lib/proguard.jar
resources-object = $(build)/resources-jar.o
vm-objects-dep = $(build)/vm-objects.d
vm-classes-dep = $(build)/vm-classes.d
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x)))
main-class = Hello
all-javas := $(shell find $(src) -name '*.java')
all-properties := $(shell find $(src) -name '*.properties')
javas = $(src)/$(main-class).java
classes = $(call java-classes,$(javas),$(src),$(stage1))
bootimage-object = $(build)/bootimage-bin.o
codeimage-object = $(build)/codeimage-bin.o
boot-jar = $(build)/boot.jar
boot-object = $(build)/boot-jar.o
.PHONY: build
build: make-vm $(xcode-build)/$(release)/hello.app/hello
.PHONY: run
run: build
/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication $(xcode-build)/Release-iphonesimulator/hello.app
.PHONY: make-vm
make-vm:
(cd $(vm) && make arch=$(arch) platform=$(platform) sim=$(sim) process=$(process) \
"openjdk=$(openjdk)" "openjdk-src=$(openjdk-src)" $(bootimage) \
android=$(android) $(vm-targets))
.PHONY: xcode-build
xcode-build:
(cd hello && xcodebuild ARCHS=$(arch-xcode-name) ONLY_ACTIVE_ARCH=NO -sdk $(sdk) build)
$(classes): $(all-javas) $(all-properties)
@rm -rf $(stage1)
@mkdir -p $(stage1)
$(javac) -d $(stage1) -sourcepath $(src) \
-source 1.7 -target 1.7 \
-bootclasspath $(vm-build)/classpath $(javas)
cp $(all-properties) $(stage1)/
$(vm-objects-dep):
@mkdir -p $(build)/vm-objects
(wd=$$(pwd) && cd $(build)/vm-objects \
&& ar x $${wd}/$(vm-build)/libavian.a)
@touch $(@)
$(vm-classes-dep): $(classes)
cp -r $(vm-build)/classpath/* $(stage1)
@touch $(@)
$(build)/resources.jar: $(resources).d
wd=$$(pwd); cd $(resources) && jar cf $${wd}/$(build)/resources.jar *
$(build)/resources-jar.o: $(build)/resources.jar
$(converter) $(<) $(@) _binary_resources_jar_start \
_binary_resources_jar_end $(platform) $(arch) 1
$(xcode-build)/$(release)/hello.app/hello: $(build)/libhello.list xcode-build
$(build)/%.o: $(src)/%.m
@mkdir -p $(dir $(@))
$(cc) $(cflags) -c $(<) -o $(@)
$(build)/%.o: $(src)/%.c
@mkdir -p $(dir $(@))
$(cc) $(cflags) -c $(<) -o $(@)
$(stage2).d: $(classes) $(vm-classes-dep)
@mkdir -p $(dir $(@))
rm -rf $(stage2)
ifeq ($(run-proguard),true)
$(java) -jar $(proguard) \
-injars $(stage1) \
-outjars $(stage2) \
-dontusemixedcaseclassnames \
-dontwarn \
-dontoptimize \
-dontobfuscate \
@$(vm)/vm.pro \
$(proguard-flags) \
@hello.pro
else
mkdir -p $(stage2)
cp -r $(stage1)/* $(stage2)
endif
@touch $(@)
$(resources).d: $(stage2).d
@mkdir -p $(dir $(@))
rm -rf $(resources)
mkdir -p $(resources)
wd=$$(pwd); cd $(stage2) && find . -type f -not -name '*.class' \
| xargs tar cf - | tar xf - -C $${wd}/$(resources)
@touch $(@)
$(bootimage-object): $(stage2).d
$(bootimage-generator) -cp $(stage2) -bootimage $(@) \
-codeimage $(codeimage-object) $(bootimage-flags)
$(boot-jar): $(stage2).d
wd=$$(pwd); cd $(stage2) && jar cf $${wd}/$(boot-jar) *
$(boot-object): $(boot-jar)
$(converter) $(<) $(@) _binary_boot_jar_start \
_binary_boot_jar_end $(platform) $(arch) 1
$(build)/libhello.list: $(objects) $(vm-objects-dep) $(resources-object) \
$(android-archives)
@mkdir -p $(dir $(@))
rm -rf $(@)
mkdir -p $(build)/libhello
cp $(objects) $(build)/vm-objects/*.o $(resources-object) $(build)/libhello
(cd $(build)/libhello \
&& for x in $(android-archives); do ar x $${x}; done)
for x in $(build)/libhello/*; do echo ../$${x}; done > $(@)
$(build)/main: $(build)/main.o $(objects) $(vm-objects-dep)
$(cc) $(lflags) $(build)/main.o $(objects) $(build)/vm-objects/*.o -o $(@)
.PHONY: clean
clean:
rm -rf $(build) $(xcode-build)