-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldetour.mak
138 lines (111 loc) · 3.38 KB
/
ldetour.mak
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
136
137
138
#工程名字
PROJECT_NAME = ldetour
#目标名字
TARGET_NAME = ldetour
#系统环境
UNAME_S = $(shell uname -s)
#伪目标
.PHONY: clean all target pre_build post_build
all : pre_build target post_build
#CFLAG
MYCFLAGS =
#需要定义的FLAG
MYCFLAGS += -Wsign-compare
MYCFLAGS += -Wno-sign-compare
MYCFLAGS += -Wno-unused-variable
MYCFLAGS += -Wno-unused-parameter
MYCFLAGS += -Wno-unknown-pragmas
MYCFLAGS += -Wno-unused-but-set-parameter
#c标准库版本
#gnu99/gnu11/gnu17
STDC = -std=gnu99
#c++标准库版本
#c++11/c++14/c++17/c++20
STDCPP = -std=c++17
#需要的include目录
MYCFLAGS += -Isrc/detour
MYCFLAGS += -I../lua/lua
MYCFLAGS += -I../luakit/include
#需要定义的选项
#LDFLAGS
LDFLAGS =
#源文件路径
SRC_DIR = src
#需要排除的源文件,目录基于$(SRC_DIR)
EXCLUDE =
#需要连接的库文件
LIBS =
#是否启用mimalloc库
LIBS += -lmimalloc
MYCFLAGS += -I$(SOLUTION_DIR)extend/mimalloc/mimalloc/include -include ../../mimalloc-ex.h
#自定义库
LIBS += -llua
#系统库
LIBS += -lm -ldl -lstdc++ -lpthread
#定义基础的编译选项
ifndef CC
CC = gcc
endif
ifndef CX
CX = c++
endif
CFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDC) $(MYCFLAGS)
CXXFLAGS = -g -O2 -Wall -Wno-deprecated -Wextra $(STDCPP) $(MYCFLAGS)
#项目目录
ifndef SOLUTION_DIR
SOLUTION_DIR=./
endif
#临时文件目录
INT_DIR = $(SOLUTION_DIR)temp/$(PROJECT_NAME)
#目标文件前缀,定义则.so和.a加lib前缀,否则不加
PROJECT_PREFIX =
#目标定义
MYCFLAGS += -fPIC
TARGET_DIR = $(SOLUTION_DIR)bin
TARGET_DYNAMIC = $(TARGET_DIR)/$(PROJECT_PREFIX)$(TARGET_NAME).so
#soname
ifeq ($(UNAME_S), Linux)
LDFLAGS += -Wl,-soname,$(PROJECT_PREFIX)$(TARGET_NAME).so
endif
#install_name
ifeq ($(UNAME_S), Darwin)
LDFLAGS += -Wl,-install_name,$(PROJECT_PREFIX)$(TARGET_NAME).so
endif
#link添加.so目录
LDFLAGS += -L$(SOLUTION_DIR)bin
LDFLAGS += -L$(SOLUTION_DIR)library
#自动生成目标
OBJS =
#子目录
OBJS += $(patsubst $(SRC_DIR)/detour/%.c, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.c)))
OBJS += $(patsubst $(SRC_DIR)/detour/%.m, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.m)))
OBJS += $(patsubst $(SRC_DIR)/detour/%.cc, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.cc)))
OBJS += $(patsubst $(SRC_DIR)/detour/%.cpp, $(INT_DIR)/detour/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/detour/*.cpp)))
#根目录
OBJS += $(patsubst $(SRC_DIR)/%.c, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.c)))
OBJS += $(patsubst $(SRC_DIR)/%.m, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.m)))
OBJS += $(patsubst $(SRC_DIR)/%.cc, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cc)))
OBJS += $(patsubst $(SRC_DIR)/%.cpp, $(INT_DIR)/%.o, $(filter-out $(EXCLUDE), $(wildcard $(SRC_DIR)/*.cpp)))
# 编译所有源文件
$(INT_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.m
$(CC) $(CFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.cc
$(CX) $(CXXFLAGS) -c $< -o $@
$(INT_DIR)/%.o : $(SRC_DIR)/%.cpp
$(CX) $(CXXFLAGS) -c $< -o $@
$(TARGET_DYNAMIC) : $(OBJS)
$(CC) -o $@ -shared $(OBJS) $(LDFLAGS) $(LIBS)
#target伪目标
target : $(TARGET_DYNAMIC)
#clean伪目标
clean :
rm -rf $(INT_DIR)
#预编译
pre_build:
mkdir -p $(INT_DIR)
mkdir -p $(TARGET_DIR)
mkdir -p $(INT_DIR)/detour
#后编译
post_build: