-
Notifications
You must be signed in to change notification settings - Fork 115
/
Makefile
270 lines (222 loc) · 6.91 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
# ------------------------------------------------------------------------------
# Options
# ------------------------------------------------------------------------------
PLAT ?= LINUX
TYPE ?= DEBUG
ASAN ?= 0
TSAN ?= 0
LTO ?= 0
GIT_VERSION := "$(shell git describe --always)"
# ------------------------------------------------------------------------------
# Sources
# ------------------------------------------------------------------------------
PF_DIRS = $(sort $(dir $(wildcard ./src/*/), ./src/))
PF_SRCS = $(foreach dir,$(PF_DIRS),$(wildcard $(dir)*.c))
PF_SRC_OBJS = $(PF_SRCS:./src/%.c=./obj/%.o)
PF_ASM = $(foreach dir,$(PF_DIRS),$(wildcard $(dir)*.S))
PF_ASM_OBJS = $(PF_ASM:./src/%.S=./obj/%.o)
PF_OBJS = $(PF_SRC_OBJS) $(PF_ASM_OBJS)
PF_DEPS = $(PF_SRC_OBJS:%.o=%.d)
# ------------------------------------------------------------------------------
# Library Dependencies
# ------------------------------------------------------------------------------
GLEW_SRC = ./deps/GLEW
SDL2_SRC = ./deps/SDL2
PYTHON_SRC = ./deps/Python
OPENAL_SRC = ./deps/openal-soft
# ------------------------------------------------------------------------------
# Linux
# ------------------------------------------------------------------------------
LINUX_GLEW_LIB = libGLEW.so.2.2
LINUX_SDL2_LIB = libSDL2-2.0.so.0
LINUX_PYTHON_LIB = libpython2.7.so.1.0
LINUX_PYTHON_TARGET = libpython2.7.so
LINUX_OPENAL_LIB = libopenal.so.1
LINUX_SDL2_CONFIG = --host=x86_64-pc-linux-gnu
LINUX_PYTHON_CONFIG = --host=x86_64-pc-linux-gnu
LINUX_OPENAL_OPTS = "-DALSOFT_UTILS=OFF -DALSOFT_EXAMPLES=OFF"
LINUX_CC = gcc
LINUX_BIN = ./bin/pf
LINUX_LDFLAGS = \
-l:$(SDL2_LIB) \
-l:$(GLEW_LIB) \
-l:$(PYTHON_LIB) \
-l:$(OPENAL_LIB) \
-lGL \
-ldl \
-lutil \
-Xlinker -export-dynamic \
-Xlinker -rpath='$$ORIGIN/../lib'
LINUX_DEFS = -D_DEFAULT_SOURCE
# ------------------------------------------------------------------------------
# Windows
# ------------------------------------------------------------------------------
WINDOWS_GLEW_LIB = glew32.dll
WINDOWS_SDL2_LIB = SDL2.dll
WINDOWS_PYTHON_LIB = libpython2.7.dll
WINDOWS_OPENAL_LIB = OpenAL32.dll
ifneq ($(OS),Windows_NT)
WINDOWS_GLEW_OPTS = "SYSTEM=linux-mingw64"
endif
WINDOWS_SDL2_CONFIG = --host=x86_64-w64-mingw32
WINDOWS_PYTHON_CONFIG = --host=x86_64-w64-mingw32
WINDOWS_PYTHON_DEFS = "-D__USE_MINGW_ANSI_STDIO=1 -D__MINGW32__"
WINDOWS_PYTHON_TARGET = libpython2.7.dll
WINDOWS_OPENAL_OPTS = -DCMAKE_TOOLCHAIN_FILE=XCompile.txt -DHOST=x86_64-w64-mingw32 -DALSOFT_UTILS=OFF -DALSOFT_EXAMPLES=OFF
WINDOWS_CC = x86_64-w64-mingw32-gcc
WINDOWS_BIN = ./lib/pf.exe
WINDOWS_LDFLAGS = \
-lmingw32 \
-lSDL2 \
-lglew32 \
-llibpython2.7 \
-lOpenAL32 \
-lopengl32 \
-luuid
WINDOWS_DEFS = -DMS_WIN64
# ------------------------------------------------------------------------------
# Platform-Agnostic
# ------------------------------------------------------------------------------
CC = $($(PLAT)_CC)
BIN = $($(PLAT)_BIN)
PLAT_LDFLAGS = $($(PLAT)_LDFLAGS)
DEFS = $($(PLAT)_DEFS) -DGIT_VERSION=\"$(GIT_VERSION)\"
GLEW_LIB = $($(PLAT)_GLEW_LIB)
SDL2_LIB = $($(PLAT)_SDL2_LIB)
PYTHON_LIB = $($(PLAT)_PYTHON_LIB)
OPENAL_LIB = $($(PLAT)_OPENAL_LIB)
SDL2_CONFIG = $($(PLAT)_SDL2_CONFIG)
PYTHON_CONFIG = $($(PLAT)_PYTHON_CONFIG)
PYTHON_DEFS = $($(PLAT)_PYTHON_DEFS)
PYTHON_TARGET = $($(PLAT)_PYTHON_TARGET)
GLEW_OPTS = $($(PLAT)_GLEW_OPTS)
OPENAL_OPTS = $($(PLAT)_OPENAL_OPTS)
WARNING_FLAGS = \
-Wall \
-Wno-missing-braces \
-Wno-unused-function \
-Wno-unused-variable \
-Werror
EXTRA_DEBUG_FLAGS = -g
EXTRA_RELEASE_FLAGS = -DNDEBUG
EXTRA_FLAGS = $(EXTRA_$(TYPE)_FLAGS)
ifneq ($(ASAN),0)
ASAN_CFLAGS = -fsanitize=address -static-libasan
ASAN_LDFLAGS = -fsanitize=address -static-libasan
endif
ifneq ($(TSAN),0)
TSAN_CFLAGS = -fsanitize=thread -static-libtsan
TSAN_LDFLAGS = -fsanitize=thread -static-libtsan
endif
ifneq ($(LTO),0)
LTO_CFLAGS = -flto
LTO_LDFLAGS = -flto
endif
CFLAGS = \
-I$(GLEW_SRC)/include \
-I$(SDL2_SRC)/include \
-I$(PYTHON_SRC)/Include \
-I$(OPENAL_SRC)/include \
-std=c99 \
-O3 \
-fno-strict-aliasing \
-fwrapv \
$(ASAN_CFLAGS) \
$(TSAN_CFLAGS) \
$(WARNING_FLAGS) \
$(LTO_CFLAGS) \
$(EXTRA_FLAGS)
LDFLAGS = \
-L./lib/ \
-lm \
-lpthread \
$(ASAN_LDFLAGS) \
$(TSAN_LDFLAGS) \
$(LTO_LDFLAGS) \
$(PLAT_LDFLAGS)
DEPS = \
./lib/$(GLEW_LIB) \
./lib/$(SDL2_LIB) \
./lib/$(PYTHON_LIB) \
./lib/$(OPENAL_LIB)
# ------------------------------------------------------------------------------
# Targets
# ------------------------------------------------------------------------------
./lib/$(GLEW_LIB):
mkdir -p ./lib
make -C $(GLEW_SRC) extensions
make -C $(GLEW_SRC) $(GLEW_OPTS) glew.lib.shared
cp $(GLEW_SRC)/lib/$(GLEW_LIB) $@
./lib/$(SDL2_LIB):
mkdir -p ./lib
mkdir -p $(SDL2_SRC)/build
cd $(SDL2_SRC)/build \
&& ../configure $(SDL2_CONFIG) \
&& make
cp $(SDL2_SRC)/build/build/.libs/$(SDL2_LIB) $@
./lib/$(PYTHON_LIB):
mkdir -p $(PYTHON_SRC)/build
cd $(PYTHON_SRC)/build \
&& ../configure \
$(PYTHON_CONFIG) \
--build=x86_64-pc-linux-gnu \
--enable-shared \
--disable-ipv6 \
--without-threads \
--without-signal-module \
&& cp ./pyconfig.h ../Include/. \
&& make $(PYTHON_TARGET) CFLAGS=$(PYTHON_DEFS)
cp $(PYTHON_SRC)/build/$(PYTHON_TARGET) $@
./lib/$(OPENAL_LIB):
mkdir -p $(OPENAL_SRC)/build
ifeq ($(OS),Windows_NT)
ln -sf $(shell which windres) $(OPENAL_SRC)/build/x86_64-w64-mingw32-windres
endif
cd $(OPENAL_SRC)/build \
&& export PATH="$(shell pwd)/$(OPENAL_SRC)/build:$$PATH" \
&& echo $$PATH \
&& cmake .. $(OPENAL_OPTS) \
-DCMAKE_CXX_FLAGS="-I. -I.. -I../include -I../alc -I../common" \
&& make
cp $(OPENAL_SRC)/build/$(OPENAL_LIB) $@
deps: $(DEPS)
$(PF_SRC_OBJS): ./obj/%.o: ./src/%.c
@mkdir -p $(dir $@)
@printf "%-8s %s\n" "[CC]" $@
@$(CC) -MT $@ -MMD -MP -MF ./obj/$*.d $(CFLAGS) $(DEFS) -c $< -o $@
$(PF_ASM_OBJS): ./obj/%.o: ./src/%.S
@mkdir -p $(dir $@)
@printf "%-8s %s\n" "[AS]" $@
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
$(BIN): $(PF_OBJS)
@mkdir -p ./bin
@printf "%-8s %s\n" "[LD]" $@
@$(CC) $^ -o $(BIN) $(LDFLAGS)
./obj/version.o: .FORCE
.FORCE:
-include $(PF_DEPS)
.PHONY: pf clean run run_editor clean_deps launchers .FORCE
pf: $(BIN)
clean_deps:
cd deps/GLEW && git clean -f -d
cd deps/SDL2 && git clean -f -d
cd deps/Python && git clean -f -d
cd deps/openal-soft && git clean -f -d
rm -rf deps/SDL2/build
rm -rf deps/Python/build
rm -rf deps/openal-soft/build
rm -rf ./lib/*
clean:
rm -rf $(PF_OBJS) $(PF_DEPS) $(BIN)
run:
@$(BIN) ./ ./scripts/rts/main.py
run_editor:
@$(BIN) ./ ./scripts/editor/main.py
launchers:
ifeq ($(PLAT),WINDOWS)
make -C launcher BIN_PATH='.\\\\lib\\\\pf.exe' SCRIPT_PATH="./scripts/rts/main.py" BIN="../demo.exe" launcher
make -C launcher BIN_PATH='.\\\\lib\\\\pf.exe' SCRIPT_PATH="./scripts/editor/main.py" BIN="../editor.exe" launcher
else
make -C launcher BIN_PATH=$(BIN) SCRIPT_PATH="./scripts/rts/main.py" BIN="../demo" launcher
make -C launcher BIN_PATH=$(BIN) SCRIPT_PATH="./scripts/editor/main.py" BIN="../editor" launcher
endif