-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (69 loc) · 2.88 KB
/
Makefile
File metadata and controls
82 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
.PHONY: generate specs jni java clean lint test test-tools build prove examples
# JDK detection for host tests (jni.h and libjvm.so).
JDK_HOME ?= $(shell readlink -f $$(which javac) 2>/dev/null | sed 's|/bin/javac$$||')
JNI_INCLUDE ?= $(JDK_HOME)/include
LIBJVM_DIR ?= $(shell find $(JDK_HOME) -name libjvm.so -printf '%h' -quit 2>/dev/null)
# Android SDK platform JAR for specgen.
ANDROID_JAR ?= $(ANDROID_HOME)/platforms/android-36/android.jar
# Run all generators (proto/grpc/cli generation moved to jni-proxy repo)
generate: specs jni java
# Run specgen — generates YAML specs from ref/ .class files
specs:
go run ./tools/cmd/specgen/ -ref ref -classpath $(ANDROID_JAR) -output spec/java/ -go-module github.com/AndroidGoLab/jni
# Run jnigen only — generates capi/ and root package idiomatic files
jni:
go run ./tools/cmd/jnigen/ -spec spec/jni.yaml -overlay spec/overlays/jni.yaml -templates templates/jni/ -output .
# Run javagen only — generates high-level Android API packages
java:
go run ./tools/cmd/javagen/ -specs spec/java/ -overlays spec/overlays/java/ -templates templates/java/ -output . -go-module github.com/AndroidGoLab/jni
# Remove all generated files (identified by "DO NOT EDIT" header), excluding tools/
clean:
grep -rl "Code generated by jnigen\. DO NOT EDIT\." --include="*.go" --exclude-dir=tools . | xargs -r rm -f
grep -rl "Code generated by javagen\. DO NOT EDIT\." --include="*.go" --exclude-dir=tools . | xargs -r rm -f
find . -path '*/consts' -type d -empty -not -path './tools/*' -delete 2>/dev/null || true
rm -f capi/cgo_vtable_dispatch.h
# Run golangci-lint
lint:
golangci-lint run ./...
# Run all tests (requires JDK for jni.h)
test:
@if [ -z "$(JDK_HOME)" ] || [ ! -d "$(JNI_INCLUDE)" ]; then \
echo "Error: JDK not found. Install a JDK or set JDK_HOME."; \
exit 1; \
fi
C_INCLUDE_PATH="$(JNI_INCLUDE):$(JNI_INCLUDE)/linux" \
LD_LIBRARY_PATH="$(LIBJVM_DIR)" \
go test ./...
# Run only tool tests (no JDK needed)
test-tools:
go test ./tools/...
# Verify Lean proofs (requires elan/lake)
prove:
@command -v lake >/dev/null 2>&1 || { echo "lake not found. Install elan: https://github.com/leanprover/elan"; exit 1; }
cd proofs && lake build
# Build all example APKs (requires Android SDK + NDK)
EXAMPLE_DIRS := $(sort $(dir $(wildcard examples/*/Makefile)))
examples:
@failed=""; \
for d in $(EXAMPLE_DIRS); do \
name=$$(basename $$d); \
printf " %-20s" "$$name"; \
if $(MAKE) -C $$d build >/dev/null 2>&1; then \
echo "OK"; \
else \
echo "FAIL"; \
failed="$$failed $$name"; \
fi; \
done; \
if [ -n "$$failed" ]; then \
echo "Failed:$$failed"; \
exit 1; \
fi; \
echo "All examples built."
# Cross-compile libraries for android/arm64 (requires NDK toolchain)
build:
CGO_ENABLED=1 \
GOOS=android \
GOARCH=arm64 \
CC=$(shell echo $$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang) \
go build ./...