]> git.sesse.net Git - stockfish/commitdiff
Fix Makefile for Android NDK cross-compile
authorpschneider1968 <36973164+pschneider1968@users.noreply.github.com>
Fri, 21 Jan 2022 13:11:53 +0000 (14:11 +0100)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Tue, 25 Jan 2022 06:27:23 +0000 (07:27 +0100)
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

index 5f3e739f788fc47fa182ba54be5ad8d7492d9fa7..9666f13846325d709bb8904dc07a34efe46e477c 100644 (file)
@@ -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: