forked from anura-engine/anura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
238 lines (195 loc) · 6.76 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
#
# Main Makefile, intended for use on Linux/X11 and compatible platforms
# using GNU Make.
#
# It should guess the paths to the game dependencies on its own, except for
# Boost which is assumed to be installed to the default locations. If you have
# installed Boost to a non-standard location, you will need to override CXXFLAGS
# and LDFLAGS with any applicable -I and -L arguments.
#
# The main options are:
#
# CCACHE The ccache binary that should be used when USE_CCACHE is
# enabled (see below). Defaults to 'ccache'.
# CXX C++ compiler comand line.
# CXXFLAGS Additional C++ compiler options.
# OPTIMIZE If set to 'yes' (default), builds with compiler
# optimizations enabled (-O2). You may alternatively use
# CXXFLAGS to set your own optimization options.
# LDFLAGS Additional linker options.
# USE_CCACHE If set to 'yes' (default), builds using the CCACHE binary
# to run the compiler. If ccache is not installed (i.e.
# found in PATH), this option has no effect.
# USE_DB_CLIENT If set to 'yes' and couchbase is present will build.
#
OPTIMIZE?=yes
USE_LUA?=yes
USE_BOX2D?=yes
CCACHE?=ccache
USE_CCACHE?=$(shell which $(CCACHE) > /dev/null 2>&1 && echo yes)
ifneq ($(USE_CCACHE),yes)
CCACHE=
USE_CCACHE=no
endif
SANITIZE_ADDRESS?=
ifneq ($(SANITIZE_ADDRESS), yes)
SANITIZE_ADDRESS=no
endif
SANITIZE_UNDEFINED?=
ifneq ($(SANITIZE_UNDEFINED), yes)
SANITIZE_UNDEFINED=no
endif
ifeq ($(OPTIMIZE),yes)
BASE_CXXFLAGS += -O2
endif
ifneq ($(USE_LUA), yes)
USE_LUA=no
endif
BASE_CXXFLAGS += -Wall -Werror
ifneq (,$(findstring clang, `$(CXX)`))
SANITIZE_UNDEFINED=
BASE_CXXFLAGS += -Qunused-arguments -Wno-unknown-warning-option -Wno-deprecated-register
ifeq ($(USE_LUA), yes)
BASE_CXXFLAGS += -Wno-pointer-bool-conversion -Wno-parentheses-equality
endif
else ifneq (, $(findstring g++, `$(CXX)`))
GCC_GTEQ_490 := $(shell expr `$(CXX) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/'` \>= 40900)
GCC_GTEQ_510 := $(shell expr `$(CXX) -dumpversion | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/'` \>= 50100)
BASE_CXXFLAGS += -Wno-literal-suffix -Wno-sign-compare
ifeq "$(GCC_GTEQ_510)" "1"
BASE_CXXFLAGS += -Wsuggest-override
endif
ifeq "$(GCC_GTEQ_490)" "1"
BASE_CXXFLAGS += -fdiagnostics-color=auto
else
SANITIZE_UNDEFINED=
endif
endif
SDL2_CONFIG?=sdl2-config
USE_SDL2?=$(shell which $(SDL2_CONFIG) 2>&1 > /dev/null && echo yes)
ifneq ($(USE_SDL2),yes)
$(error SDL2 not found, SDL-1.2 is no longer supported)
endif
BASE_CXXFLAGS += $(shell $(SDL2_CONFIG) --cflags)
LDFLAGS+ = $(shell $(SDL2_CONFIG) --ldflags)
ifeq ($(USE_LUA), yes)
BASE_CXXFLAGS += -DUSE_LUA
#USE_LUA := yes # ?=$(shell pkg-config --exists lua5.2 && echo yes)
endif
TARBALL := /var/www/anura/anura-$(shell date +"%Y%m%d-%H%M").tar.bz2
# Initial compiler options, used before CXXFLAGS and CPPFLAGS. -rdynamic -Wno-literal-suffix
BASE_CXXFLAGS += -std=c++0x -g -fno-inline-functions \
-fthreadsafe-statics \
-Wno-narrowing -Wno-reorder -Wno-unused \
-Wno-unknown-pragmas -Wno-overloaded-virtual
LDFLAGS?=-rdynamic
MANDATORY_LIBS=pkg-config --cflags x11 sdl2 glew SDL2_image SDL2_ttf libpng zlib freetype2 cairo
# Check for sanitize-address option
ifeq ($(SANITIZE_ADDRESS), yes)
BASE_CXXFLAGS += -g3 -fsanitize=address
LDFLAGS += -fsanitize=address
endif
# Check for sanitize-undefined option
ifeq ($(SANITIZE_UNDEFINED), yes)
BASE_CXXFLAGS += -fsanitize=undefined
endif
# Compiler include options, used after CXXFLAGS and CPPFLAGS.
INC := -isystem external/header-only-libs $(shell $(MANDATORY_LIBS))
ifdef STEAM_RUNTIME_ROOT
INC += -isystem $(STEAM_RUNTIME_ROOT)/include
endif
# Linker library options.
LIBS := $(shell pkg-config --libs x11 gl ) \
$(shell pkg-config --libs $(MANDATORY_LIBS)) \
-logg -lvorbis -lvorbisfile -lrt
# libvpx check
USE_LIBVPX?=$(shell pkg-config --exists vpx && echo yes)
ifeq ($(USE_LIBVPX),yes)
BASE_CXXFLAGS += -DUSE_LIBVPX
INC += $(shell pkg-config --cflags vpx)
LIBS += $(shell pkg-config --libs vpx)
else
USE_LIBVPX=no
endif
# couchbase check
USE_DB_CLIENT?=no
ifeq ($(USE_DB_CLIENT),yes)
BASE_CXXFLAGS += -DUSE_DBCLIENT
LIBS += -lcouchbase
else
USE_DB_CLIENT=no
endif
# cairo check
USE_SVG?=$(shell pkg-config --exists cairo && echo yes)
ifeq ($(USE_SVG),yes)
BASE_CXXFLAGS += -DUSE_SVG
INC += $(shell pkg-config --cflags cairo)
LIBS += $(shell pkg-config --libs cairo)
else
USE_SVG=no
endif
MODULES := kre svg Box2D tiled hex xhtml
ifeq ($(USE_LUA),yes)
MODULES += eris
endif
SRC_DIR := $(addprefix src/,$(MODULES)) src
BUILD_DIR := $(addprefix build/,$(MODULES)) build
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
OBJ := $(patsubst src/%.cpp,./build/%.o,$(SRC))
DEPS := $(patsubst src/%.cpp,./build/%.d,$(SRC))
INCLUDES := $(addprefix -I,$(SRC_DIR))
USE_IMGUI?=yes
ifeq ($(USE_IMGUI),yes)
BASE_CXXFLAGS += -DUSE_IMGUI
INC += -Iimgui
CPPFLAGS += -Iexternal/header-only-libs -DIMGUI_INCLUDE_IMGUI_USER_INL
SRC += imgui/imgui.cpp imgui/imgui_draw.cpp
OBJ += imgui/imgui.o imgui/imgui_draw.o
SRC_DIR += ./imgui
endif
vpath %.cpp $(SRC_DIR)
CPPFLAGS += -MMD -MP
define cc-command
$1/%.o: %.cpp
@echo "Building:" $$<
@$(CCACHE) $(CXX) $(CPPFLAGS) $(BASE_CXXFLAGS) $(CXXFLAGS) $(INC) $(INCLUDES) -MF $$@.d -c -o $$@ $$<
endef
.PHONY: all checkdirs clean
all: checkdirs anura
anura: $(OBJ)
@echo "Linking : anura"
@$(CXX) \
$(BASE_CXXFLAGS) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) \
$(OBJ) -o anura \
$(LIBS) -lboost_regex -lboost_system -lboost_filesystem -lboost_locale -licui18n -licuuc -licudata -lpthread -fthreadsafe-statics
checkdirs: $(BUILD_DIR)
@printf "\
OPTIMIZE : $(OPTIMIZE)\n\
USE_CCACHE : $(USE_CCACHE)\n\
CCACHE : $(CCACHE)\n\
SANITIZE_ADDRESS : $(SANITIZE_ADDRESS)\n\
SANITIZE_UNDEFINED : $(SANITIZE_UNDEFINED)\n\
USE_DB_CLIENT : $(USE_DB_CLIENT)\n\
USE_BOX2D : $(USE_BOX2D)\n\
USE_LIBVPX : $(USE_LIBVPX)\n\
USE_LUA : $(USE_LUA)\n\
USE_SDL2 : $(USE_SDL2)\n\
CXX : $(CXX)\n\
BASE_CXXFLAGS : $(BASE_CXXFLAGS)\n\
CXXFLAGS : $(CXXFLAGS)\n\
LDFLAGS : $(LDFLAGS)\n\
INC : $(INC)\n\
LIBS : $(LIBS)\n"
$(BUILD_DIR):
@mkdir -p $@
clean:
rm -f $(foreach bdir,$(BUILD_DIR),$(bdir)/*.o) $(foreach bdir,$(BUILD_DIR),$(bdir)/*.o.d) anura
unittests: anura
./anura --tests
tarball: unittests
@strip anura
@tar --transform='s,^,anura/,g' -cjf $(TARBALL) anura data/ images/
@cp $(TARBALL) /var/www/anura/anura-latest-linux.tar.bz2
$(foreach bdir,$(BUILD_DIR),$(eval $(call cc-command,$(bdir))))
# pull in dependency info for *existing* .o files
-include $(OBJ:.o=.o.d)