-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
111 lines (88 loc) · 4.01 KB
/
makefile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
.DEFAULT_GOAL := help
PROJECTNAME=$(shell basename "$(PWD)")
SOURCES=$(sort $(wildcard ./src/*.rs ./src/**/*.rs))
OS_NAME=$(shell uname | tr '[:upper:]' '[:lower:]')
PATH := $(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin:$(PATH)
ANDROID_AARCH64_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/aarch64-linux-android29-clang
ANDROID_ARMV7_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/armv7a-linux-androideabi29-clang
ANDROID_I686_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/i686-linux-android29-clang
ANDROID_X86_64_LINKER=$(ANDROID_NDK_HOME)/toolchains/llvm/prebuilt/$(OS_NAME)-x86_64/bin/x86_64-linux-android29-clang
SHELL := /bin/bash
# ##############################################################################
# # GENERAL
# ##############################################################################
.PHONY: help
help: makefile
@echo
@echo " Available actions in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
## init: Install missing dependencies.
.PHONY: init
init:
rustup target add aarch64-apple-ios x86_64-apple-ios
#rustup target add armv7-apple-ios armv7s-apple-ios i386-apple-ios ## deprecated
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
@if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi
cargo install cbindgen
## :
# ##############################################################################
# # RECIPES
# ##############################################################################
## all: Compile iOS, Android and bindings targets
all: ios android bindings
## ios: Compile the iOS universal library
ios: target/universal/release/libstackmate.a
target/universal/release/libstackmate.a: $(SOURCES) ndk-home
@if [ $$(uname) == "Darwin" ] ; then \
cargo lipo --release ; \
else echo "Skipping iOS compilation on $$(uname)" ; \
fi
@echo "[DONE] $@"
## android: Compile the android targets (arm64, armv7 and i686)
android: target/aarch64-linux-android/release/libstackmate.so target/armv7-linux-androideabi/release/libstackmate.so target/i686-linux-android/release/libstackmate.so target/x86_64-linux-android/release/libstackmate.so
target/aarch64-linux-android/release/libstackmate.so: $(SOURCES) ndk-home
CC_aarch64_linux_android=$(ANDROID_AARCH64_LINKER) \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$(ANDROID_AARCH64_LINKER) \
cargo build --target aarch64-linux-android --release
@echo "[DONE] $@"
target/armv7-linux-androideabi/release/libstackmate.so: $(SOURCES) ndk-home
CC_armv7_linux_androideabi=$(ANDROID_ARMV7_LINKER) \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=$(ANDROID_ARMV7_LINKER) \
cargo build --target armv7-linux-androideabi --release
@echo "[DONE] $@"
target/i686-linux-android/release/libstackmate.so: $(SOURCES) ndk-home
CC_i686_linux_android=$(ANDROID_I686_LINKER) \
CARGO_TARGET_I686_LINUX_ANDROID_LINKER=$(ANDROID_I686_LINKER) \
PKG_CONFIG_ALLOW_CROSS=1 OPENSSL_STATIC=1 cargo build --target i686-linux-android --release
@echo "[DONE] $@"
target/x86_64-linux-android/release/libstackmate.so: $(SOURCES) ndk-home
CC_x86_64_linux_android=$(ANDROID_X86_64_LINKER) \
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$(ANDROID_X86_64_LINKER) \
cargo build --target x86_64-linux-android --release
@echo "[DONE] $@"
.PHONY: ndk-home
ndk-home:
@if [ ! -d "${ANDROID_NDK_HOME}" ] ; then \
echo "Error: Please, set the ANDROID_NDK_HOME env variable to point to your NDK folder" ; \
exit 1 ; \
fi
## bindings: Generate the .h file for iOS
bindings: target/bindings.h
target/bindings.h: $(SOURCES)
cbindgen $^ -c cbindgen.toml | grep -v \#include | uniq > $@
@echo "[DONE] $@"
## :
# ##############################################################################
# # OTHER
# ##############################################################################
## clean:
.PHONY: clean
clean:
cargo clean
rm -f target/bindings.h target/bindings.src.h
## test:
.PHONY: test
test:
cargo test