forked from ithewei/libhv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.in
298 lines (252 loc) · 6.53 KB
/
Makefile.in
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#+++++++++++++++++++++++++++++++++configure++++++++++++++++++++++++++++++++++++++++
# OS=Windows,Linux,Android
# ARCH=x86,x86_64,arm,aarch64
# CC = $(CROSS_COMPILE)gcc
# CXX = $(CROSS_COMPILE)g++
# CPPFLAGS += $(addprefix -D, $(DEFINES))
# CPPFLAGS += $(addprefix -I, $(SRCDIRS))
# CPPFLAGS += $(addprefix -I, $(INCDIRS))
# LDFLAGS += $(addprefix -L, $(LIBDIRS))
# LDFLAGS += $(addprefix -l, $(LIBS))
#
# Usage:
# make all \
# TARGET=libxx \
# TARGET_TYPE=SHARED \
# BUILD_TYPE=DEBUG \
# CROSS_COMPILE=arm-linux-androideabi- \
# SRCDIRS="src/base src/event" \
# INCDIRS="src/util" \
# SRCS="src/util/hmain.cpp src/util/iniparser.cpp" \
# DEFINES=USE_OPENCV \
# LIBS="opencv_core opencv_highgui"
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-include config.mk
# VARIABLES
TARGET ?= test
# BUILD_TYPE=DEBUG,RELEASE
BUILD_TYPE ?= RELEASE
# TARGET_TYPE=EXECUTABLE,SHARED,STATIC,SHARED|STATIC
TARGET_TYPE ?= EXECUTABLE
# COMMANDS
ifdef CROSS_COMPILE
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
CPP = $(CC) -E
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
endif
MKDIR = -mkdir -p 2>/dev/null
CP = -cp -r 2>/dev/null
RM = -rm -r 2>/dev/null
# PLATFORM: OS, ARCH
CC_VERSION=$(shell $(CC) --version 2>&1 | head -n 1)
TARGET_PLATFORM=$(shell $(CC) -v 2>&1 | grep Target | sed 's/Target: //')
ifneq ($(findstring mingw, $(TARGET_PLATFORM)), )
OS=Windows
endif
ifneq ($(findstring android, $(TARGET_PLATFORM)), )
OS=Android
endif
ifneq ($(findstring darwin, $(TARGET_PLATFORM)), )
OS=Darwin
endif
ifndef OS
OS=Linux
endif
ifndef ARCH
ARCH=$(shell echo $(TARGET_PLATFORM) | awk -F'-' '{print $$1}')
endif
# CFLAGS, CXXFLAGS, ARFLAGS
ifeq ($(BUILD_TYPE), DEBUG)
DEFAULT_CFLAGS = -g -Wall -O0
else
DEFAULT_CFLAGS += -O2
endif
CFLAGS ?= $(DEFAULT_CFLAGS)
CXXFLAGS ?= $(DEFAULT_CFLAGS)
ifneq ($(OS), Windows)
ifeq ($(findstring -fPIC, $(CFLAGS)), )
override CFLAGS += -fPIC
endif
ifeq ($(findstring -fPIC, $(CXXFLAGS)), )
override CXXFLAGS += -fPIC
endif
endif
ifeq ($(findstring -std, $(CFLAGS)), )
override CFLAGS += -std=c99
endif
ifeq ($(findstring -std, $(CXXFLAGS)), )
override CXXFLAGS += -std=c++11
endif
ARFLAGS ?= cr
# DIRS
ifeq ($(OS), Linux)
PREFIX ?= /usr/local
else
PREFIX ?= install
endif
INCDIR = include
LIBDIR = lib
SRCDIR = src
BINDIR = bin
DEPDIR = 3rd
CONFDIR = etc
DISTDIR = dist
DOCDIR = docs
SRCDIRS += $(shell find $(SRCDIR) -type d)
override INCDIRS += $(INCDIR) $(DEPDIR) $(DEPDIR)/include
override LIBDIRS += $(LIBDIR) $(DEPDIR)/lib $(DEPDIR)/lib/$(TARGET_PLATFORM)
# CPPFLAGS
ifeq ($(OS), Windows)
CPPFLAGS += -D_WIN32_WINNT=0x600
ifeq ($(TARGET_TYPE), SHARED)
CPPFLAGS += -DDLL_EXPORTS
endif
endif
ifeq ($(BUILD_TYPE), DEBUG)
CPPFLAGS += -DDEBUG
else
CPPFLAGS += -DNDEBUG
endif
ifeq ($(ENABLE_UDS), yes)
CPPFLAGS += -DENABLE_UDS
endif
ifeq ($(USE_MULTIMAP), yes)
CPPFLAGS += -DUSE_MULTIMAP
endif
CPPFLAGS += $(addprefix -D, $(DEFINES))
CPPFLAGS += $(addprefix -I, $(INCDIRS))
CPPFLAGS += $(addprefix -I, $(SRCDIRS))
# LDFLAGS
ifeq ($(OS), Windows)
LDFLAGS += -static-libgcc -static-libstdc++
endif
ifeq ($(WITH_CURL), yes)
CPPFLAGS += -DWITH_CURL
LDFLAGS += -lcurl
ifeq ($(OS), Windows)
LDFLAGS += -lwldap32 -ladvapi32 -lcrypt32
endif
endif
ifeq ($(WITH_NGHTTP2), yes)
CPPFLAGS += -DWITH_NGHTTP2
LDFLAGS += -lnghttp2
endif
ifeq ($(WITH_OPENSSL), yes)
CPPFLAGS += -DWITH_OPENSSL
LDFLAGS += -lssl -lcrypto
else
ifeq ($(WITH_GNUTLS), yes)
CPPFLAGS += -DWITH_GNUTLS
LDFLAGS += -lgnutls
else
ifeq ($(WITH_MBEDTLS), yes)
CPPFLAGS += -DWITH_MBEDTLS
LDFLAGS += -lmbedtls -lmbedx509 -lmbedcrypto
endif
endif
endif
LDFLAGS += $(addprefix -L, $(LIBDIRS))
LDFLAGS += $(addprefix -l, $(LIBS))
ifeq ($(OS), Windows)
LDFLAGS += -lwinmm -liphlpapi -lws2_32
ifeq ($(ENABLE_WINDUMP), yes)
CPPFLAGS += -DENABLE_WINDUMP
LDFLAGS += -ldbghelp
endif
LDFLAGS += -Wl,-Bstatic -lstdc++ -lpthread -lm
else
ifeq ($(OS), Android)
LDFLAGS += -lstdc++ -lm -llog -ldl
else
LDFLAGS += -lstdc++ -lpthread -lm -ldl
LINK_RT=$(shell echo "int main(){return 0;}" | $(CC) -x c - -lrt 2>&1)
ifeq ($(LINK_RT), )
LDFLAGS += -lrt
endif
endif
endif
ifeq ($(OS), Darwin)
LDFLAGS += -framework CoreFoundation -framework Security
endif
ALL_SRCS += $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c $(dir)/*.cc $(dir)/*.cpp))
ifeq ($(ALL_SRCS), )
ALL_SRCS = $(wildcard *.c *.cc *.cpp)
endif
override SRCS += $(filter-out %_test.c %_test.cc %_test.cpp, $(ALL_SRCS))
# OBJS += $(patsubst %.c, %.o, $(SRCS))
# OBJS += $(patsubst %.cc, %.o, $(SRCS))
# OBJS += $(patsubst %.cpp, %.o, $(SRCS))
OBJS := $(addsuffix .o, $(basename $(SRCS)))
INSTALLED_INCS=$(addprefix $(PREFIX)/$(INCDIR)/, $(shell ls $(INCDIR)))
INSTALLED_LIBS=$(addprefix $(PREFIX)/$(LIBDIR)/, $(shell ls $(LIBDIR)))
INSTALLED_BINS=$(addprefix $(PREFIX)/$(BINDIR)/, $(shell ls $(BINDIR)))
# info
$(info $(CC_VERSION))
$(info OS = $(OS))
$(info ARCH = $(ARCH))
$(info MAKE = $(MAKE))
$(info CC = $(CC))
$(info CXX = $(CXX))
$(info CFLAGS = $(CFLAGS))
$(info CXXFLAGS = $(CXXFLAGS))
$(info CPPFLAGS = $(CPPFLAGS))
$(info LDFLAGS = $(LDFLAGS))
$(info TARGET = $(TARGET))
$(info TARGET_TYPE = $(TARGET_TYPE))
$(info TARGET_PLATFORM = $(TARGET_PLATFORM))
$(info BUILD_TYPE = $(BUILD_TYPE))
$(info SRCS=$(SRCS))
$(info OBJS=$(OBJS))
# $(info INSTALLED_INCS=$(INSTALLED_INCS))
# $(info INSTALLED_LIBS=$(INSTALLED_LIBS))
# $(info INSTALLED_BINS=$(INSTALLED_BINS))
default: all
all: prepare $(TARGET)
prepare:
$(MKDIR) $(BINDIR) $(LIBDIR)
$(TARGET): $(OBJS)
ifneq ($(findstring SHARED, $(TARGET_TYPE)), )
ifeq ($(OS), Windows)
$(CC) -shared $^ -o $(LIBDIR)/$@.dll $(LDFLAGS) -Wl,--output-def,$(LIBDIR)/$(@).def
else
ifeq ($(OS), Darwin)
$(CC) -dynamiclib -install_name @rpath/$@.dylib $^ -o $(LIBDIR)/$@.dylib $(LDFLAGS)
else
$(CC) -shared $^ -o $(LIBDIR)/$@.so $(LDFLAGS)
endif
endif
endif
ifneq ($(findstring STATIC, $(TARGET_TYPE)), )
$(AR) $(ARFLAGS) $(LIBDIR)/$@.a $^
endif
ifneq ($(findstring EXECUTABLE, $(TARGET_TYPE)), )
ifeq ($(OS), Windows)
$(CC) $^ -o $(BINDIR)/$@.exe $(LDFLAGS)
else
$(CC) $^ -o $(BINDIR)/$@ $(LDFLAGS)
endif
endif
clean:
$(RM) $(OBJS)
#$(RM) $(LIBDIR)
#$(RM) $(BINDIR)
install:
$(CP) $(INCDIR)/* $(PREFIX)/$(INCDIR)/
$(CP) $(LIBDIR)/* $(PREFIX)/$(LIBDIR)/
$(CP) $(BINDIR)/* $(PREFIX)/$(BINDIR)/
$(LDCONFIG)
uninstall:
$(RM) $(INSTALLED_INCS)
$(RM) $(INSTALLED_LIBS)
$(RM) $(INSTALLED_BINS)
dist:
$(MKDIR) $(DISTDIR)
$(CP) $(INCDIR) $(LIBDIR) $(BINDIR) $(CONFDIR) $(DOCDIR) $(DISTDIR)
undist:
$(RM) $(DISTDIR)
.PHONY: default all prepare clean install uninstall dist undist