-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
212 lines (186 loc) · 6.34 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
#
BIN = bin
LIB_DIR = lib
OBJ := obj
OBJ_DEBUG = obj-debug
# determine platform
OSSHORT := $(shell sh -c 'uname -o 2>/dev/null')
OS := $(shell sh -c 'uname -s 2>/dev/null')
MACHINE := $(shell sh -c 'uname -m 2>/dev/null')
#
NAME = yannet
ifeq ($(OS), Darwin)
LIB_EXT = .dylib
else ifeq ($(OSSHORT), Msys)
LIB_EXT = .dll
else
LIB_EXT = .so
endif
LIB := lib$(NAME)$(LIB_EXT)
LIBS_LDFLAGS =
MAIN_LDFLAGS =
LDFLAG_LIB := $(NAME)
#
SRCS_PLATFORM =
#
CPPVERSION = -std=c++2a
OFLAGS = -O3
EXTRAFLAGS =
INCLUDES = -Isrc
#
CXX := $(CXX) -fPIC
# set platform specific flags
ifeq ($(OS), Darwin)
# MacOSX
EXTRAFLAGS := $(EXTRAFLAGS) -DHAVE_UNISTD_H
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/bsd/KernelEventMechanism.cpp
LIBS_LDFLAGS := -framework Cocoa -framework IOKit -framework Carbon -lssl -lcrypto
else ifeq ($(OS), FreeBSD)
# FreeBSD
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/bsd/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES) -I/usr/local/include
LIBS_LDFLAGS := -L/usr/local/lib -lssl -lcrypto -pthread
MAIN_LDFLAGS := -pthread
else ifeq ($(OS), NetBSD)
# NetBSD
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/bsd/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES) -I/usr/pkg/include
LIBS_LDFLAGS := -Wl,-rpath /usr/pkg/lib -L/usr/X11R7/lib -L/usr/pkg/lib -lexecinfo -lssl -lcrypto
else ifeq ($(OS), OpenBSD)
# OpenBSD
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/bsd/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES) -I/usr/local/include
LIBS_LDFLAGS := -L/usr/local/lib -lm -lstdc++ -lssl -lcrypto
else ifeq ($(OS), Haiku)
# Haiku
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/bsd/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES) -I/boot/system/develop/headers
LIBS_LDFLAGS := -lnetwork -lssl -lcrypto
else ifeq ($(OS), Linux)
# Linux
SRCS_PLATFORM := $(SRCS_PLATFORM) \
src/yannet/os/network/platform/linux/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES)
LIBS_LDFLAGS := -L/usr/lib64 -lssl -lcrypto
else ifeq ($(OSSHORT), Msys)
# Windows
SRCS_PLATFORM:= $(SRCS_PLATFORM) \
src/yannet/os/network/platform/fallback/KernelEventMechanism.cpp
INCLUDES := $(INCLUDES) -I/mingw64/include
LIBS_LDFLAGS = -L/mingw64/lib -lws2_32 -lssl -lcrypto
endif
CPPFLAGS := $(INCLUDES)
CFLAGS := -g $(OFLAGS) $(EXTRAFLAGS) -pipe -MMD -MP -DNDEBUG
CFLAGS_DEBUG := -g -pipe -MMD -MP
CXXFLAGS := $(CFLAGS) $(CPPVERSION)
CXXFLAGS_DEBUG := $(CFLAGS_DEBUG) $(CPPVERSION)
LIBS := $(LIB_DIR)/$(LIB)
SRC = src
SRCS = \
src/yannet/network/httpclient/HTTPClient.cpp \
src/yannet/network/httpclient/HTTPClientException.cpp \
src/yannet/network/httpclient/HTTPDownloadClient.cpp \
src/yannet/network/udpclient/NetworkClientException.cpp \
src/yannet/network/udpclient/UDPClient.cpp \
src/yannet/network/udpclient/UDPClientMessage.cpp \
src/yannet/network/udpserver/NetworkServerException.cpp \
src/yannet/network/udpserver/ServerClient.cpp \
src/yannet/network/udpserver/ServerClientRequestHandlerHubException.cpp \
src/yannet/network/udpserver/ServerRequest.cpp \
src/yannet/network/udpserver/ServerWorkerThread.cpp \
src/yannet/network/udpserver/ServerWorkerThreadPool.cpp \
src/yannet/network/udpserver/UDPServer.cpp \
src/yannet/network/udpserver/UDPServerClient.cpp \
src/yannet/network/udpserver/UDPServerIOThread.cpp \
src/yannet/os/filesystem/FileSystem.cpp \
src/yannet/os/network/Network.cpp \
src/yannet/os/network/NetworkException.cpp \
src/yannet/os/network/NetworkIOException.cpp \
src/yannet/os/network/NetworkSocketClosedException.cpp \
src/yannet/os/network/NetworkKEMException.cpp \
src/yannet/os/network/NetworkSocket.cpp \
src/yannet/os/network/NetworkSocketException.cpp \
src/yannet/os/network/UDPSocket.cpp \
src/yannet/os/network/SecureTCPSocket.cpp \
src/yannet/os/network/TCPSocket.cpp \
src/yannet/os/threading/Barrier.cpp \
src/yannet/tests/ThreadingTest_ConsumerThread.cpp \
src/yannet/tests/ThreadingTest_ProducerThread.cpp \
src/yannet/tests/ThreadingTest_TestThread.cpp \
src/yannet/tests/UDPServerTest_UDPServer.cpp \
src/yannet/tests/UDPServerTest_UDPServerClient.cpp \
src/yannet/utilities/Base64.cpp \
src/yannet/utilities/Console.cpp \
src/yannet/utilities/ExceptionBase.cpp \
src/yannet/utilities/Integer.cpp \
src/yannet/utilities/RTTI.cpp \
src/yannet/utilities/StringTools.cpp \
src/yannet/utilities/StringTokenizer.cpp \
$(SRCS_PLATFORM)
MAIN_SRCS = \
src/yannet/tests/HTTPClientTest-main.cpp \
src/yannet/tests/HTTPDownloadClientTest-main.cpp \
src/yannet/tests/ThreadingTest-main.cpp \
src/yannet/tests/UDPClientTest-main.cpp \
src/yannet/tests/UDPServerTest-main.cpp
MAINS = $(MAIN_SRCS:$(SRC)/%-main.cpp=$(BIN)/%)
OBJS = $(SRCS:$(SRC)/%.cpp=$(OBJ)/%.o)
OBJS_DEBUG = $(SRCS_DEBUG:$(SRC)/%.cpp=$(OBJ_DEBUG)/%.o)
define cpp-command
@mkdir -p $(dir $@);
@echo Compile $<; $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
endef
define cpp-command-debug
@mkdir -p $(dir $@);
@echo Compile $<; $(CXX) $(CPPFLAGS) $(CXXFLAGS_DEBUG) -c -o $@ $<
endef
define c-command
@mkdir -p $(dir $@);
@echo Compile $<; $(CXX) -x c $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
endef
$(LIB_DIR)/$(LIB): $(OBJS) $(OBJS_DEBUG)
$(OBJS):$(OBJ)/%.o: $(SRC)/%.cpp | print-opts
$(cpp-command)
$(OBJS_DEBUG):$(OBJ_DEBUG)/%.o: $(SRC)/%.cpp | print-opts
$(cpp-command-debug)
$(LIB_DIR)/$(LIB):
@echo Creating shared library $@
@mkdir -p $(dir $@)
@rm -f $@
ifeq ($(OSSHORT), Msys)
@scripts/windows-mingw-create-library-rc.sh $@ $@.rc
@windres $@.rc -o coff -o $@.rc.o
$(CXX) -shared $(patsubst %$(LIB_EXT),,$^) -o $@ $@.rc.o $(LIBS_LDFLAGS) -Wl,--out-implib,$(LIB_DIR)/$(LIB).a
@rm $@.rc
@rm $@.rc.o
else
$(CXX) -shared $(patsubst %$(LIB_EXT),,$^) -o $@ $(LIBS_LDFLAGS)
endif
@echo Done $@
ifeq ($(OSSHORT), Msys)
$(MAINS):$(BIN)/%:$(SRC)/%-main.cpp $(LIBS)
@mkdir -p $(dir $@);
@scripts/windows-mingw-create-executable-rc.sh "$<" $@.rc
@windres $@.rc -o coff -o $@.rc.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $@.rc.o $< -L$(LIB_DIR) -l$(LDFLAG_LIB) $(MAIN_LDFLAGS)
@rm $@.rc
@rm $@.rc.o
else
$(MAINS):$(BIN)/%:$(SRC)/%-main.cpp $(LIBS)
@mkdir -p $(dir $@);
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< -L$(LIB_DIR) -l$(LDFLAG_LIB) $(MAIN_LDFLAGS)
endif
mains: $(MAINS)
all: mains
clean:
rm -rf obj obj-debug $(LIB_DIR) $(BIN)
print-opts:
@echo Building with \"$(CXX) $(CPPFLAGS) $(CXXFLAGS)\"
.PHONY: all mains clean print-opts
-include $(OBJS:%.o=%.d)
-include $(OBJS_DEBUG:%.o=%.d)