-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMakefile
135 lines (109 loc) · 3.25 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
UNAME := $(shell uname -s)
BUILD_DIR := build
include Make/darwin.mk
include Make/linux.mk
include Make/android.mk
DEPLOYMENTS := \
debug \
release
define platform_rules
# Source files
SRCS_$(1) := $(foreach dir, \
$(4), \
$(wildcard $(dir)/*.c))
OBJS_$(1) := $$(patsubst %.c, \
$$(BUILD_DIR)/$(1)/$(3)/$(2)/%.o, \
$$(SRCS_$(1)))
# Compiled objects
$$(BUILD_DIR)/$(1)/$(3)/$(2)/%.o: %.c | \
$$(addprefix $$(BUILD_DIR)/$(1)/$(3)/$(2)/,$$($(4)))
@echo "Compiling for $(1) on $(2) in $(3): $$<..."
@mkdir -p $$(dir $$@)
@$$(GCC_$(1)) $$(GCCFLAGS_$(1)_$(3)) -arch $(2) -I. -c $$< -o $$@
# libBwsrHook
$$(BUILD_DIR)/$(1)/$(3)/$(2)/libBwsrHook: \
$$(OBJS_$(1)) | \
$$(addprefix $$(BUILD_DIR)/$(1)/$(3)/$(2)/,$$($(4)))
@echo "Building Archive for $(1) on $(2) in $(3)..."
@$$(AR_$(1)) rcs $(BUILD_DIR)/$(1)/$(3)/$(2)/libBwsrHook.a $$^
# Example
$$(BUILD_DIR)/$(1)/$(3)/$(2)/Example: Example.c \
$$(OBJS_$(1)) | \
$$(addprefix $$(BUILD_DIR)/$(1)/$(3)/$(2)/,$$($(4)))
@echo "Compiling Example for $(1) on $(2) in $(3)..."
@$$(GCC_$(1)) $$(GCCFLAGS_$(1)_$(3)) -arch $(2) $$(EXAMPLE_LDFLAGS_$(1)) -I. -o $$@ $$^
ifeq ($(1),ios)
@codesign -s - --entitlements Entitlements.plist $$@
endif
$$(addprefix $$(BUILD_DIR)/$(1)/$(3)/$(2)/,$$($(4))):
@mkdir -p $$@
endef
# Evaluate the platform_rules for each platform
ifeq ($(UNAME),Darwin)
$(foreach platform,$(DARWIN_PLATFORMS), \
$(foreach arch,$(DARWIN_ARCHS), \
$(foreach deployment,$(DEPLOYMENTS), \
$(eval $(call platform_rules,$(platform),$(arch),$(deployment),$(DARWIN_DIRS))) \
) \
) \
)
endif
ifeq ($(UNAME),Linux)
$(foreach platform,$(LINUX_PLATFORMS), \
$(foreach arch,$(LINUX_ARCHS), \
$(foreach deployment,$(DEPLOYMENTS), \
$(eval $(call platform_rules,$(platform),$(arch),$(deployment),$(LINUX_DIRS))) \
) \
) \
)
endif
ifdef ANDROID_NDK
$(foreach platform,$(ANDROID_PLATFORMS), \
$(foreach arch,$(ANDROID_ARCHS), \
$(foreach deployment,$(DEPLOYMENTS), \
$(eval $(call platform_rules,$(platform),$(arch),$(deployment),$(ANDROID_DIRS))) \
) \
) \
)
endif
$(BUILD_DIR):
@mkdir -p $@
clean:
rm -rf build
collect_header:
@cp Hook/InlineHook.h $(BUILD_DIR)
hooklib_debug: \
mac_debug \
ios_debug \
android_debug \
linux_debug
hooklib_release: \
mac_release \
ios_release \
android_release \
linux_release
examples_debug: \
mac_example_debug \
ios_example_debug \
android_example_debug \
linux_example_debug
examples_release: \
mac_example_release \
ios_example_release \
android_example_release \
linux_example_release
examples: \
examples_release \
examples_debug
hooklibs: \
hooklib_release \
hooklib_debug
debug: \
hooklib_debug \
examples_debug
release: \
hooklib_release \
examples_release
all: hooklibs examples collect_header
.DEFAULT_GOAL := all
.PHONY: all clean release debug