forked from ithewei/libhv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.in
257 lines (221 loc) · 5.73 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
#+++++++++++++++++++++++++++++++++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 \
# CROSS_COMPILE=arm-linux-androideabi- \
# DEFINES=USE_OPENCV \
# LIBS="opencv_core opencv_highgui"
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# VARIABLES
TARGET=test
#BUILD_TYPE=DEBUG,RELEASE
BUILD_TYPE=RELEASE
#TARGET_TYPE=EXECUTABLE,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
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
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
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
endif
DEFAULT_CFLAGS += -O3 -fPIC
ifndef CFLAGS
CFLAGS := $(DEFAULT_CFLAGS) -std=c99
else
ifeq ($(findstring -fPIC, $(CFLAGS)), )
override CFLAGS += -fPIC
endif
ifeq ($(findstring -std, $(CFLAGS)), )
override CFLAGS += -std=c99
endif
endif
ifndef CXXFLAGS
CXXFLAGS := $(DEFAULT_CFLAGS) -std=c++11
else
ifeq ($(findstring -fPIC, $(CXXFLAGS)), )
override CXXFLAGS += -fPIC
endif
ifeq ($(findstring -std, $(CXXFLAGS)), )
override CXXFLAGS += -std=c++11
endif
endif
ifndef ARFLAGS
ARFLAGS := cr
endif
# DIRS
PREFIX = install
ifeq ($(OS), Linux)
PREFIX = /usr/local
endif
INCDIR = include
LIBDIR = lib
SRCDIR = src
BINDIR = bin
DEPDIR = 3rd
CONFDIR = etc
DISTDIR = dist
DOCDIR = doc
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 ($(TARGET_TYPE), STATIC)
CPPFLAGS += -DHV_STATICLIB
endif
ifeq ($(BUILD_TYPE), DEBUG)
CPPFLAGS += -DDEBUG
else
CPPFLAGS += -DNDEBUG
endif
CPPFLAGS += $(addprefix -D, $(DEFINES))
CPPFLAGS += $(addprefix -I, $(INCDIRS))
CPPFLAGS += $(addprefix -I, $(SRCDIRS))
# LDFLAGS
ifeq ($(OS), Windows)
LDFLAGS += -static-libgcc -static-libstdc++
endif
ifneq ($(findstring WITH_CURL, $(DEFINES)), )
override LIBS += curl
ifeq ($(OS), Windows)
LIBS += wldap32 advapi32 crypt32
endif
endif
ifneq ($(findstring WITH_NGHTTP2, $(DEFINES)), )
override LIBS += nghttp2
endif
ifneq ($(findstring WITH_OPENSSL, $(DEFINES)), )
override LIBS += ssl crypto
endif
LDFLAGS += $(addprefix -L, $(LIBDIRS))
LDFLAGS += $(addprefix -l, $(LIBS))
ifeq ($(OS), Windows)
LDFLAGS += -lwinmm -liphlpapi -lws2_32
ifneq ($(findstring WITH_WINDUMP, $(DEFINES)), )
LDFLAGS += -ldbghelp
endif
LDFLAGS += -Wl,-Bstatic -lstdc++ -lpthread -lm
else
ifeq ($(OS), Android)
LDFLAGS += -lstdc++ -lm -llog -ldl
else
LDFLAGS += -lstdc++ -lpthread -lm -ldl
ifneq ($(findstring gcc, $(CC_VERSION)), )
LDFLAGS += -lrt # for clock_gettime, clang not -lrt
endif
endif
endif
override SRCS += $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c $(dir)/*.cc $(dir)/*.cpp))
ifeq ($(SRCS), )
SRCS = $(wildcard *.c *.cc *.cpp)
endif
#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)
ifeq ($(TARGET_TYPE), SHARED)
ifeq ($(OS), Windows)
$(CC) -shared $^ -o $(LIBDIR)/[email protected] $(LDFLAGS) -Wl,--output-def,$(LIBDIR)/$(@).def
else
$(CC) -shared $^ -o $(LIBDIR)/[email protected] $(LDFLAGS)
endif
else
ifeq ($(TARGET_TYPE), STATIC)
$(AR) $(ARFLAGS) $(LIBDIR)/[email protected] $^
else
ifeq ($(OS), Windows)
$(CC) $^ -o $(BINDIR)/[email protected] $(LDFLAGS)
else
$(CC) $^ -o $(BINDIR)/$@ $(LDFLAGS)
endif
endif
endif
clean:
$(RM) $(OBJS)
#$(RM) $(LIBDIR)
#$(RM) $(BINDIR)
install:
$(CP) $(INCDIR)/* $(PREFIX)/$(INCDIR)/
$(CP) $(LIBDIR)/* $(PREFIX)/$(LIBDIR)/
$(CP) $(BINDIR)/* $(PREFIX)/$(BINDIR)/
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