From bddd38c45e1f1457e1435cd066036e98f54d7397 Mon Sep 17 00:00:00 2001 From: pschneider1968 <36973164+pschneider1968@users.noreply.github.com> Date: Fri, 21 Jan 2022 14:11:53 +0100 Subject: [PATCH] Fix Makefile for Android NDK cross-compile For cross-compiling to Android on windows, the Makefile needs some tweaks. Tested with Android NDK 23.1.7779620 and 21.4.7075529, using Windows 10 with clean MSYS2 environment (i.e. no MINGW/GCC/Clang toolchain in PATH) and Fedora 35, with build target: build ARCH=armv8 COMP=ndk The resulting binary runs fine inside Droidfish on my Samsung Galaxy Note20 Ultra and Samsung Galaxy Tab S7+ Other builds tested to exclude regressions: MINGW64/Clang64 build on Windows; MINGW64 cross build, native Clang and GCC builds on Fedora. wiki docs https://github.com/glinscott/fishtest/wiki/Cross-compiling-Stockfish-for-Android-on-Windows-and-Linux closes https://github.com/official-stockfish/Stockfish/pull/3901 No functional change --- src/Makefile | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5f3e739f..9666f138 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,7 +27,9 @@ endif ### Target Windows OS ifeq ($(OS),Windows_NT) - target_windows = yes + ifneq ($(COMP),ndk) + target_windows = yes + endif else ifeq ($(COMP),mingw) target_windows = yes ifeq ($(WINE_PATH),) @@ -451,11 +453,19 @@ ifeq ($(COMP),ndk) ifeq ($(arch),armv7) CXX=armv7a-linux-androideabi16-clang++ CXXFLAGS += -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon - STRIP=arm-linux-androideabi-strip + ifneq ($(shell which arm-linux-androideabi-strip 2>/dev/null),) + STRIP=arm-linux-androideabi-strip + else + STRIP=llvm-strip + endif endif ifeq ($(arch),armv8) CXX=aarch64-linux-android21-clang++ - STRIP=aarch64-linux-android-strip + ifneq ($(shell which aarch64-linux-android-strip 2>/dev/null),) + STRIP=aarch64-linux-android-strip + else + STRIP=llvm-strip + endif endif LDFLAGS += -static-libstdc++ -pie -lm -latomic endif @@ -801,7 +811,7 @@ strip: install: -mkdir -p -m 755 $(BINDIR) -cp $(EXE) $(BINDIR) - -strip $(BINDIR)/$(EXE) + $(STRIP) $(BINDIR)/$(EXE) # clean all clean: objclean profileclean @@ -833,7 +843,7 @@ net: # clean binaries and objects objclean: - @rm -f $(EXE) *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o + @rm -f stockfish stockfish.exe *.o ./syzygy/*.o ./nnue/*.o ./nnue/features/*.o # clean auxiliary profiling files profileclean: