-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
200 lines (159 loc) · 6.1 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
# Taken from https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
CC = clang
CXX = clang++
GIT_HASH := $(shell git describe --always --dirty)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
BUILD_DIR ?= build
ZIPFLAGS := -rq
RMDIR := $(RM) -r
MKDIR_P ?= mkdir -p
SRC_DIRS ?= $(shell find src -type d -not -path src)
SRC_DIRS += vendor/glad vendor/nanovg vendor/nanogui vendor/pugixml vendor
UNAME := $(shell uname)
SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c')
INCFLAGS := $(addprefix -I, $(SRC_DIRS))
CPPFLAGS := ${CPPFLAGS}
CPPFLAGS += $(INCFLAGS) -MMD -MP -DNANOGUI_GLAD -g -Wall
# Compile with clang UBSAN
ifeq ($(AVARA_UBSAN), TRUE)
LD = clang++
CPPFLAGS += -fsanitize=undefined -g -fno-omit-frame-pointer
LDFLAGS += -fsanitize=undefined -g
endif
# Compile with extra warnings
ifeq ($(AVARA_WARNINGS), TRUE)
CPPFLAGS += -pedantic -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy
CPPFLAGS += -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations
CPPFLAGS += -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow
CPPFLAGS += -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef
CPPFLAGS += -Wno-unused-function -Wno-multichar -Wno-gnu-anonymous-struct -Wno-unused-parameter
endif
CXXFLAGS := ${CXXFLAGS}
CXXFLAGS += -std=c++17
LDFLAGS := ${LDFLAGS}
ifeq ($(UNAME), Darwin)
# MacOS
SRCS += $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.mm')
INC_EXTRA := -I/opt/homebrew/include -I/usr/local/include
CXXFLAGS += -mmacosx-version-min=10.9 $(INC_EXTRA)
CPPFLAGS += -mmacosx-version-min=10.9 $(INC_EXTRA)
CFLAGS += -mmacosx-version-min=10.9 $(INC_EXTRA)
ifneq ("$(wildcard $(HOME)/Library/Frameworks/SDL2.framework)", "")
FRAMEWORK_PATH = $(HOME)/Library/Frameworks
else
FRAMEWORK_PATH = /Library/Frameworks
endif
CPPFLAGS += -F$(FRAMEWORK_PATH)
LDFLAGS += -F$(FRAMEWORK_PATH) -rpath $(FRAMEWORK_PATH) -L/opt/homebrew/lib -L/usr/local/lib -lstdc++ -lm -lpthread -framework SDL2 -framework OpenGL -framework AppKit
POST_PROCESS ?= dsymutil
JOBS := $(shell sysctl -n hw.ncpu)
# if the -j option was passed, use that instead
MAKE_PID := $(shell echo $$PPID)
JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
ifneq ($(JOB_FLAG),)
JOBS := $(subst -j,,$(JOB_FLAG))
endif
else ifneq (,$(findstring NT-10.0,$(UNAME)))
# Windows - should match for MSYS2 on Win10
WINDRES := $(shell which windres)
PLATFORM := platform/windows
PRE_PROCESS += $(WINDRES) $(PLATFORM)/appicon.rc -O coff $(BUILD_DIR)/appicon.o;
PRE_PROCESS += $(WINDRES) $(PLATFORM)/version.rc -O coff $(BUILD_DIR)/version.o;
EXTRA_OBJS += $(BUILD_DIR)/appicon.o $(BUILD_DIR)/version.o
LDFLAGS += -lstdc++ -lm -lpthread -lmingw32 -lSDL2main -lSDL2 -lglu32 -lopengl32 -lws2_32 -lcomdlg32
CPPFLAGS += -Wno-unknown-pragmas
CFLAGS += -D_WIN32_WINNT=0x501
POST_PROCESS ?= ls -lh
else
# Linux
PKG_CONFIG ?= pkg-config
LDFLAGS += -lstdc++ -lm -lpthread -ldl
LDFLAGS += $(shell ${PKG_CONFIG} --libs-only-l glu)
LDFLAGS += $(shell ${PKG_CONFIG} --libs-only-l sdl2)
CPPFLAGS += $(shell ${PKG_CONFIG} --cflags-only-I directfb)
CPPFLAGS += $(shell ${PKG_CONFIG} --cflags-only-I sdl2)
CPPFLAGS += -fPIC
POST_PROCESS ?= ls -lh
endif
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
# Use the command "make macapp SIGNING_ID=yourid" if you want to use your signing id.
# Alternatively set this to "NONE" for no code signing.
SIGNING_ID := NONE
avara: set-version $(BUILD_DIR)/Avara resources
tests: set-version $(BUILD_DIR)/tests resources
$(BUILD_DIR)/tests
bspviewer: $(BUILD_DIR)/BSPViewer resources
levelviewer: $(BUILD_DIR)/AvaraLevelViewer resources
hsnd2wav: $(BUILD_DIR)/hsnd2wav resources
frandom: $(BUILD_DIR)/frandom
fixed: $(BUILD_DIR)/fixed
macapp:
xcodebuild -configuration Debug -scheme Avara \
-IDEBuildOperationMaxNumberOfConcurrentCompileTasks=$(JOBS) \
-derivedDataPath $(BUILD_DIR)/DerivedData \
ONLY_ACTIVE_ARCH=NO \
CONFIGURATION_BUILD_DIR=$(BUILD_DIR)
macdist: macapp
cd $(BUILD_DIR) && zip $(ZIPFLAGS) MacAvara.zip Avara.app && cd ..
winapp: avara
$(RMDIR) $(BUILD_DIR)/WinAvara
$(MKDIR_P) $(BUILD_DIR)/WinAvara
cp -r $(BUILD_DIR)/{Avara.exe,levels,rsrc} $(BUILD_DIR)/WinAvara
cp /mingw64/bin/{libstdc++-6,libwinpthread-1,libgcc_s_seh-1,SDL2}.dll $(BUILD_DIR)/WinAvara
windist: winapp
cd $(BUILD_DIR) && zip $(ZIPFLAGS) WinAvara.zip WinAvara && cd ..
# Avara
$(BUILD_DIR)/Avara: $(OBJS) $(BUILD_DIR)/src/Avara.cpp.o
$(PRE_PROCESS)
$(CXX) $(OBJS) $(EXTRA_OBJS) $(BUILD_DIR)/src/Avara.cpp.o -o $@ $(LDFLAGS)
$(POST_PROCESS) $@
# Tests
$(BUILD_DIR)/tests: $(OBJS) $(BUILD_DIR)/src/tests.cpp.o
$(CXX) $(OBJS) $(BUILD_DIR)/src/tests.cpp.o -o $@ $(LDFLAGS) -lgtest
$(POST_PROCESS) $@
# BSPViewer
$(BUILD_DIR)/BSPViewer: $(OBJS) $(BUILD_DIR)/src/BSPViewer.cpp.o
$(CC) $(OBJS) $(BUILD_DIR)/src/BSPViewer.cpp.o -o $@ $(LDFLAGS)
$(POST_PROCESS) $@
# hsnd2wav
$(BUILD_DIR)/hsnd2wav: $(OBJS) $(BUILD_DIR)/src/hsnd2wav.cpp.o
$(CXX) $(OBJS) $(BUILD_DIR)/src/hsnd2wav.cpp.o -o $@ $(LDFLAGS)
$(POST_PROCESS) $@
# frandom
$(BUILD_DIR)/frandom: $(OBJS) $(BUILD_DIR)/src/frandom.cpp.o
$(CXX) $(OBJS) $(BUILD_DIR)/src/frandom.cpp.o -o $@ $(LDFLAGS)
$(POST_PROCESS) $@
# fixed
$(BUILD_DIR)/fixed: $(OBJS) $(BUILD_DIR)/src/fixed.cpp.o
$(CXX) $(OBJS) $(BUILD_DIR)/src/fixed.cpp.o -o $@ $(LDFLAGS)
$(POST_PROCESS) $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
# obj-c++ source
$(BUILD_DIR)/%.mm.o: %.mm
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
set-version:
grep -q $(GIT_HASH) src/util/GitVersion.h || (echo "#define GIT_VERSION \"$(GIT_HASH)\"" > src/util/GitVersion.h)
clean:
$(RM) src/util/GitVersion.h
$(RMDIR) $(BUILD_DIR)
clean-levels:
$(RM) levels/*/alf/*.alf
$(RM) levels/*/default.avarascript
$(RM) levels/*/set.json
$(RM) levels/*/ogg/*.ogg
$(RM) levels/*/wav/*.wav
resources:
# python3 bin/pict2svg.py
# cp -r bsps levels rsrc shaders $(BUILD_DIR)
rsync -av levels rsrc $(BUILD_DIR)
-include $(DEPS)