Skip to content

Commit 5339f96

Browse files
committed
build: limit Android Darwin host make rules
The Android make generator needs Darwin-specific host archive and link commands when cross-compiling on macOS. Keep the default Android make command template unchanged and select the Darwin host variant only while generating Android Makefiles on macOS. Signed-off-by: moluopro <[email protected]>
1 parent fcf1522 commit 5339f96

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

  • tools/gyp/pylib/gyp/generator

tools/gyp/pylib/gyp/generator/make.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ def CalculateGeneratorInputInfo(params):
249249
define create_thin_archive
250250
rm -f $(1) $(OBJ_FILE_LIST); mkdir -p `dirname $(1)`
251251
$(call write-to-file,$(1).$(OBJ_FILE_LIST),$(filter %.o,$(2)))
252-
if [ "$(TOOLSET)" = "host" ] && [ "$$(uname -s)" = "Darwin" ]; then \
253-
$(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST); \
254-
else \
255-
$(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST); \
256-
fi
252+
$(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)
257253
endef
258254
259255
# Due to circular dependencies between libraries :(, we wrap the
@@ -262,7 +258,7 @@ def CalculateGeneratorInputInfo(params):
262258
quiet_cmd_link = LINK($(TOOLSET)) $@
263259
quiet_cmd_link_host = LINK($(TOOLSET)) $@
264260
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
265-
cmd_link_host = if [ "$$(uname -s)" = "Darwin" ]; then $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS); else $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS); fi
261+
cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
266262
267263
# Other shared-object link notes:
268264
# - Set SONAME to the library filename so our binaries don't reference
@@ -276,6 +272,21 @@ def CalculateGeneratorInputInfo(params):
276272
cmd_solink_module_host = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
277273
""" # noqa: E501
278274

275+
LINK_COMMANDS_ANDROID_DARWIN_HOST = LINK_COMMANDS_ANDROID.replace(
276+
"$(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST)",
277+
'if [ "$(TOOLSET)" = "host" ]; then \\\n'
278+
" $(AR.$(TOOLSET)) crs $(1) @$(1).$(OBJ_FILE_LIST); \\\n"
279+
" else \\\n"
280+
" $(AR.$(TOOLSET)) crsT $(1) @$(1).$(OBJ_FILE_LIST); \\\n"
281+
" fi",
282+
).replace(
283+
"cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) "
284+
"$(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) "
285+
"-Wl,--end-group $(LIBS)",
286+
"cmd_link_host = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) "
287+
"$(LDFLAGS.$(TOOLSET)) -o $@ $(LD_INPUTS) $(LIBS)",
288+
)
289+
279290

280291
LINK_COMMANDS_AIX = """\
281292
quiet_cmd_alink = AR($(TOOLSET)) $@
@@ -2522,7 +2533,10 @@ def CalculateMakefilePath(build_file, base_name):
25222533
}
25232534
)
25242535
elif flavor == "android":
2525-
header_params.update({"link_commands": LINK_COMMANDS_ANDROID})
2536+
link_commands = LINK_COMMANDS_ANDROID
2537+
if sys.platform == "darwin":
2538+
link_commands = LINK_COMMANDS_ANDROID_DARWIN_HOST
2539+
header_params.update({"link_commands": link_commands})
25262540
elif flavor == "zos":
25272541
copy_archive_arguments = "-fPR"
25282542
CC_target = GetEnvironFallback(("CC_target", "CC"), "njsc")

0 commit comments

Comments
 (0)