-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
212 lines (166 loc) · 6.48 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#############################################################################
#
# Generic Makefile Template for C/C++ Projects
#
# License: GPL (General Public License)
# Note: GPL only applies to this file; you can use this Makefile in non-GPL projects.
# Author: Pear <service AT pear DOT hk>
# Date: 2016/04/26 (version 0.7)
# Author: kevin1078 <kevin1078 AT 126 DOT com>
# Date: 2012/04/24 (version 0.6)
# Author: whyglinux <whyglinux AT gmail DOT com>
# Date: 2008/04/05 (version 0.5)
# 2007/06/26 (version 0.4)
# 2007/04/09 (version 0.3)
# 2007/03/24 (version 0.2)
# 2006/03/04 (version 0.1)
#===========================================================================
## Customizable Section: adapt those variables to suit your program.
##==========================================================================
# The executable file name. Must be specified.
# PROGRAM = rdb
PROGRAM = libwrapper.so
# C and C++ program compilers. Un-comment and specify for cross-compiling if needed.
#CC = gcc
#CXX = g++
# Un-comment the following line to compile C programs as C++ ones.
#CC = $(CXX)
# The extra pre-processor and compiler options; applies to both C and C++ compiling as well as LD.
EXTRA_CFLAGS = -ggdb3 -fPIC -fdata-sections -ffunction-sections -fno-builtin -nostdlib
# The extra linker options, e.g. "-lmysqlclient -lz"
EXTRA_LDFLAGS = -L/usr/local/lib -lpbvt -lcapstone
# Specify the include dirs, e.g. "-I/usr/include/mysql -I./include -I/usr/include -I/usr/local/include".
INCLUDE = -Iinclude
# The C Preprocessor options (notice here "CPP" does not mean "C++"; man cpp for more info.). Actually $(INCLUDE) is included.
CPPFLAGS = -Wall -Wextra # helpful for writing better code (behavior-related)
# The options used in linking as well as in any direct use of ld.
LDFLAGS = -shared
# The directories in which source files reside.
# If not specified, all subdirectories of the current directory will be added recursively.
SRCDIRS := src
# OS specific.
EXTRA_CFLAGS_MACOS =
EXTRA_LDFLAGS_MACOS = -Wl,-search_paths_first -Wl,-dead_strip -v # deleting unused code for Pear, for minimal exe size
LDFLAGS_MACOS =
EXTRA_CFLAGS_LINUX = -Wl,--gc-sections
EXTRA_LDFLAGS_LINUX = -Wl,--gc-sections -Wl,--strip-all # deleting unused code for Pear, for minimal exe size
LDFLAGS_LINUX =
EXTRA_CFLAGS_WINDOWS =
EXTRA_LDFLAGS_WINDOWS =
LDFLAGS_WINDOWS =
# Actually process the OS specific flags.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin) # if MacOS
EXTRA_CFLAGS += $(EXTRA_CFLAGS_MACOS)
EXTRA_LDFLAGS += $(EXTRA_LDFLAGS_MACOS)
LDFLAGS += $(LDFLAGS_MACOS)
else ifeq ($(UNAME_S), Linux) # if Linux
EXTRA_CFLAGS += $(EXTRA_CFLAGS_LINUX)
EXTRA_LDFLAGS += $(EXTRA_LDFLAGS_LINUX)
LDFLAGS += $(LDFLAGS_LINUX)
else # Windows, or... need to specify "MINGW" or "CYGWIN" to correctly detect.
EXTRA_CFLAGS += $(EXTRA_CFLAGS_WINDOWS)
EXTRA_LDFLAGS += $(EXTRA_LDFLAGS_WINDOWS)
LDFLAGS += $(LDFLAGS_WINDOWS)
endif
#Actually $(INCLUDE) is included in $(CPPFLAGS).
CPPFLAGS += $(INCLUDE)
## Implicit Section: change the following only when necessary.
##==========================================================================
# The source file types (headers excluded).
# .c indicates C source files, and others C++ ones.
SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp
# The header file types.
HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp
# The pre-processor and compiler options.
# Users can override those variables from the command line.
CFLAGS = -O2 # -DNDEBUG
CXXFLAGS= -O2 # -DNDEBUG
# The command used to delete file.
RM = rm -f
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
## Stable Section: usually no need to be changed. But you can add more.
##==========================================================================
ifeq ($(SRCDIRS),)
SRCDIRS := $(shell find $(SRCDIRS) -type d)
endif
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
SRC_CXX = $(filter-out %.c,$(SOURCES))
OBJS = $(addsuffix .o, $(basename $(SOURCES)))
#DEPS = $(OBJS:%.o=%.d) #replace %.d with .%.d (hide dependency files)
DEPS = $(foreach f, $(OBJS), $(addprefix $(dir $(f))., $(patsubst %.o, %.d, $(notdir $(f)))))
## Define some useful variables.
DEP_OPT = $(shell if `$(CC) --version | grep -i "GCC" >/dev/null`; then \
echo "-MM"; else echo "-M"; fi )
DEPEND.d = $(CC) $(DEP_OPT) $(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS)
COMPILE.c = $(CC) $(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cxx = $(CXX) $(EXTRA_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
LINK.c = $(CC) $(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
LINK.cxx = $(CXX) $(EXTRA_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
.PHONY: all objs tags ctags clean distclean help show
# Delete the default suffixes
.SUFFIXES:
all: $(PROGRAM)
# Rules for creating dependency files (.d).
#------------------------------------------
.%.d:%.c
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.C
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.cc
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.cpp
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.CPP
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.c++
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.cp
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
.%.d:%.cxx
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
# Rules for generating object files (.o).
#----------------------------------------
objs:$(OBJS)
%.o:%.c
$(COMPILE.c) $< -o $@
%.o:%.C
$(COMPILE.cxx) $< -o $@
%.o:%.cc
$(COMPILE.cxx) $< -o $@
%.o:%.cpp
$(COMPILE.cxx) $< -o $@
%.o:%.CPP
$(COMPILE.cxx) $< -o $@
%.o:%.c++
$(COMPILE.cxx) $< -o $@
%.o:%.cp
$(COMPILE.cxx) $< -o $@
%.o:%.cxx
$(COMPILE.cxx) $< -o $@
# Rules for generating the tags.
#-------------------------------------
tags: $(HEADERS) $(SOURCES)
$(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
ctags: $(HEADERS) $(SOURCES)
$(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
# Rules for generating the executable.
#-------------------------------------
$(PROGRAM):$(OBJS)
$(LINK.c) $(OBJS) $(EXTRA_LDFLAGS) -o $@
@echo Type ./run.sh myprogram arg1 arg2 ... to execute the program.
all: $(PROGRAM)
clean:
$(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe