forked from DiscordMessenger/dm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
238 lines (201 loc) · 6.23 KB
/
Makefile
File metadata and controls
238 lines (201 loc) · 6.23 KB
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
# User settings
# -----------------------------
# User-configurable variables
# -----------------------------
DEBUG ?= yes # yes = build debug with symbols, no = release
UNICODE ?= yes # yes = build Unicode, no = ANSI
IS_MINGW_ON_WINDOWS ?= no # yes if compiling on native Windows with MinGW
# Optional environment overrides
USER_INC_DIRS ?=
USER_DEFINES ?=
COMMIT_HASH ?= undefined
# Windows version macros
WINVER ?= 0x0501
WIN32IE ?= 0x0500
# Build directories
BUILD_DIR = build
BIN_DIR = bin
SRC_DIR = src
# Target executable
TARGET = $(BIN_DIR)/DiscordMessenger.exe
# -----------------------------
# Toolchain configuration
# -----------------------------
ifeq ($(IS_MINGW_ON_WINDOWS),yes)
MSYS_PATH ?= C:/MinGW/msys/1.0
OPENSSL_DIR ?= C:/DiscordMessenger/openssl
LIBWEBP_DIR ?= C:/DiscordMessenger/libwebp/build
DMCC ?= gcc
DMCXX ?= g++
DMWR ?= windres
DMSTRIP ?= strip
MKDIR ?= $(MSYS_PATH)/bin/mkdir.exe
FIND ?= $(MSYS_PATH)/bin/find.exe
else
OPENSSL_DIR ?= /mnt/c/DiscordMessenger/openssl
LIBWEBP_DIR ?= /mnt/c/DiscordMessenger/libwebp/build
DMPREFIX ?= i686-w64-mingw32
DMCC ?= $(DMPREFIX)-gcc
DMCXX ?= $(DMPREFIX)-g++
DMWR ?= $(DMPREFIX)-windres
DMSTRIP ?= $(DMPREFIX)-strip
MKDIR ?= mkdir
FIND ?= find
# Extra flags for static linking
EXTRA_FLAGS=-static-libgcc -static-libstdc++ -Wl,--no-whole-archive
endif
# Print info
$(info Discord Messenger makefile)
$(info Debug: $(DEBUG))
$(info Unicode: $(UNICODE))
# -----------------------------
# Include and library paths
# -----------------------------
OPENSSL_INC_DIR = $(OPENSSL_DIR)/include
OPENSSL_LIB_DIR = $(OPENSSL_DIR)
SYSROOTD=
ifdef SYSROOT
SYSROOTD = --sysroot=$(SYSROOT)
endif
INC_DIRS = \
$(USER_INC_DIRS) \
-I$(OPENSSL_INC_DIR) \
-I$(SRC_DIR) \
-I$(SRC_DIR)/core \
-Ideps \
-Ideps/asio \
-Ideps/iprogsthreads/include \
-Ideps/mwas/include
LIB_DIRS = \
-L$(OPENSSL_LIB_DIR)
DEFINES = \
-DWINVER=$(WINVER) \
-D_WIN32_WINNT=$(WINVER) \
-D_WIN32_IE=$(WIN32IE) \
-DASIO_STANDALONE \
-DASIO_DISABLE_IOCP \
-DASIO_HAS_THREADS \
-DASIO_DISABLE_STD_FUTURE \
-DASIO_DISABLE_GETADDRINFO \
-DASIO_SEPARATE_COMPILATION \
-DASIO_IPROGS_THREADS \
-D_WEBSOCKETPP_IPROGS_THREAD_ \
-DMINGW_SPECIFIC_HACKS \
-DDISCORD_MESSENGER \
-DUSE_IPROGS_REIMPL \
-DASIO_DISABLE_WINDOWS_OBJECT_HANDLE \
$(USER_DEFINES)
# Optional git commit hash define
ifneq ($(COMMIT_HASH),undefined)
DEFINES += -DGIT_COMMIT_HASH=$(COMMIT_HASH)
endif
# Unicode defines
# note: USE_IPROGS_REIMPL is defined so that iprogsthreads will use the mwas
# version of certain APIs such as TryEnterCriticalSection
ifeq ($(UNICODE), yes)
UNICODE_DEF = -DUNICODE -D_UNICODE
else
UNICODE_DEF =
endif
# Debug/release flags
ifeq ($(DEBUG), yes)
DEBUG_DEF = -D_DEBUG -g -O0 -fno-omit-frame-pointer
else
DEBUG_DEF = -DNDEBUG -O2 -fno-omit-frame-pointer
endif
# -----------------------------
# Linker subsystem version
# -----------------------------
XL = -Xlinker
MJSSV = $(XL) --major-subsystem-version $(XL)
MNSSV = $(XL) --minor-subsystem-version $(XL)
MJOSV = $(XL) --major-os-version $(XL)
MNOSV = $(XL) --minor-os-version $(XL)
# Give it a subsystem version of 4.0 and an OS version of 1.0
# (replace with 3.10 if you intend to run on NT 3.1)
SSYSVER = $(MJSSV) 4 $(MNSSV) 0 $(MJOSV) 1 $(MNOSV) 0
# -----------------------------
# Compiler and linker flags
# -----------------------------
CXXFLAGS = \
$(INC_DIRS) \
$(DEFINES) \
-MMD \
-std=c++11 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-march=i586 \
$(UNICODE_DEF) \
$(DEBUG_DEF)
LDFLAGS = \
$(LIB_DIRS) \
$(SSYSVER) \
-mwindows \
-lmswsock -lwsock32 -lcomctl32 -lgdi32 -luser32 -lole32 -lcrypt32 \
-lcrypto -lssl \
$(EXTRA_FLAGS)
# Optional WebP support
ifeq ($(DISABLE_WEBP),1)
else
LIB_DIRS += -L$(LIBWEBP_DIR)
LDFLAGS += -lwebp
endif
# Resource compiler flags
WRFLAGS = -Ihacks
# -----------------------------
# Source files
# -----------------------------
# Auxiliary dependencies
AUX_CXXFILES = \
$(shell $(FIND) deps/iprogsthreads/src -not -path '*/.*' -type f -name '*.cpp') \
$(shell $(FIND) deps/asio/src -not -path '*/.*' -type f -name '*.cpp') \
$(shell $(FIND) deps/mwas/src -not -path '*/.*' -type f -name '*.cpp') \
$(shell $(FIND) deps/md5 -not -path '*/.*' -type f -name '*.cpp')
# All source files
CXXFILES := $(shell $(FIND) $(SRC_DIR) -not -path '*/.*' -type f -name '*.cpp') $(AUX_CXXFILES)
RESFILES := $(shell $(FIND) $(SRC_DIR) -not -path '*/.*' -type f -name '*.rc')
# Objects and dependency files
OBJ := $(patsubst %, $(BUILD_DIR)/%, $(CXXFILES:.cpp=.o) $(RESFILES:.rc=.o))
DEP := $(patsubst %, $(BUILD_DIR)/%, $(CXXFILES:.cpp=.d))
# -----------------------------
# Default targets
# -----------------------------
.PHONY: all clean
all: $(TARGET)
clean:
@echo ">> Cleaning build directory"
@rm -rf $(BUILD_DIR)
# Include dependency files
-include $(DEP)
# -----------------------------
# Directory creation rule
# -----------------------------
# Creates any directory needed for a target
$(BUILD_DIR)/%/:
@mkdir -p $@
# -----------------------------
# Compilation patterns
# -----------------------------
# Compute object directory for a given source file
OBJ_DIR = $(BUILD_DIR)/$(dir $<)
# Compile C++ files
$(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR)/%/
@echo ">> Compiling $<"
@$(DMCXX) $(SYSROOTD) $(CXXFLAGS) -c $< -o $@ -MMD -MF $(BUILD_DIR)/$*.d
# Compile resource files
$(BUILD_DIR)/%.o: %.rc | $(BUILD_DIR)/%/
@echo ">> Compiling resource $<"
@$(DMWR) $(WRFLAGS) -i $< -o $@
# -----------------------------
# Linking
# -----------------------------
$(TARGET): $(OBJ)
@echo ">> LINKING $@"
@$(MKDIR) -p $(dir $@)
@$(DMCXX) $(SYSROOTD) $^ $(LDFLAGS) -o $@
ifeq ($(DEBUG),no)
@echo ">> Duplicating binary and stripping symbols"
@cp $@ $(basename $@)-Symbols.exe
@$(DMSTRIP) $@
endif