forked from pluot-mb/CCCaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
474 lines (373 loc) · 13.7 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
VERSION = 3.0
SUFFIX = .023
NAME = cccaster
TAG =
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifneq ($(TAG),)
DOT_TAG = .$(TAG)
endif
# Main program files
ARCHIVE = $(NAME).v$(VERSION)$(SUFFIX)$(DOT_TAG).zip
BINARY = $(NAME).v$(VERSION)$(DOT_TAG).exe
FOLDER = $(NAME)
PALETTES_FOLDER = palettes
DLL = hook$(DOT_TAG).dll
LAUNCHER = launcher.exe
UPDATER = updater.exe
DEBUGGER = debugger.exe
GENERATOR = generator.exe
PALETTES = palettes.exe
MBAA_EXE = MBAA.exe
README = README.md
CHANGELOG = ChangeLog.txt
RELAY_LIST = relay_list.txt
# Library sources
GTEST_CC_SRCS = 3rdparty/gtest/fused-src/gtest/gtest-all.cc
JLIB_CC_SRCS = $(wildcard 3rdparty/JLib/*.cc)
HOOK_CC_SRCS = $(wildcard 3rdparty/minhook/src/*.cc 3rdparty/d3dhook/*.cc)
HOOK_C_SRCS = $(wildcard 3rdparty/minhook/src/hde32/*.c)
CONTRIB_CC_SRCS = $(GTEST_CC_SRCS) $(JLIB_CC_SRCS)
CONTRIB_C_SRCS = $(wildcard 3rdparty/*.c)
# Main program sources
LIB_CPP_SRCS = $(wildcard lib/*.cpp)
BASE_CPP_SRCS = $(wildcard netplay/*.cpp) $(LIB_CPP_SRCS)
MAIN_CPP_SRCS = $(wildcard targets/Main*.cpp tests/*.cpp) $(BASE_CPP_SRCS)
DLL_CPP_SRCS = $(wildcard targets/Dll*.cpp) $(filter-out lib/ConsoleUi.cpp,$(BASE_CPP_SRCS))
NON_GEN_SRCS = \
$(wildcard netplay/*.cpp tools/*.cpp targets/*.cpp lib/*.cpp tests/*.cpp)
NON_GEN_HEADERS = \
$(filter-out lib/Version.%.hpp lib/Protocol.%.hpp,$(wildcard netplay/*.hpp targets/*.hpp lib/*.hpp tests/*.hpp))
AUTOGEN_HEADERS = $(wildcard lib/Version.*.hpp lib/Protocol.*.hpp)
# Main program objects
LIB_OBJECTS = $(LIB_CPP_SRCS:.cpp=.o) $(CONTRIB_C_SRCS:.c=.o)
MAIN_OBJECTS = $(MAIN_CPP_SRCS:.cpp=.o) $(CONTRIB_CC_SRCS:.cc=.o) $(CONTRIB_C_SRCS:.c=.o)
DLL_OBJECTS = $(DLL_CPP_SRCS:.cpp=.o) $(HOOK_CC_SRCS:.cc=.o) $(HOOK_C_SRCS:.c=.o) $(CONTRIB_C_SRCS:.c=.o)
# Tool chain
PREFIX = i686-w64-mingw32-
GCC = $(PREFIX)gcc
CXX = $(PREFIX)g++
WINDRES = windres
STRIP = strip
TOUCH = touch
ZIP = zip
UNAME := $(shell uname)
$(info VAR=$(UNAME))
# OS specific tools / settings
ifeq ($(OS),Windows_NT)
CHMOD_X = icacls $@ /grant Everyone:F
GRANT = icacls $@ /grant Everyone:F
ASTYLE = 3rdparty/astyle.exe
OPENGL_HEADERS = /usr/mingw/i686-w64-mingw32/include/GL
else
WINDRES = $(PREFIX)windres
STRIP = $(PREFIX)strip
CHMOD_X = chmod +x $@
GRANT =
ASTYLE = 3rdparty/astyle
TOUCH = $(STRIP)
OPENGL_HEADERS = /usr/i686-w64-mingw32/include/GL
endif
# Build flags
DEFINES = -DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_WIN32_WINNT=0x501 -D_M_IX86
DEFINES += -DNAMED_PIPE='"\\\\.\\pipe\\cccaster_pipe"' -DPALETTES_FOLDER='"$(PALETTES_FOLDER)\\"' -DREADME='"$(README)"'
DEFINES += -DMBAA_EXE='"$(MBAA_EXE)"' -DBINARY='"$(BINARY)"' -DFOLDER='"$(FOLDER)\\"' -DCHANGELOG='"$(CHANGELOG)"'
DEFINES += -DHOOK_DLL='"$(FOLDER)\\$(DLL)"' -DLAUNCHER='"$(FOLDER)\\$(LAUNCHER)"' -DUPDATER='"$(UPDATER)"'
DEFINES += -DRELAY_LIST='"$(RELAY_LIST)"'
INCLUDES = -I$(CURDIR) -I$(CURDIR)/netplay -I$(CURDIR)/lib -I$(CURDIR)/tests -I$(CURDIR)/3rdparty
INCLUDES += -I$(CURDIR)/3rdparty/cereal/include -I$(CURDIR)/3rdparty/gtest/include -I$(CURDIR)/3rdparty/minhook/include
INCLUDES += -I$(CURDIR)/3rdparty/d3dhook -I$(CURDIR)/3rdparty/framedisplay
CC_FLAGS = -m32 $(INCLUDES) $(DEFINES)
# Linker flags
LD_FLAGS = -m32 -static -lws2_32 -lpsapi -lwinpthread -lwinmm -lole32 -ldinput -lwininet
# Build options
# DEFINES += -DDISABLE_LOGGING
# DEFINES += -DDISABLE_ASSERTS
# DEFINES += -DLOGGER_MUTEXED
# DEFINES += -DJLIB_MUTEXED
# Install after make, set to 0 to disable install after make
INSTALL = 1
# Build type flags
DEBUG_FLAGS = -ggdb3 -O0 -fno-inline -D_GLIBCXX_DEBUG -DDEBUG
ifeq ($(OS),Windows_NT)
LOGGING_FLAGS = -s -Os -O2 -DLOGGING -DRELEASE
else
LOGGING_FLAGS = -s -Os -O2 -DLOGGING
endif
RELEASE_FLAGS = -s -Os -Ofast -fno-rtti -DNDEBUG -DRELEASE -DDISABLE_LOGGING -DDISABLE_ASSERTS
# Build type
BUILD_TYPE = build_debug
BUILD_PREFIX = $(BUILD_TYPE)_$(BRANCH)
# Default build target
ifeq ($(OS),Windows_NT)
DEFAULT_TARGET = debug
else
DEFAULT_TARGET = logging
endif
all: $(DEFAULT_TARGET)
# target-profile: STRIP = $(TOUCH)
# target-profile: DEFINES += -DNDEBUG -DRELEASE -DDISABLE_LOGGING -DDISABLE_ASSERTS
# target-profile: CC_FLAGS += -O2 -fno-rtti -pg
# target-profile: LD_FLAGS += -pg -lgmon
# target-profile: $(ARCHIVE)
launcher: $(FOLDER)/$(LAUNCHER)
debugger: tools/$(DEBUGGER)
generator: tools/$(GENERATOR)
palettes: $(PALETTES)
$(ARCHIVE): $(BINARY) $(FOLDER)/$(DLL) $(FOLDER)/$(LAUNCHER) $(FOLDER)/$(UPDATER)
$(ARCHIVE): $(FOLDER)/unzip.exe $(FOLDER)/$(README) $(FOLDER)/$(CHANGELOG)
@echo
rm -f $(wildcard $(NAME)*.zip)
$(ZIP) $(ARCHIVE) $^
$(ZIP) $(ARCHIVE) -j scripts/Add_Handler_Protocol.bat
$(ZIP) $(ARCHIVE) -j $(RELAY_LIST)
cp -r res/GRP GRP
$(ZIP) $(ARCHIVE) -r GRP
rm -rf GRP
$(GRANT)
$(BINARY): $(addprefix $(BUILD_PREFIX)/,$(MAIN_OBJECTS)) res/icon.res
rm -f $(filter-out $(BINARY),$(wildcard $(NAME)*.exe))
$(CXX) -o $@ $(CC_FLAGS) -Wall -std=c++11 $^ $(LD_FLAGS)
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
$(FOLDER)/$(DLL): $(addprefix $(BUILD_PREFIX)/,$(DLL_OBJECTS)) res/rollback.o | $(FOLDER)
$(CXX) -o $@ $(CC_FLAGS) -Wall -std=c++11 $^ -shared $(LD_FLAGS) -ld3dx9
@echo
$(STRIP) $@
$(GRANT)
@echo
$(FOLDER)/$(LAUNCHER): tools/Launcher.cpp | $(FOLDER)
$(CXX) -o $@ $^ -m32 -s -Os -O2 -Wall -static -mwindows
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
$(FOLDER)/$(UPDATER): tools/Updater.cpp lib/StringUtils.cpp | $(FOLDER)
$(CXX) -o $@ $^ -m32 -s -Os -O2 -std=c++11 -I$(CURDIR)/lib -Wall -static -lpsapi
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
$(FOLDER)/unzip.exe: 3rdparty/unzip.exe | $(FOLDER)
cp -f $^ $(FOLDER)/
$(FOLDER)/$(README): $(README) | $(FOLDER)
cp -f $^ $(FOLDER)/
$(FOLDER)/$(CHANGELOG): $(CHANGELOG) | $(FOLDER)
cp -f $^ $(FOLDER)/
$(FOLDER):
mkdir -p $@
res/rollback.bin: tools/$(GENERATOR)
ifeq ($(UNAME),Darwin)
wine tools/$(GENERATOR) $@
else
tools/$(GENERATOR) $@
endif
@echo
res/rollback.o: res/rollback.bin
ifeq ($(UNAME),Darwin)
$(PREFIX)objcopy -I binary -O elf32-i386 -B i386 $< $@
else
objcopy -I binary -O elf32-i386 -B i386 $< $@
endif
@echo
res/icon.res: res/icon.rc res/icon.ico
$(WINDRES) -F pe-i386 res/icon.rc -O coff -o $@
@echo
LOGGING_PREFIX = build_logging_$(BRANCH)
DEBUGGER_LIB_OBJECTS = \
$(addprefix $(LOGGING_PREFIX)/,$(filter-out lib/Version.o lib/LoggerLogVersion.o lib/ConsoleUi.o,$(LIB_OBJECTS)))
tools/$(DEBUGGER): tools/Debugger.cpp $(DEBUGGER_LIB_OBJECTS)
$(CXX) -o $@ $(CC_FLAGS) $(LOGGING_FLAGS) -Wall -std=c++11 $^ $(LD_FLAGS) \
-I$(CURDIR)/3rdparty/distorm3/include -L$(CURDIR)/3rdparty/distorm3 -ldistorm3
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
GENERATOR_LIB_OBJECTS = \
$(addprefix $(LOGGING_PREFIX)/,$(filter-out lib/Version.o lib/LoggerLogVersion.o lib/ConsoleUi.o,$(LIB_OBJECTS)))
tools/$(GENERATOR): tools/Generator.cpp $(GENERATOR_LIB_OBJECTS)
$(CXX) -o $@ $(CC_FLAGS) $(LOGGING_FLAGS) -Wall -std=c++11 $^ $(LD_FLAGS)
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
PALETTES_SRC = tools/Palettes.cpp tools/PaletteEditor.cpp netplay/PaletteManager.cpp netplay/CharacterSelect.cpp
PALETTES_SRC += lib/StringUtils.cpp lib/KeyValueStore.cpp
FRAMEDISPLAY_SRC = $(wildcard 3rdparty/framedisplay/*.cc)
FRAMEDISPLAY_OBJECTS = $(FRAMEDISPLAY_SRC:.cc=.o)
FRAMEDISPLAY_INCLUDES = -I$(CURDIR) -I$(CURDIR)/netplay -I$(CURDIR)/lib -I$(CURDIR)/3rdparty/framedisplay
FRAMEDISPLAY_INCLUDES += -I$(CURDIR)/3rdparty/libpng -I$(CURDIR)/3rdparty/libz -I$(CURDIR)/3rdparty/glfw
FRAMEDISPLAY_INCLUDES += -I"$(CURDIR)/3rdparty/AntTweakBar/include" -I$(OPENGL_HEADERS)
# FRAMEDISPLAY_CC_FLAGS = -ggdb3 -O0 -fno-inline -D_GLIBCXX_DEBUG -DDEBUG
FRAMEDISPLAY_CC_FLAGS = -s -Os -Ofast -fno-rtti
FRAMEDISPLAY_CC_FLAGS += -DDISABLE_LOGGING -DDISABLE_SERIALIZATION -DPALETTES_FOLDER='"$(PALETTES_FOLDER)\\"'
FRAMEDISPLAY_LD_FLAGS = -L$(CURDIR)/3rdparty/libpng -L$(CURDIR)/3rdparty/libz -L"$(CURDIR)/3rdparty/AntTweakBar/lib"
FRAMEDISPLAY_LD_FLAGS += -L$(CURDIR)/3rdparty/glfw
FRAMEDISPLAY_LD_FLAGS += -mwindows -static -lmingw32 -lpng -lz -lglfw -lopengl32 -lglu32
3rdparty/framedisplay/%.o: 3rdparty/framedisplay/%.cc
$(CXX) $(FRAMEDISPLAY_CC_FLAGS) $(FRAMEDISPLAY_INCLUDES) -o $@ -c $<
3rdparty/AntTweakBar/lib/libAntTweakBar.a: $(wildcard 3rdparty/AntTweakBar/src/*.c* 3rdparty/AntTweakBar/src/*.h)
$(MAKE) --directory=3rdparty/AntTweakBar/src
$(PALETTES): $(PALETTES_SRC) $(FRAMEDISPLAY_OBJECTS) res/palettes.res 3rdparty/AntTweakBar/lib/libAntTweakBar.a
$(CXX) $(FRAMEDISPLAY_CC_FLAGS) -o $@ $(FRAMEDISPLAY_INCLUDES) -Wall -std=c++11 -C $^ $(FRAMEDISPLAY_LD_FLAGS)
@echo
$(STRIP) $@
$(CHMOD_X)
@echo
res/palettes.res: res/palettes.rc res/palettes.ico
$(WINDRES) -F pe-i386 res/palettes.rc -O coff -o $@
@echo
define make_version
@scripts/make_version $(VERSION)$(SUFFIX) > lib/Version.local.hpp
endef
define make_protocol
@scripts/make_protocol $(NON_GEN_HEADERS)
endef
define make_depend
@scripts/make_depend "$(CXX)" "-m32 $(INCLUDES)"
endef
version:
$(make_version)
proto:
$(make_protocol)
reset-proto:
rm -f lib/ProtocolEnums.hpp
@$(MAKE) proto
depend: version proto
$(make_depend)
.depend_$(BRANCH): $(NON_GEN_SRCS) $(NON_GEN_HEADERS)
$(make_version)
$(make_protocol)
$(make_depend)
clean-proto:
git checkout -- lib/ProtocolEnums.hpp
rm -f $(AUTOGEN_HEADERS)
clean-res:
rm -f res/rollback.* res/icon.res
rm -rf GRP
clean-lib:
$(MAKE) --directory=3rdparty/AntTweakBar/src clean
rm -f 3rdparty/framedisplay/*.o
clean-common: clean-proto clean-res clean-lib
rm -rf tmp*
rm -f .depend_$(BRANCH) .include_$(BRANCH) *.exe *.zip tools/*.exe \
$(filter-out $(FOLDER)/config.ini $(wildcard $(FOLDER)/*.mappings $(FOLDER)/*.log),$(wildcard $(FOLDER)/*))
clean-debug: clean-common
rm -rf build_debug_$(BRANCH)
clean-logging: clean-common
rm -rf build_logging_$(BRANCH)
clean-release: clean-common
rm -rf build_release_$(BRANCH)
clean: clean-debug clean-logging clean-release
clean-all: clean-debug clean-logging clean-release
rm -rf .include* .depend* build*
check:
cppcheck --enable=all $(NON_GEN_SRCS) $(NON_GEN_HEADERS)
trim:
sed --binary --in-place 's/\\r$$//' $(NON_GEN_SRCS) $(NON_GEN_HEADERS)
sed --in-place 's/[[:space:]]\\+$$//' $(NON_GEN_SRCS) $(NON_GEN_HEADERS)
format:
$(ASTYLE) \
--indent=spaces=4 \
--convert-tabs \
--indent-preprocessor \
--indent-switches \
--style=allman \
--max-code-length=120 \
--pad-paren \
--pad-oper \
--suffix=none \
--formatted \
--keep-one-line-blocks \
--align-pointer=name \
--align-reference=type \
$(filter-out tools/Generator.cpp netplay/CharacterSelect.cpp lib/KeyboardVKeyNames.hpp targets/DllAsmHacks.hpp,\
$(NON_GEN_SRCS) $(NON_GEN_HEADERS))
count:
@wc -l $(NON_GEN_SRCS) $(NON_GEN_HEADERS) | sort -nr | head -n 10 && echo ' ...'
ifeq (,$(findstring version,$(MAKECMDGOALS)))
ifeq (,$(findstring proto,$(MAKECMDGOALS)))
ifeq (,$(findstring depend,$(MAKECMDGOALS)))
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring check,$(MAKECMDGOALS)))
ifeq (,$(findstring trim,$(MAKECMDGOALS)))
ifeq (,$(findstring format,$(MAKECMDGOALS)))
ifeq (,$(findstring count,$(MAKECMDGOALS)))
ifeq (,$(findstring install,$(MAKECMDGOALS)))
ifeq (,$(findstring palettes,$(MAKECMDGOALS)))
-include .depend_$(BRANCH)
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
pre-build:
$(make_version)
$(make_protocol)
@echo
@echo ========== Main-build ==========
@echo
post-build: main-build
@echo
@echo ========== Post-build ==========
@echo
if [ $(INSTALL) = 1 ] && [ -s ./scripts/install ]; then ./scripts/install; fi;
debug: post-build
logging: post-build
release: post-build
profile: post-build
target-debug: $(ARCHIVE)
target-logging: $(ARCHIVE)
target-release: $(ARCHIVE)
ifneq (,$(findstring logging,$(MAKECMDGOALS)))
main-build: pre-build
@$(MAKE) --no-print-directory target-logging BUILD_TYPE=build_logging
else
ifneq (,$(findstring release,$(MAKECMDGOALS)))
main-build: pre-build
@$(MAKE) --no-print-directory target-release BUILD_TYPE=build_release
else
ifneq (,$(findstring profile,$(MAKECMDGOALS)))
main-build: pre-build
@$(MAKE) --no-print-directory target-profile BUILD_TYPE=build_debug STRIP=touch
else
ifeq ($(DEFAULT_TARGET),logging)
main-build: pre-build
@$(MAKE) --no-print-directory target-logging BUILD_TYPE=build_logging
else
main-build: pre-build
@$(MAKE) --no-print-directory target-debug BUILD_TYPE=build_debug STRIP=touch
endif
endif
endif
endif
build_debug_$(BRANCH):
rsync -a -f"- .git/" -f"- build_*/" -f"+ */" -f"- *" --exclude=".*" . $@
build_debug_$(BRANCH)/%.o: %.cpp | build_debug_$(BRANCH)
$(CXX) $(CC_FLAGS) $(DEBUG_FLAGS) -Wall -Wempty-body -std=c++11 -o $@ -c $<
build_debug_$(BRANCH)/%.o: %.cc | build_debug_$(BRANCH)
$(CXX) $(CC_FLAGS) $(DEBUG_FLAGS) -o $@ -c $<
build_debug_$(BRANCH)/%.o: %.c | build_debug_$(BRANCH)
$(GCC) $(filter-out -fno-rtti,$(CC_FLAGS) $(DEBUG_FLAGS)) -Wno-attributes -o $@ -c $<
build_logging_$(BRANCH):
rsync -a -f"- .git/" -f"- build_*/" -f"+ */" -f"- *" --exclude=".*" . $@
build_logging_$(BRANCH)/%.o: %.cpp | build_logging_$(BRANCH)
$(CXX) $(CC_FLAGS) $(LOGGING_FLAGS) -Wall -Wempty-body -std=c++11 -o $@ -c $<
build_logging_$(BRANCH)/%.o: %.cc | build_logging_$(BRANCH)
$(CXX) $(CC_FLAGS) $(LOGGING_FLAGS) -o $@ -c $<
build_logging_$(BRANCH)/%.o: %.c | build_logging_$(BRANCH)
$(GCC) $(filter-out -fno-rtti,$(CC_FLAGS) $(LOGGING_FLAGS)) -Wno-attributes -o $@ -c $<
build_release_$(BRANCH):
rsync -a -f"- .git/" -f"- build_*/" -f"+ */" -f"- *" --exclude=".*" . $@
build_release_$(BRANCH)/%.o: %.cpp | build_release_$(BRANCH)
$(CXX) $(CC_FLAGS) $(RELEASE_FLAGS) -std=c++11 -o $@ -c $<
build_release_$(BRANCH)/%.o: %.cc | build_release_$(BRANCH)
$(CXX) $(CC_FLAGS) $(RELEASE_FLAGS) -o $@ -c $<
build_release_$(BRANCH)/%.o: %.c | build_release_$(BRANCH)
$(GCC) $(filter-out -fno-rtti,$(CC_FLAGS) $(RELEASE_FLAGS)) -Wno-attributes -o $@ -c $<