@@ -17,7 +17,14 @@ FIXTURE_MODULES := $(notdir $(wildcard tools/pkg/specgen/testdata/*/))
1717NDK_SYSROOT := $(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
1818C2FFI_BIN ?= c2ffi
1919
20- .PHONY : all capi specs idiomatic clean regen fixtures test lint check-examples e2e e2e-build e2e-examples e2e-examples-test e2e-audio ndkcli ndkcli-commands
20+ API_LEVEL ?= 35
21+ NDK_CC_ARM64 := $(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android$(API_LEVEL ) -clang
22+ NDK_CC_X86_64 := $(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android$(API_LEVEL ) -clang
23+ BUILD_DIR := build
24+
25+ .PHONY : all capi specs idiomatic clean regen fixtures test lint check-examples check-no-capi \
26+ e2e e2e-build e2e-examples e2e-examples-test e2e-audio \
27+ ndkcli ndkcli-commands ndkcli-release install-ndk
2128
2229all : specs capi idiomatic
2330
@@ -102,15 +109,14 @@ lint:
102109
103110# Cross-compile all examples and ndkcli for Android arm64 to catch compile errors (requires NDK)
104111check-examples :
105- CGO_ENABLED=1 GOOS=android GOARCH=arm64 \
106- CC=$(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android35-clang \
112+ CGO_ENABLED=1 GOOS=android GOARCH=arm64 CC=$(NDK_CC_ARM64 ) \
107113 go build ./examples/... ./cmd/ndkcli/
108114
109115# Cross-compile E2E test binary for Android x86_64 (requires NDK)
110116e2e-build :
111- CGO_ENABLED=1 GOOS=android GOARCH=amd64 \
112- CC=$(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android35-clang \
113- go build -o tests/e2e /e2e_test ./tests/e2e
117+ @mkdir -p $( BUILD_DIR )
118+ CGO_ENABLED=1 GOOS=android GOARCH=amd64 CC=$(NDK_CC_X86_64 ) \
119+ go build -o $( BUILD_DIR ) /e2e_test ./tests/e2e
114120
115121# Run full E2E test on Android emulator (requires SDK + NDK + KVM)
116122e2e : e2e-build
@@ -128,11 +134,32 @@ e2e-examples-test:
128134e2e-audio :
129135 ./tests/e2e/run-audio-e2e.sh
130136
131- # Build ndkcli for Android (requires NDK)
137+ # Install Android NDK (for CI; no-op if already present)
138+ ANDROID_NDK_VERSION ?= r28
139+ ANDROID_NDK_DIR_NAME ?= 28.0.13004108
140+ install-ndk :
141+ @if [ -d " $( NDK_PATH) " ]; then echo " NDK already at $( NDK_PATH) " ; exit 0; fi ; \
142+ echo " Installing Android NDK $( ANDROID_NDK_VERSION) ..." ; \
143+ wget -q " https://dl.google.com/android/repository/android-ndk-$( ANDROID_NDK_VERSION) -linux.zip" -O /tmp/ndk.zip; \
144+ unzip -q /tmp/ndk.zip -d /tmp/ndk-extract/; \
145+ mkdir -p " $( ANDROID_HOME) /ndk" ; \
146+ mv /tmp/ndk-extract/android-ndk-* " $( ANDROID_HOME) /ndk/$( ANDROID_NDK_DIR_NAME) " ; \
147+ rm -f /tmp/ndk.zip; \
148+ echo " NDK installed to $( ANDROID_HOME) /ndk/$( ANDROID_NDK_DIR_NAME) "
149+
150+ # Build ndkcli for Android arm64 (requires NDK)
132151ndkcli :
133- CGO_ENABLED=1 GOOS=android GOARCH=arm64 \
134- CC=$(NDK_PATH ) /toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android$(APK_API ) -clang \
135- go build -o ndkcli ./cmd/ndkcli/
152+ @mkdir -p $(BUILD_DIR )
153+ CGO_ENABLED=1 GOOS=android GOARCH=arm64 CC=$(NDK_CC_ARM64 ) \
154+ go build -o $(BUILD_DIR ) /ndkcli ./cmd/ndkcli/
155+
156+ # Build release binaries for both architectures (stripped)
157+ ndkcli-release :
158+ @mkdir -p $(BUILD_DIR )
159+ CGO_ENABLED=1 GOOS=android GOARCH=arm64 CC=$(NDK_CC_ARM64 ) \
160+ go build -trimpath -ldflags=" -s -w" -o $(BUILD_DIR ) /ndkcli-android-arm64 ./cmd/ndkcli/
161+ CGO_ENABLED=1 GOOS=android GOARCH=amd64 CC=$(NDK_CC_X86_64 ) \
162+ go build -trimpath -ldflags=" -s -w" -o $(BUILD_DIR ) /ndkcli-android-x86_64 ./cmd/ndkcli/
136163
137164# Print all ndkcli subcommands (extracted from source, no binary needed)
138165ndkcli-commands :
0 commit comments