-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
60 lines (45 loc) · 1.3 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
SRC := binder.c buf.c transaction.c
CFLAGS += -Wall -Iinclude
TARGET_ARCH ?= x86_64
ifndef NDK_ROOT
$(error NDK_ROOT is not set)
endif
# Cross-compile for aarch64 if the $ARCH is arm64 or aarch64
ifneq ($(filter arm64 aarch64,$(ARCH)),)
TARGET_ARCH := aarch64
endif
# Compile for Android platform if $ANDROID is 1
ifeq ($(ANDROID),1)
# Android NDK settings
SDK := 30
HOST_OS := $(shell uname | tr '[:upper:]' '[:lower:]')
HOST_ARCH := x86_64
HOST_PLATFORM := $(HOST_OS)-$(HOST_ARCH)
TARGET_PLATFORM := $(TARGET_ARCH)-linux-android
NDK_TOOLCHAIN := $(NDK_ROOT)/toolchains/llvm/prebuilt/$(HOST_PLATFORM)
CC := $(NDK_TOOLCHAIN)/bin/$(TARGET_PLATFORM)$(SDK)-clang
CFLAGS += -DANDROID
else
CC := clang
CFLAGS += --target=aarch64-linux-gnu
endif
SRC := $(addprefix src/, $(SRC))
OBJ := $(SRC:.c=.o)
all: libdevbinder.a examples
$(OBJ): %.o : %.c
$(CC) $(CFLAGS) -c $< -o $@
libdevbinder.so: $(OBJ)
$(CC) $(CFLAGS) -fPIC -shared -o libdevbinder.so $(OBJ)
libdevbinder.a: $(OBJ)
ar rcs $@ $(OBJ)
examples: server client
server: CFLAGS += -static
server: examples/server.c libdevbinder.a
$(CC) $(CFLAGS) -o $@ $^
client: CFLAGS += -static
client: examples/client.c libdevbinder.a
$(CC) $(CFLAGS) -o $@ $^
.PHONY: clean
clean:
rm -f src/*.o libdevbinder.so libdevbinder.a
rm -f server client