-
Notifications
You must be signed in to change notification settings - Fork 21
/
makefile
303 lines (206 loc) · 9.09 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
# Source http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
CONFIG := Debug
Debug_CXX_FLAGS := -Og -g
Release_CXX_FLAGS := -O3
CONFIG_CXX_FLAGS := $($(CONFIG)_CXX_FLAGS)
# Determine OS (Linux, Darwin, ...)
CURRENT_OS := $(shell uname 2>/dev/null || echo Unknown)
TARGET_OS ?= $(CURRENT_OS)
ROOTBUILDDIR := .build
BUILDDIRPREFIX := $(ROOTBUILDDIR)/$(CONFIG)_Linux_
## Default and top-level targets ##
.PHONY: all
all: ophd
.PHONY: test
test: testLibOPHD testLibControls
.PHONY: check
check: checkOPHD checkControls
## NAS2D project ##
NAS2DDIR := nas2d-core/
NAS2DINCLUDEDIR := $(NAS2DDIR)
NAS2DLIB := $(NAS2DDIR)lib/libnas2d.a
$(NAS2DLIB): nas2d ;
.PHONY: nas2d
nas2d: $(NAS2DDIR)makefile
$(MAKE) -C nas2d-core
$(NAS2DDIR)makefile:
@echo "\nWARNING: NAS2D dependency not found. Install as Git submodule or download manually."
@if test -d ".git"; then \
echo "Git detected. Attempting to download submodules.\n"; \
git submodule update --init --recursive; \
else \
echo "You don't seem to be using Git. Consider using Git clone.\n"; \
false; \
fi
## Default project flags ##
Linux_OpenGL_LIBS := -lGLEW -lGL
FreeBSD_OpenGL_LIBS := $(Linux_OpenGL_LIBS)
Darwin_OpenGL_LIBS := -lGLEW -framework OpenGL
Windows_OpenGL_LIBS := -lglew32 -lopengl32
OpenGL_LIBS := $($(TARGET_OS)_OpenGL_LIBS)
CPPFLAGS := $(CPPFLAGS_EXTRA)
CXXFLAGS_WARN := -Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wnull-dereference -Wold-style-cast -Wcast-qual -Wcast-align -Wdouble-promotion -Wfloat-conversion -Wsign-conversion -Wshadow -Wnon-virtual-dtor -Woverloaded-virtual -Wmissing-include-dirs -Winvalid-pch -Wmissing-format-attribute $(WARN_EXTRA)
CXXFLAGS := $(CXXFLAGS_EXTRA) $(CONFIG_CXX_FLAGS) -std=c++20 $(CXXFLAGS_WARN) -I$(NAS2DINCLUDEDIR) $(shell sdl2-config --cflags)
LDFLAGS := $(LDFLAGS_EXTRA) $(shell sdl2-config --libs)
LDLIBS := $(LDLIBS_EXTRA) -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf $(OpenGL_LIBS)
PROJECT_FLAGS := $(CPPFLAGS) $(CXXFLAGS)
PROJECT_LINKFLAGS := $(LDFLAGS) $(LDLIBS)
## libOPHD project ##
libOPHD_SRCDIR := libOPHD/
libOPHD_OUTDIR := $(BUILDDIRPREFIX)$(libOPHD_SRCDIR)
libOPHD_OBJDIR := $(libOPHD_OUTDIR)Intermediate/
libOPHD_OUTPUT := $(libOPHD_OUTDIR)libOPHD.a
libOPHD_SRCS := $(shell find $(libOPHD_SRCDIR) -name '*.cpp')
libOPHD_OBJS := $(patsubst $(libOPHD_SRCDIR)%.cpp,$(libOPHD_OBJDIR)%.o,$(libOPHD_SRCS))
.PHONY: libOphd
libOphd: $(libOPHD_OUTPUT)
$(libOPHD_OUTPUT): $(libOPHD_OBJS)
$(libOPHD_OBJS): $(libOPHD_OBJDIR)%.o : $(libOPHD_SRCDIR)%.cpp $(libOPHD_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(libOPHD_OBJS)))
## libControls project ##
libControls_SRCDIR := libControls/
libControls_OUTDIR := $(BUILDDIRPREFIX)$(libControls_SRCDIR)
libControls_OBJDIR := $(libControls_OUTDIR)Intermediate/
libControls_OUTPUT := $(libControls_OUTDIR)libControls.a
libControls_SRCS := $(shell find $(libControls_SRCDIR) -name '*.cpp')
libControls_OBJS := $(patsubst $(libControls_SRCDIR)%.cpp,$(libControls_OBJDIR)%.o,$(libControls_SRCS))
.PHONY: libControls
libControls: $(libControls_OUTPUT)
$(libControls_OUTPUT): $(libControls_OBJS)
$(libControls_OBJS): $(libControls_OBJDIR)%.o : $(libControls_SRCDIR)%.cpp $(libControls_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(libControls_OBJS)))
## testLibOPHD project ##
testLibOphd_SRCDIR := testLibOPHD/
testLibOphd_OBJDIR := $(BUILDDIRPREFIX)$(testLibOphd_SRCDIR)Intermediate/
testLibOphd_OUTPUT := $(BUILDDIRPREFIX)$(testLibOphd_SRCDIR)testLibOPHD
testLibOphd_SRCS := $(shell find $(testLibOphd_SRCDIR) -name '*.cpp')
testLibOphd_OBJS := $(patsubst $(testLibOphd_SRCDIR)%.cpp,$(testLibOphd_OBJDIR)%.o,$(testLibOphd_SRCS))
testLibOphd_CPPFLAGS := $(CPPFLAGS) -I./
testLibOphd_LDLIBS := -lgtest -lgtest_main -lgmock -lgmock_main -lpthread $(LDLIBS)
testLibOphd_PROJECT_FLAGS := $(testLibOphd_CPPFLAGS) $(CXXFLAGS)
testLibOphd_PROJECT_LINKFLAGS = $(LDFLAGS) $(testLibOphd_LDLIBS)
.PHONY: testLibOPHD
testLibOPHD: $(testLibOphd_OUTPUT)
.PHONY: checkOPHD
checkOPHD: $(testLibOphd_OUTPUT)
$(testLibOphd_OUTPUT)
$(testLibOphd_OUTPUT): PROJECT_LINKFLAGS := $(testLibOphd_PROJECT_LINKFLAGS)
$(testLibOphd_OUTPUT): $(testLibOphd_OBJS) $(libOPHD_OUTPUT) $(NAS2DLIB)
$(testLibOphd_OBJS): PROJECT_FLAGS := $(testLibOphd_PROJECT_FLAGS)
$(testLibOphd_OBJS): $(testLibOphd_OBJDIR)%.o : $(testLibOphd_SRCDIR)%.cpp $(testLibOphd_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(testLibOphd_OBJS)))
## testLibControls project ##
testLibControls_SRCDIR := testLibControls/
testLibControls_OBJDIR := $(BUILDDIRPREFIX)$(testLibControls_SRCDIR)Intermediate/
testLibControls_OUTPUT := $(BUILDDIRPREFIX)$(testLibControls_SRCDIR)testLibControls
testLibControls_SRCS := $(shell find $(testLibControls_SRCDIR) -name '*.cpp')
testLibControls_OBJS := $(patsubst $(testLibControls_SRCDIR)%.cpp,$(testLibControls_OBJDIR)%.o,$(testLibControls_SRCS))
testLibControls_CPPFLAGS := $(CPPFLAGS) -I./
testLibControls_LDLIBS := -lgtest -lgtest_main -lgmock -lgmock_main -lpthread $(LDLIBS)
testLibControls_PROJECT_FLAGS := $(testLibControls_CPPFLAGS) $(CXXFLAGS)
testLibControls_PROJECT_LINKFLAGS = $(LDFLAGS) $(testLibControls_LDLIBS)
.PHONY: testLibControls
testLibControls: $(testLibControls_OUTPUT)
.PHONY: checkControls
checkControls: $(testLibControls_OUTPUT)
$(testLibControls_OUTPUT)
$(testLibControls_OUTPUT): PROJECT_LINKFLAGS := $(testLibControls_PROJECT_LINKFLAGS)
$(testLibControls_OUTPUT): $(testLibControls_OBJS) $(libControls_OUTPUT) $(NAS2DLIB)
$(testLibControls_OBJS): PROJECT_FLAGS := $(testLibControls_PROJECT_FLAGS)
$(testLibControls_OBJS): $(testLibControls_OBJDIR)%.o : $(testLibControls_SRCDIR)%.cpp $(testLibControls_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(testLibControls_OBJS)))
## demoLibControls project ##
demoLibControls_SRCDIR := demoLibControls/
demoLibControls_OBJDIR := $(BUILDDIRPREFIX)$(demoLibControls_SRCDIR)Intermediate/
demoLibControls_OUTPUT := $(BUILDDIRPREFIX)$(demoLibControls_SRCDIR)demoLibControls
demoLibControls_SRCS := $(shell find $(demoLibControls_SRCDIR) -name '*.cpp')
demoLibControls_OBJS := $(patsubst $(demoLibControls_SRCDIR)%.cpp,$(demoLibControls_OBJDIR)%.o,$(demoLibControls_SRCS))
demoLibControls_CPPFLAGS := $(CPPFLAGS) -I./
demoLibControls_PROJECT_FLAGS := $(demoLibControls_CPPFLAGS) $(CXXFLAGS)
.PHONY: demoLibControls
demoLibControls: $(demoLibControls_OUTPUT)
.PHONY: runDemoControls
runDemoControls:
$(demoLibControls_OUTPUT)
$(demoLibControls_OUTPUT): $(demoLibControls_OBJS) $(libControls_OUTPUT) $(NAS2DLIB)
$(demoLibControls_OBJS): PROJECT_FLAGS := $(demoLibControls_PROJECT_FLAGS)
$(demoLibControls_OBJS): $(demoLibControls_OBJDIR)%.o : $(demoLibControls_SRCDIR)%.cpp $(demoLibControls_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(demoLibControls_OBJS)))
## OPHD project ##
ophd_SRCDIR := OPHD/
ophd_OBJDIR := $(BUILDDIRPREFIX)$(ophd_SRCDIR)Intermediate/
ophd_OUTPUT := ophd.exe
ophd_SRCS := $(shell find $(ophd_SRCDIR) -name '*.cpp')
ophd_OBJS := $(patsubst $(ophd_SRCDIR)%.cpp,$(ophd_OBJDIR)%.o,$(ophd_SRCS))
ophd_CPPFLAGS := $(CPPFLAGS) -I./
ophd_PROJECT_FLAGS := $(ophd_CPPFLAGS) $(CXXFLAGS)
.PHONY: ophd
ophd: $(ophd_OUTPUT)
$(ophd_OUTPUT): $(ophd_OBJS) $(libOPHD_OUTPUT) $(libControls_OUTPUT) $(NAS2DLIB)
$(ophd_OBJS): PROJECT_FLAGS := $(ophd_PROJECT_FLAGS)
$(ophd_OBJS): $(ophd_OBJDIR)%.o : $(ophd_SRCDIR)%.cpp $(ophd_OBJDIR)%.d
include $(wildcard $(patsubst %.o,%.d,$(ophd_OBJS)))
.PHONY: intermediate
intermediate: $(ophd_OBJS)
## Compile rules ##
DEPFLAGS = -MT $@ -MMD -MP -MF $(@:.o=.Td)
COMPILE.cpp = $(CXX) $(DEPFLAGS) $(PROJECT_FLAGS) $(TARGET_ARCH) -c
POSTCOMPILE = @mv -f $(@:.o=.Td) $(@:.o=.d) && touch $@
%:
@mkdir -p "${@D}"
$(CXX) $^ $(PROJECT_LINKFLAGS) -o $@
lib%.a:
@mkdir -p "${@D}"
ar rcs $@ $^
%.o:
@mkdir -p "${@D}"
$(COMPILE.cpp) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
%.d: ;
.PRECIOUS: %.d
## Clean ##
.PHONY: clean clean-all
clean:
-rm -fr $(libOPHD_OBJDIR)
-rm -fr $(libControls_OBJDIR)
-rm -fr $(testLibOphd_OBJDIR)
-rm -fr $(testLibControls_OBJDIR)
-rm -fr $(ophd_OBJDIR)
clean-all:
-rm -rf $(ROOTBUILDDIR)
-rm -f $(ophd_OUTPUT)
## Package ##
PACKAGEDIR := $(ROOTBUILDDIR)/package/
VERSION = $(shell git describe --tags --dirty)
CONFIG = $(TARGET_OS).x64
PACKAGE_NAME = $(PACKAGEDIR)ophd-$(VERSION)-$(CONFIG).tar.gz
.PHONY: package
package: $(PACKAGE_NAME)
$(PACKAGE_NAME): $(ophd_OUTPUT)
@mkdir -p "$(PACKAGEDIR)"
tar -czf $(PACKAGE_NAME) $(ophd_OUTPUT)
## Dependencies ##
.PHONY: install-dependencies
install-dependencies:
$(MAKE) -C nas2d-core install-dependencies
## Linting ##
.PHONY: show-warnings
show-warnings:
@$(MAKE) clean > /dev/null
$(MAKE) --output-sync all CXX=clang++ CXXFLAGS_WARN=-Weverything 2>&1 >/dev/null | grep -o "\[-W.*\]" | sort | uniq
@$(MAKE) clean > /dev/null
.PHONY: lint
lint: cppcheck cppclean cppinclude
.PHONY: cppcheck
cppcheck:
cppcheck --quiet "$(ophd_SRCDIR)"
.PHONY: cppclean
cppclean:
cppclean --quiet --include-path "$(NAS2DINCLUDEDIR)" --include-path "/usr/include/SDL2" --exclude "MicroPather" "$(ophd_SRCDIR)"
.PHONY: cppinclude
cppinclude:
cppinclude
.PHONY: format
format:
@clang-format --version
find $(ophd_SRCDIR) \( -name '*.cpp' -o -name '*.h' \) \! -name 'resource.h' -o -path '$(ophd_SRCDIR)MicroPather' -prune -type f | xargs clang-format -i