Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (50 loc) · 1.61 KB
/
Copy pathMakefile
File metadata and controls
68 lines (50 loc) · 1.61 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
NDK_PATH ?= $(HOME)/Android/Sdk/ndk/29.0.13113456
API_LEVEL ?= 26
ARCH ?= arm64-v8a
TOOLCHAIN = $(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64
ifeq ($(TERMUX_VERSION),)
CC = $(TOOLCHAIN)/bin/clang
AR = $(TOOLCHAIN)/bin/llvm-ar
SYSROOT = $(TOOLCHAIN)/sysroot
else
CC = clang
AR = llvm-ar
endif
TARGET_arm64-v8a = aarch64-linux-android$(API_LEVEL)
TARGET_armeabi-v7a = armv7a-linux-androideabi$(API_LEVEL)
TARGET_x86 = i686-linux-android$(API_LEVEL)
TARGET_x86_64 = x86_64-linux-android$(API_LEVEL)
ifneq ($(SYSROOT),)
CC_ARCH = $(CC) --target=$(TARGET_$(ARCH)) --sysroot=$(SYSROOT)
else
CC_ARCH = $(CC) --target=$(TARGET_$(ARCH))
endif
CFLAGS_BASE = -std=c99 -DANDROID -fPIC -Isrc -Wpedantic -Wall -Wextra -Werror -Wformat -Wuninitialized -Wshadow -Wno-variadic-macros
CFLAGS_debug = $(CFLAGS_BASE) -g -O0 -DPLTI_LOGGING
CFLAGS_release = $(CFLAGS_BASE) -O3 -flto
BUILD_TYPE ?= debug
out ?= build/$(BUILD_TYPE)/$(ARCH)
CFLAGS = $(CFLAGS_$(BUILD_TYPE))
SRCS = src/plti.c src/elf_util.c
OBJS = $(patsubst src/%.c,$(out)/%.o,$(SRCS))
DEPS = $(OBJS:.o=.d)
STATIC_LIB = $(out)/libplti.a
SHARED_LIB = $(out)/libplti.so
.PHONY: all lib_debug lib_release clean
all: $(STATIC_LIB) $(SHARED_LIB)
lib_debug:
$(MAKE) BUILD_TYPE=debug out=build/debug/$(ARCH) all
lib_release:
$(MAKE) BUILD_TYPE=release out=build/release/$(ARCH) all
$(out)/%.o: src/%.c
@mkdir -p $(dir $@)
$(CC_ARCH) $(CFLAGS) -c $< -o $@
$(STATIC_LIB): $(OBJS)
@mkdir -p $(dir $@)
$(AR) rcs $@ $^
$(SHARED_LIB): $(OBJS)
@mkdir -p $(dir $@)
$(CC_ARCH) $(CFLAGS) -shared -Wl,-soname,libplti.so $(OBJS) -llog -ldl -o $@
-include $(DEPS)
clean:
rm -rf build