-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.mk
More file actions
289 lines (238 loc) · 6.38 KB
/
Copy pathapp.mk
File metadata and controls
289 lines (238 loc) · 6.38 KB
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
build-arch = $(shell uname -m)
ifeq ($(build-arch),i586)
build-arch = i386
endif
ifeq ($(build-arch),i686)
build-arch = i386
endif
ifeq ('$(build-arch)','Power Macintosh')
build-arch = powerpc
endif
build-platform = \
$(shell uname -s | tr [:upper:] [:lower:] \
| sed 's/^mingw32.*$$/mingw32/' \
| sed 's/^cygwin.*$$/cygwin/')
arch = $(build-arch)
platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))
mode = fast
process = compile
ifneq ($(process),compile)
options := -$(process)
endif
ifneq ($(mode),fast)
options := $(options)-$(mode)
endif
ifeq ($(bootimage),true)
options := $(options)-bootimage
endif
ifeq ($(heapdump),true)
options := $(options)-heapdump
endif
root = ..
base = $(shell pwd)
vm = $(root)/avian
swt = $(root)/swt-3.5/$(platform)-$(arch)/swt.jar
src = src
bld = build/$(platform)-$(arch)$(options)/$(name)
stage1 = $(bld)/stage1
stage2 = $(bld)/stage2
vm-bld = $(vm)/build/$(platform)-$(arch)$(options)
ifneq ($(platform),darwin)
ifeq ($(arch),i386)
mflag = -m32
endif
ifeq ($(arch),x86_64)
mflag = -m64
endif
endif
cxx = g++ $(mflag)
cc = gcc $(mflag)
dlltool = dlltool
objcopy = objcopy
proguard = $(root)/proguard4.4/lib/proguard.jar
java = "$(JAVA_HOME)/bin/java"
javac = "$(JAVA_HOME)/bin/javac"
jar = "$(JAVA_HOME)/bin/jar"
converter = $(vm-bld)/binaryToObject
ifeq ($(mode),fast)
upx = upx
strip = strip --strip-all
else
upx = :
strip = :
endif
so-prefix = lib
so-suffix = .so
pointer-size = 8
asm = x86
common-cflags = -Wextra -Werror -Wunused-parameter -Winit-self \
-I"$(JAVA_HOME)/include" \
-fno-rtti -fno-exceptions \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DMAIN_CLASS=\"$(main-class)\"
cflags = $(common-cflags) \
-I"$(JAVA_HOME)/include/linux" \
-fvisibility=hidden -fPIC
common-lflags = -lz -lm -lstdc++
lflags = $(common-lflags) -rdynamic -lpthread -ldl
ifeq ($(arch),i386)
pointer-size = 4
endif
ifeq ($(arch),powerpc)
asm = powerpc
pointer-size = 4
endif
ifeq ($(platform),darwin)
ifneq ($(arch),x86_64)
# SWT >= 3.5 only works on OS X 10.5 and above, so we use 3.4 instead
swt = $(root)/swt-3.4/$(platform)-$(arch)/swt.jar
endif
cflags = $(common-cflags) -Wno-deprecated -Wno-deprecated-declarations
lflags = $(common-lflags) -ldl -framework CoreFoundation -framework Carbon
upx = :
strip = strip -S -x
ifeq ($(arch),powerpc)
cross-flags := -mmacosx-version-min=10.4 -arch ppc
endif
ifeq ($(arch),i386)
cross-flags := -mmacosx-version-min=10.4 -arch i386
endif
so-suffix = .jnilib
ifdef proguard
proguard += -dontusemixedcaseclassnames
endif
endif
ifeq ($(platform),windows)
inc = "$(root)/win32/include"
lib = "$(root)/win32/lib"
so-prefix =
so-suffix = .dll
exe-suffix = .exe
ifeq ($(build-platform),windows)
# Really need to just do nothing here
build-cflags = $(common-cflags) \
-I"$(JAVA_HOME)/include/win32" -I$(src) -mthreads
proguard += -dontusemixedcaseclassnames
else
cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc
dlltool = i586-mingw32msvc-dlltool
objcopy = i586-mingw32msvc-objcopy
endif
cflags = -I$(inc) $(common-cflags)
lflags = -L$(lib) $(common-lflags) -lws2_32 -Wl,--kill-at -mwindows
ifeq ($(arch),x86_64)
wine-include-flags =
upx = :
cxx = x86_64-w64-mingw32-g++
cc = x86_64-w64-mingw32-gcc
dlltool = x86_64-w64-mingw32-dlltool
ar = x86_64-w64-mingw32-ar
ranlib = x86_64-w64-mingw32-ranlib
restool = x86_64-w64-mingw32-windres
strip = x86_64-w64-mingw32-strip --strip-all
inc = "$(root)/win64/include"
lib = "$(root)/win64/lib"
lflags = -Wl,--as-needed -L$(lib) $(common-lflags) \
-lws2_32 -lversion -lpsapi -lz -ljpeg -lole32 -lurlmon -luuid \
-lwininet -mwindows
endif
endif
ifeq ($(mode),debug)
opt = -O0 -g3
endif
ifeq ($(mode),debug-fast)
opt = -O0 -g3 -DNDEBUG
endif
ifeq ($(mode),fast)
opt = -O3 -g3 -DNDEBUG
endif
ifdef cross-flags
cc := $(cc) $(cross-flags)
cxx := $(cxx) $(cross-flags)
endif
cflags += $(opt)
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x)))
classes = $(call java-classes,$(sources),$(source-directory),$(stage1))
cpps = $(src)/main.cpp
objects = $(call cpp-objects,$(cpps),$(src),$(bld))
jar-object = $(bld)/jar.o
vm-lib = $(vm-bld)/libavian.a
executable = $(bld)/$(name)${exe-suffix}
properties = $(stage1)/properties.d
data = $(stage1)/data.d
jars = $(stage1)/jars.d
vm-classes = $(stage1)/vm-classes.d
vm-objects = $(bld)/vm-objects.d
define make-vm
(cd $(vm) && unset MAKEFLAGS && \
make mode=$(mode) process=$(process) arch=$(arch) platform=$(platform))
cd "$(base)"
endef
## targets ####################################################################
.PHONY: build
build: $(executable)
$(classes): $(sources)
$(make-vm)
@rm -rf $(stage1)
@mkdir -p $(stage1)
$(javac) -d $(stage1) -sourcepath $(src) \
-cp $(swt) -bootclasspath $(vm)/build/classpath $(sources)
$(properties): $(classes)
ifdef properties-file
cp $(properties-file) $(stage1)
endif
@touch $(@)
$(data): $(classes)
ifdef data-files
@mkdir -p $(stage1)/$(data-directory)
cp $(data-files) $(stage1)/$(data-directory)
endif
@touch $(@)
$(vm-classes): $(classes)
cp -r $(vm)/build/classpath/* $(stage1)
@touch $(@)
$(jars): $(classes)
(cd $(stage1) && $(jar) xf "$(base)/$(swt)")
rm -r $(stage1)/org/eclipse/swt/awt
@touch $(@)
$(bld)/boot.jar: \
$(classes) $(properties) $(data) $(jars) $(vm-classes)
@mkdir -p $(dir $(bld)/tmp)
ifdef proguard
$(java) -jar $(proguard) \
-injars $(stage1) \
-outjars $(stage2) \
-printmapping $(bld)/mapping.txt \
-include $(vm)/vm.pro \
-include swt.pro \
-keep class $(main-class) \{ \
public static void 'main(java.lang.String[]);' \
\}
($(jar) c0f "$(@)" -C $(stage2) .)
else
($(jar) c0f "$(@)" -C $(stage1) .)
endif
$(jar-object): $(bld)/boot.jar
$(converter) $(<) $(@) _binary_boot_jar_start \
_binary_boot_jar_end $(platform) $(arch)
$(bld)/%.o: $(src)/%.cpp
@mkdir -p $(dir $(@))
$(cxx) $(cflags) -c $(<) -o $(@)
$(vm-lib):
$(make-vm)
$(vm-objects): $(vm-lib)
$(make-vm)
@mkdir -p $(bld)/vm
(cd $(bld)/vm && ar x "$(base)/$(vm-lib)")
$(executable): $(jar-object) $(objects) $(vm-objects)
ifeq ($(platform),windows)
$(dlltool) -z $(@).def $(objects) $(bld)/vm/*
$(dlltool) -d $(@).def -e $(@).exp
$(cc) $(@).exp $(jar-object) $(objects) $(hook-lib) $(bld)/vm/*.o \
$(lflags) -o $(@)
else
$(cc) $(jar-object) $(objects) $(bld)/vm/*.o $(lflags) -o $(@)
endif
$(strip) $(@)
$(upx) $(@)