Repository navigation
Expand file tree
/
Copy pathcommon.mk
More file actions
296 lines (257 loc) · 10.9 KB
/
Copy pathcommon.mk
File metadata and controls
296 lines (257 loc) · 10.9 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
290
291
292
293
294
295
296
# Common variables for the various subprojects of j2objc.
#
# The including makefile must define the variable J2OBJC_ROOT.
#
# Author: Keith Stanger
DIST_DIR = $(J2OBJC_ROOT)/dist
DIST_INCLUDE_DIR = $(DIST_DIR)/include
DIST_LIB_DIR = $(DIST_DIR)/lib
DIST_JAR_DIR = $(DIST_LIB_DIR)
DIST_LICENSE_DIR = $(DIST_DIR)/third_party_licenses
DIST_FRAMEWORK_DIR = $(DIST_DIR)/frameworks
# Release version string used by j2objc and cycle_finder's -version flag.
ifndef J2OBJC_VERSION
CURR_DATE = $(shell date "+%Y/%m/%d")
J2OBJC_VERSION = $(USER)-$(CURR_DATE)
endif
ifdef CONFIGURATION_BUILD_DIR
XCODE_INCLUDE_DIR = $(CONFIGURATION_BUILD_DIR)/Headers
endif
BUILD_DIR_NAME = build_result
BUILD_DIR = $(CURDIR)/$(BUILD_DIR_NAME)
ifdef CONFIGURATION_BUILD_DIR
ARCH_BUILD_DIR = $(TARGET_TEMP_DIR)
ARCH_BIN_DIR = $(CONFIGURATION_BUILD_DIR)
ARCH_LIB_DIR = $(CONFIGURATION_BUILD_DIR)
ARCH_INCLUDE_DIR = $(CONFIGURATION_BUILD_DIR)/Headers
else
ARCH_BUILD_DIR = $(BUILD_DIR)
ARCH_BIN_DIR = $(DIST_DIR)
ARCH_LIB_DIR = $(DIST_LIB_DIR)
ARCH_LIB_MACOSX_DIR = $(DIST_LIB_MACOSX_DIR)
ARCH_LIB_MAC_CATALYST_DIR = $(DIST_LIB_MAC_CATALYST_DIR)
ARCH_LIB_SIMULATOR_DIR = $(ARCH_LIB_SIMULATOR_DIR)
ARCH_INCLUDE_DIR = $(DIST_INCLUDE_DIR)
endif
# iPhone-specific library dirs, used for xcframework.
ARCH_BUILD_IPHONE_DIR = $(ARCH_BUILD_DIR)/iphone
# iPhone simulator library dirs.
ARCH_BUILD_SIMULATOR_DIR = $(ARCH_BUILD_DIR)/simulator
ARCH_LIB_SIMULATOR_DIR = $(ARCH_LIB_DIR)/simulator
DIST_LIB_SIMULATOR_DIR = $(DIST_LIB_DIR)/simulator
# Macosx library dirs.
ARCH_BUILD_MACOSX_DIR = $(ARCH_BUILD_DIR)/macosx
ARCH_LIB_MACOSX_DIR = $(ARCH_LIB_DIR)/macosx
DIST_LIB_MACOSX_DIR = $(DIST_LIB_DIR)/macosx
# Watchos library dirs.
ARCH_BUILD_WATCH_DIR = $(ARCH_BUILD_DIR)/watchos
ARCH_LIB_WATCH_DIR = $(ARCH_LIB_DIR)/watchos
DIST_LIB_WATCH_DIR = $(DIST_LIB_DIR)/watchos
# AppleWatch simulator library dirs.
ARCH_BUILD_WATCHSIMULATOR_DIR = $(ARCH_BUILD_DIR)/watchsimulator
ARCH_LIB_WATCHSIMULATOR_DIR = $(ARCH_LIB_DIR)/watchsimulator
DIST_LIB_WATCHSIMULATOR_DIR = $(DIST_LIB_DIR)/watchsimulator
# Appletv library dirs.
ARCH_BUILD_TV_DIR = $(ARCH_BUILD_DIR)/appletvos
ARCH_LIB_TV_DIR = $(ARCH_LIB_DIR)/appletvos
DIST_LIB_TV_DIR = $(DIST_LIB_DIR)/appletvos
# Mac Catalyst library dirs.
ARCH_BUILD_MAC_CATALYST_DIR = $(ARCH_BUILD_DIR)/maccatalyst
ARCH_LIB_MAC_CATALYST_DIR = $(ARCH_LIB_DIR)/maccatalyst
DIST_LIB_MAC_CATALYST_DIR = $(DIST_LIB_DIR)/maccatalyst
ifndef GEN_OBJC_DIR
GEN_OBJC_DIR = $(BUILD_DIR)/objc
endif
ifndef GEN_JAVA_DIR
GEN_JAVA_DIR = $(BUILD_DIR)/java
endif
TVOS_AVAILABLE = \
$(shell if xcodebuild -version -sdk appletvos >/dev/null 2>&1; \
then echo "YES"; else echo "NO"; fi)
MACOSX64_AVAILABLE = \
$(shell xcodebuild -version | grep '^Xcode ' | grep -Eo '[0-9\.]+' | \
awk '{ split($$0, v, "."); print ((v[1] == 12 && v[2] >= 2) || v[1] > 12) ? "YES" : "NO"; }')
ifndef J2OBJC_ARCHS
ifdef ENV_J2OBJC_ARCHS
# The env command cannot forward variables with spaces in them.
J2OBJC_ARCHS = $(subst _, ,$(ENV_J2OBJC_ARCHS))
else
# 32bit iPhone archs are no longer built by default. To build a release
# with them, define J2OBJC_ARCHS with "iphone" and "simulator" included.
J2OBJC_ARCHS = macosx iphone64 iphone64e watchosv7k watchos64 watchsimulator watchsimulator64 \
simulator simulator64 maccatalyst
ifeq ($(TVOS_AVAILABLE), YES)
J2OBJC_ARCHS += appletvos appletvsimulator
endif
ifeq ($(MACOSX64_AVAILABLE), YES)
J2OBJC_ARCHS += macosx64 maccatalyst64
endif
endif
endif
export J2OBJC_ARCHS
# xcrun finds a specified tool in the current SDK /usr/bin directory.
XCRUN := $(shell if test -f /usr/bin/xcrun; then echo xcrun; else echo ""; fi)
# xcrun can fail when run concurrently, so we find all the tools up-front.
ifneq ($(XCRUN),)
MAKE := $(shell xcrun --find make)
CLANG := $(shell xcrun --find clang)
LIBTOOL := $(shell xcrun --find libtool)
LIPO := $(shell xcrun --find lipo)
else
MAKE = make
CLANG = clang
LIBTOOL = libtool
LIPO = lipo
endif
# The following test returns true on Linux or with GNU tools installed,
# otherwise false on macOS which uses the BSD version.
ifeq ($(shell mktemp --version >/dev/null 2>&1 && echo GNU || echo BSD), GNU)
MKTEMP_CMD = mktemp -d --tmpdir $(MKTEMP_DIR).XXXXXX
else
MKTEMP_CMD = mktemp -d -t $(MKTEMP_DIR)
endif
ifndef CONFIGURATION_BUILD_DIR
# Determine this makefile's path.
SYSROOT_SCRIPT := $(J2OBJC_ROOT)/scripts/sysroot_path.sh
SDKROOT := $(shell bash ${SYSROOT_SCRIPT})
endif
SDK_FLAGS = -isysroot $(SDKROOT)
# Enable zeroing weak references.
OBJCFLAGS += -fobjc-weak
ifeq ($(DEBUGGING_SYMBOLS), YES)
# Enable when it's decided to distribute JRE with Java source debugging.
# J2OBJC_DEBUGFLAGS = -g
DEBUGFLAGS = -g
endif
ifdef GCC_OPTIMIZATION_LEVEL
OPTIMIZATION_LEVEL = $(GCC_OPTIMIZATION_LEVEL)
endif
ifndef OPTIMIZATION_LEVEL
ifdef DEBUG
OPTIMIZATION_LEVEL = 0 # None
else
OPTIMIZATION_LEVEL = s # Fastest, smallest
endif
endif
DEBUGFLAGS := $(DEBUGFLAGS) -O$(OPTIMIZATION_LEVEL)
CC_WARNINGS = -Wall -Werror -Wshorten-64-to-32 -Wimplicit-function-declaration \
-Wmissing-field-initializers -Wduplicate-method-match -Wno-unused-variable \
-Wno-nullability-completeness
# Specify flag if clang version 13.1 or greater. This is necessary because that
# version added a new warning that needs to be suppressed, and older versions
# fail because it doesn't recognize the suppression flag.
CLANG_13_1_MINIMUM = $(shell $(CLANG) --version | \
awk '/^Apple/ { split($$4, arr, "."); print ((arr[1] == 13 && arr[2] >= 1) || arr[1] > 13) ? "YES" : "NO"; }')
ifeq ("$(CLANG_13_1_MINIMUM)", "YES")
CC_WARNINGS += -Wno-unused-but-set-variable
endif
ifdef GCC_PREPROCESSOR_DEFINITIONS
DEBUGFLAGS += $(GCC_PREPROCESSOR_DEFINITIONS:%=-D%)
endif
TRANSLATOR_DEPS = $(DIST_DIR)/j2objc $(DIST_JAR_DIR)/j2objc.jar
ifndef JAVA_HOME
JAVA_HOME = $(shell /usr/libexec/java_home -v 21)
endif
JAVA = $(JAVA_HOME)/bin/java
JAVAC = $(JAVA_HOME)/bin/javac
ifneq (,$(findstring build 21, $(shell $(JAVA) -version 2>&1)))
JAVA_VERSION = 21
else ifneq (,$(findstring build 22, $(shell $(JAVA) -version 2>&1)))
JAVA_VERSION = 22
else ifneq (,$(findstring build 23, $(shell $(JAVA) -version 2>&1)))
JAVA_VERSION = 23
else ifneq (,$(findstring build 24, $(shell $(JAVA) -version 2>&1)))
JAVA_VERSION = 24
else ifneq (,$(findstring build 25, $(shell $(JAVA) -version 2>&1)))
JAVA_VERSION = 25
else
$(error JDK not supported. Please set JAVA_HOME to JDK 21 or higher.)
endif
# Used to build JRE module.
ifndef JAVA_PLATFORM
JAVA_PLATFORM := $(shell $(J2OBJC_ROOT)/scripts/detect-java-platform.sh)
endif
ifndef MEMORY_MODEL_FLAG
# Default memory model.
MEMORY_MODEL_FLAG = -use-reference-counting
endif
ifeq ("$(strip $(MEMORY_MODEL_FLAG))", "-use-arc")
CLANG_ENABLE_OBJC_ARC=YES
endif
TRANSLATOR_BUILD_FLAGS = \
-Xlint:unchecked -encoding UTF-8 -nowarn
TRANSLATOR_BUILD_FLAGS += \
--add-exports java.compiler/javax.lang.model.element=ALL-UNNAMED \
--add-exports java.compiler/javax.lang.model.type=ALL-UNNAMED \
--add-exports java.compiler/javax.lang.model.util=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
# Java flags needed to execute j2objc translator.
J2OBJC_JAVA_FLAGS += \
--add-exports java.compiler/javax.lang.model.element=ALL-UNNAMED \
--add-exports java.compiler/javax.lang.model.type=ALL-UNNAMED \
--add-exports java.compiler/javax.lang.model.util=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
comma=,
space=$(eval) $(eval)
# Flags for the static analyzer.
STATIC_ANALYZER_FLAGS = \
-Xclang -analyzer-checker -Xclang security.insecureAPI.UncheckedReturn \
-Xclang -analyzer-checker -Xclang security.insecureAPI.getpw \
-Xclang -analyzer-checker -Xclang security.insecureAPI.gets \
-Xclang -analyzer-checker -Xclang security.insecureAPI.mkstemp \
-Xclang -analyzer-checker -Xclang security.insecureAPI.mktemp \
-Xclang -analyzer-disable-checker -Xclang security.insecureAPI.rand \
-Xclang -analyzer-disable-checker -Xclang security.insecureAPI.strcpy \
-Xclang -analyzer-checker -Xclang security.insecureAPI.vfork \
--analyze
ifeq ($(findstring clean,$(notdir $(MAKECMDGOALS))),clean)
IS_CLEAN_GOAL = 1
endif
ifeq ($(findstring test,$(notdir $(MAKECMDGOALS))),test)
IS_TEST_GOAL = 1
endif
ifndef PROTOBUF_ROOT_DIR
ifndef IS_CLEAN_GOAL
check_protobuf_dir = $(error PROTOBUF_ROOT_DIR not defined)
endif
endif
PROTOBUF_LIB_PATH = $(PROTOBUF_ROOT_DIR)/lib
PROTOBUF_INCLUDE_PATH = $(PROTOBUF_ROOT_DIR)/include
PROTOBUF_BIN_PATH = $(PROTOBUF_ROOT_DIR)/bin
PROTOBUF_PROTOC = $(PROTOBUF_BIN_PATH)/protoc
# Avoid bash 'arument list too long' errors.
# See http://stackoverflow.com/questions/512567/create-a-file-from-a-large-makefile-variable
# TODO(iroth): When make 3.82 is available, use the $(file ...) function instead.
# See https://savannah.gnu.org/bugs/?35147
define long_list_to_file
@if [ -e $(1) ]; then rm $(1); fi
@files='$(wordlist 1, 499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 500, 999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 1000,1499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 1500,1999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 2000,2499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 2500,2999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 3000,3499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 3500,3999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 4000,4499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 4500,4999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 5000,5499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 5500,5999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 6000,6499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 6500,6999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 7000,7499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 7500,7999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 8000,8499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 8500,8999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 9000,9499,$(2))' && for i in $$files; do echo $$i >> $(1); done
@files='$(wordlist 9500,9999,$(2))' && for i in $$files; do echo $$i >> $(1); done
@if [ ! -e $(1) ]; then touch $(1); fi
endef