mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Allow cross-compilation of Android version on Mac
When compiling for Android (COMP=ndk) on macOS, the build fails because the NDK's LLVM toolchain does not recognize the macOS-specific flags -mdynamic-no-pic and -mmacosx-version-min. This PR wraps these flags with ifneq ($(COMP),ndk) condition to skip them during Android cross-compilation. Please squash and merge this PR. closes https://github.com/official-stockfish/Stockfish/pull/6927 No functional change
This commit is contained in:
@@ -186,6 +186,7 @@ Moez Jellouli (MJZ1977)
|
|||||||
Mohammed Li (tthsqe12)
|
Mohammed Li (tthsqe12)
|
||||||
Mukhammedali Beriktassuly (Berektassuly)
|
Mukhammedali Beriktassuly (Berektassuly)
|
||||||
Muzhen J (XInTheDark)
|
Muzhen J (XInTheDark)
|
||||||
|
Mafanwei
|
||||||
Nathan Rugg (nmrugg)
|
Nathan Rugg (nmrugg)
|
||||||
Nguyen Pham (nguyenpham)
|
Nguyen Pham (nguyenpham)
|
||||||
Nicklas Persson (NicklasPersson)
|
Nicklas Persson (NicklasPersson)
|
||||||
|
|||||||
+20
-13
@@ -25,6 +25,13 @@ ifeq ($(KERNEL),Linux)
|
|||||||
OS := $(shell uname -o)
|
OS := $(shell uname -o)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
### Target operating system (may differ from KERNEL when cross-compiling)
|
||||||
|
TARGET_KERNEL := $(KERNEL)
|
||||||
|
ifeq ($(COMP),ndk)
|
||||||
|
TARGET_KERNEL := Linux
|
||||||
|
OS := Android
|
||||||
|
endif
|
||||||
|
|
||||||
### Command prefix to run the built executable (e.g. wine, sde, qemu)
|
### Command prefix to run the built executable (e.g. wine, sde, qemu)
|
||||||
### Backward compatible alias: WINE_PATH (deprecated)
|
### Backward compatible alias: WINE_PATH (deprecated)
|
||||||
ifneq ($(strip $(WINE_PATH)),)
|
ifneq ($(strip $(WINE_PATH)),)
|
||||||
@@ -516,7 +523,7 @@ ifeq ($(COMP),gcc)
|
|||||||
LDFLAGS += -latomic
|
LDFLAGS += -latomic
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(KERNEL),Darwin)
|
ifneq ($(TARGET_KERNEL),Darwin)
|
||||||
ifneq ($(arch),wasm32)
|
ifneq ($(arch),wasm32)
|
||||||
LDFLAGS += -Wl,--no-as-needed
|
LDFLAGS += -Wl,--no-as-needed
|
||||||
endif
|
endif
|
||||||
@@ -563,7 +570,7 @@ ifeq ($(COMP),clang)
|
|||||||
CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
|
CXXFLAGS += -pedantic -Wextra -Wshadow -Wmissing-prototypes \
|
||||||
-Wconditional-uninitialized -flax-vector-conversions=none -fconstexpr-steps=500000000
|
-Wconditional-uninitialized -flax-vector-conversions=none -fconstexpr-steps=500000000
|
||||||
|
|
||||||
ifeq ($(filter $(KERNEL),Darwin OpenBSD FreeBSD),)
|
ifeq ($(filter $(TARGET_KERNEL),Darwin OpenBSD FreeBSD),)
|
||||||
ifeq ($(target_windows),)
|
ifeq ($(target_windows),)
|
||||||
ifneq ($(RTLIB),compiler-rt)
|
ifneq ($(RTLIB),compiler-rt)
|
||||||
LDFLAGS += -latomic
|
LDFLAGS += -latomic
|
||||||
@@ -587,7 +594,7 @@ ifeq ($(COMP),clang)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
mac_target_flags := -mmacosx-version-min=10.15
|
mac_target_flags := -mmacosx-version-min=10.15
|
||||||
ifneq ($(arch),any)
|
ifneq ($(arch),any)
|
||||||
mac_target_flags += -arch $(arch)
|
mac_target_flags += -arch $(arch)
|
||||||
@@ -657,7 +664,7 @@ else ifeq ($(comp),clang)
|
|||||||
else
|
else
|
||||||
profile_make = gcc-profile-make
|
profile_make = gcc-profile-make
|
||||||
profile_use = gcc-profile-use
|
profile_use = gcc-profile-use
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
EXTRAPROFILEFLAGS = -fvisibility=hidden
|
EXTRAPROFILEFLAGS = -fvisibility=hidden
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -691,7 +698,7 @@ ifneq ($(comp),mingw)
|
|||||||
add_lrt = no
|
add_lrt = no
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
add_lrt = no
|
add_lrt = no
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -729,7 +736,7 @@ ifeq ($(optimize),yes)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
ifeq ($(comp),$(filter $(comp),clang icx))
|
ifeq ($(comp),$(filter $(comp),clang icx))
|
||||||
CXXFLAGS += -mdynamic-no-pic
|
CXXFLAGS += -mdynamic-no-pic
|
||||||
endif
|
endif
|
||||||
@@ -850,7 +857,7 @@ endif
|
|||||||
|
|
||||||
ifeq ($(neon),yes)
|
ifeq ($(neon),yes)
|
||||||
CXXFLAGS += -DUSE_NEON=$(arm_version)
|
CXXFLAGS += -DUSE_NEON=$(arm_version)
|
||||||
ifeq ($(KERNEL),Linux)
|
ifeq ($(TARGET_KERNEL),Linux)
|
||||||
ifneq ($(COMP),ndk)
|
ifneq ($(COMP),ndk)
|
||||||
ifneq ($(arch),armv8)
|
ifneq ($(arch),armv8)
|
||||||
CXXFLAGS += -mfpu=neon
|
CXXFLAGS += -mfpu=neon
|
||||||
@@ -930,7 +937,7 @@ endif
|
|||||||
ifeq ($(optimize),yes)
|
ifeq ($(optimize),yes)
|
||||||
ifeq ($(debug),no)
|
ifeq ($(debug),no)
|
||||||
ifeq ($(arch),wasm32)
|
ifeq ($(arch),wasm32)
|
||||||
else ifneq ($(KERNEL),Darwin)
|
else ifneq ($(TARGET_KERNEL),Darwin)
|
||||||
LLD_BIN := $(shell command -v ld.lld 2>/dev/null)
|
LLD_BIN := $(shell command -v ld.lld 2>/dev/null)
|
||||||
ifeq ($(LLD_BIN),)
|
ifeq ($(LLD_BIN),)
|
||||||
LLD_BIN := $(shell command -v lld 2>/dev/null)
|
LLD_BIN := $(shell command -v lld 2>/dev/null)
|
||||||
@@ -1123,7 +1130,7 @@ macos-lipo:
|
|||||||
@rm -f $(EXE)-x86_64 $(EXE)-arm64
|
@rm -f $(EXE)-x86_64 $(EXE)-arm64
|
||||||
@echo "Universal macOS binary built: $(EXE)"
|
@echo "Universal macOS binary built: $(EXE)"
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
# Apple uses ld64 which doesn't have --save-temps
|
# Apple uses ld64 which doesn't have --save-temps
|
||||||
LTO_OBJ_SUFFIX := .lto.o
|
LTO_OBJ_SUFFIX := .lto.o
|
||||||
SAVE_TEMPS := -Wl,-object_path_lto,stockfish.lto.o
|
SAVE_TEMPS := -Wl,-object_path_lto,stockfish.lto.o
|
||||||
@@ -1394,9 +1401,9 @@ ARCH_OBJS := $(TEMP_DIR)/$(BASELINE_ARCH)/stockfish.o \
|
|||||||
UNIVERSAL_FINAL_FLAGS := -fno-exceptions -Os \
|
UNIVERSAL_FINAL_FLAGS := -fno-exceptions -Os \
|
||||||
-Wno-c++26-extensions -Wno-c23-extensions # suppress #embed warnings
|
-Wno-c++26-extensions -Wno-c23-extensions # suppress #embed warnings
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
UNIVERSAL_FINAL_FLAGS += $(mac_target_flags)
|
UNIVERSAL_FINAL_FLAGS += $(mac_target_flags)
|
||||||
else ifeq ($(KERNEL),Linux)
|
else ifeq ($(TARGET_KERNEL),Linux)
|
||||||
UNIVERSAL_FINAL_FLAGS += -static-libstdc++ -static-libgcc
|
UNIVERSAL_FINAL_FLAGS += -static-libstdc++ -static-libgcc
|
||||||
ifeq ($(COMP),ndk)
|
ifeq ($(COMP),ndk)
|
||||||
UNIVERSAL_FINAL_FLAGS += -static
|
UNIVERSAL_FINAL_FLAGS += -static
|
||||||
@@ -1419,7 +1426,7 @@ arch-mangled = _ZN$(shell printf %s '$(call arch-namespace,$(1))' | wc -c | t
|
|||||||
# (Mach-O section names are restricted to <=16 chars, hence this naming scheme)
|
# (Mach-O section names are restricted to <=16 chars, hence this naming scheme)
|
||||||
arch-mac-section = _i_$(subst -,_,$(patsubst x86-64,,$(patsubst x86-64-%,%,$(1))))
|
arch-mac-section = _i_$(subst -,_,$(patsubst x86-64,,$(patsubst x86-64-%,%,$(1))))
|
||||||
|
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
arch-defmain = -Wl,-alias,_$(call arch-mangled,$(1)),_main
|
arch-defmain = -Wl,-alias,_$(call arch-mangled,$(1)),_main
|
||||||
# lld-link, used on Windows+clang, doesn't accept --defsym, so
|
# lld-link, used on Windows+clang, doesn't accept --defsym, so
|
||||||
# we define main directly in main.cpp instead and delete it later.
|
# we define main directly in main.cpp instead and delete it later.
|
||||||
@@ -1482,7 +1489,7 @@ $(TEMP_DIR)/%/stockfish.o: $(TEMP_DIR)/%/.setup $(NNUE_EMBED_OBJ) $(NET_SENTINEL
|
|||||||
$(MAKE) -C $(TEMP_DIR)/$* $(UOBJ_TGT) \
|
$(MAKE) -C $(TEMP_DIR)/$* $(UOBJ_TGT) \
|
||||||
ARCH=$* CXX=$(CXX) COMP=$(COMP) \
|
ARCH=$* CXX=$(CXX) COMP=$(COMP) \
|
||||||
NNUE_EMBED_OBJ=$(NNUE_EMBED_OBJ)
|
NNUE_EMBED_OBJ=$(NNUE_EMBED_OBJ)
|
||||||
ifeq ($(KERNEL),Darwin)
|
ifeq ($(TARGET_KERNEL),Darwin)
|
||||||
# Rename the initializer section
|
# Rename the initializer section
|
||||||
ld -r -rename_section __DATA __mod_init_func __DATA $(call arch-mac-section,$*) $@ -o $@.tmp
|
ld -r -rename_section __DATA __mod_init_func __DATA $(call arch-mac-section,$*) $@ -o $@.tmp
|
||||||
mv $@.tmp $@
|
mv $@.tmp $@
|
||||||
|
|||||||
Reference in New Issue
Block a user