-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (105 loc) · 4.06 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
EXT_SRC = $(wildcard external/*/*.c)
EXT_OBJ = $(EXT_SRC:.c=.o)
INT_SRC = $(wildcard *.c)
INT_OBJ = $(INT_SRC:.c=.o)
# just for lint
INT_H = $(wildcard *.h)
# maybe someday
TST_SRC = tests/test.c
BIN_NAM = c1k3
# todo generate
IFLAGS = -I./c1k3-assets -I./c1k3-assets/img -I./c1k3-assets/audio -I./c1k3-assets/ttf -I./c1k3-assets/blend
IFLAGS += -I./external/lodepng -I./external/libdsa -I./external/mpack -I./external/cgltf
IFLAGS += -I./tools
# todo -Wextra
CFLAGS = -Wall -Wextra -D_FORTIFY_SOURCE=2 $(IFLAGS) $(shell sdl2-config --cflags) $(shell pkg-config --cflags SDL2_mixer SDL2_ttf) -std=c11 -pedantic
LFLAGS = -lm $(shell sdl2-config --libs) $(shell pkg-config --libs SDL2_mixer SDL2_ttf)
UNAME := $(shell uname)
WIN_STR := MINGW64_NT
LIN_STR := Linux
MAC_STR := Darwin
OS := none
ifeq ($(findstring $(LIN_STR), $(UNAME)), $(LIN_STR))
CFLAGS += $(shell pkg-config --cflags glesv2)
LFLAGS += $(shell pkg-config --libs glesv2)
OS := linux
else ifeq ($(findstring $(WIN_STR), $(UNAME)), $(WIN_STR))
LFLAGS += -lGLESv2
OS := windows
else ifeq ($(findstring $(MAC_STR), $(UNAME)), $(MAC_STR))
LFLAGS += -lGLESv2
OS := mac
endif
# debug junk
SAN_FLAGS = -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment
SAN_OPT = ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1
DEBUG_CFLAGS = $(CFLAGS) -g
DBGSN_CFLAGS = $(DEBUG_CFLAGS) $(SAN_FLAGS)
RELEA_CFLAGS = $(CFLAGS) -flto -O3
all: OPT_FLAGS = $(DBGSN_CFLAGS)
all: assets $(INT_OBJ) $(EXT_OBJ)
$(CC) $(OPT_FLAGS) -o $(BIN_NAM) $(INT_OBJ) $(EXT_OBJ) $(LFLAGS)
release: OPT_FLAGS = $(RELEA_CFLAGS)
release: assets $(INT_OBJ) $(EXT_OBJ)
$(CC) $(OPT_FLAGS) -o $(BIN_NAM) $(INT_OBJ) $(EXT_OBJ) $(LFLAGS)
package: release
mkdir -p build/$(OS)
cp $(BIN_NAM) build/$(OS)/
ifeq ($(OS),linux)
tar czf $(BIN_NAM)-$(OS).tar.gz -C build/$(OS)/ .
else ifeq ($(OS),windows)
cp /ucrt64/bin/libbrotlicommon.dll build/$(OS)/
cp /ucrt64/bin/libbrotlidec.dll build/$(OS)/
cp /ucrt64/bin/libbz2-1.dll build/$(OS)/
cp /ucrt64/bin/libEGL.dll build/$(OS)/
cp /ucrt64/bin/libfreetype-6.dll build/$(OS)/
cp /ucrt64/bin/libgcc_s_seh-1.dll build/$(OS)/
cp /ucrt64/bin/libGLESv2.dll build/$(OS)/
cp /ucrt64/bin/libglib-2.0-0.dll build/$(OS)/
cp /ucrt64/bin/libgraphite2.dll build/$(OS)/
cp /ucrt64/bin/libharfbuzz-0.dll build/$(OS)/
cp /ucrt64/bin/libiconv-2.dll build/$(OS)/
cp /ucrt64/bin/libintl-8.dll build/$(OS)/
cp /ucrt64/bin/libmpg123-0.dll build/$(OS)/
cp /ucrt64/bin/libogg-0.dll build/$(OS)/
cp /ucrt64/bin/libopus-0.dll build/$(OS)/
cp /ucrt64/bin/libopusfile-0.dll build/$(OS)/
cp /ucrt64/bin/libpcre2-8-0.dll build/$(OS)/
cp /ucrt64/bin/libpng16-16.dll build/$(OS)/
cp /ucrt64/bin/libstdc++-6.dll build/$(OS)/
cp /ucrt64/bin/libwinpthread-1.dll build/$(OS)/
cp /ucrt64/bin/SDL2.dll build/$(OS)/
cp /ucrt64/bin/SDL2_mixer.dll build/$(OS)/
cp /ucrt64/bin/SDL2_ttf.dll build/$(OS)/
cp /ucrt64/bin/zlib1.dll build/$(OS)/
zip -j -r $(BIN_NAM)-$(OS).zip build/$(OS)
endif
valbuild: OPT_FLAGS = $(DEBUG_CFLAGS)
valbuild: assets $(INT_OBJ) $(EXT_OBJ)
$(CC) $(OPT_FLAGS) -o $(BIN_NAM) $(INT_OBJ) $(EXT_OBJ) $(LFLAGS)
memtest: valbuild
valgrind --track-origins=yes --leak-check=yes --gen-suppressions=all --suppressions=valgrind.supp ./$(BIN_NAM)
.NOTPARALLEL:
assets: tools/mapc
make -C c1k3-assets
tools/mapc: $(EXT_OBJ)
ifeq ($(OS),linux)
$(CC) $(DBGSN_CFLAGS) tools/mapc.c -o tools/mapc $(EXT_OBJ) $(LFLAGS)
else
$(CC) $(DEBUG_CFLAGS) tools/mapc.c -o tools/mapc $(EXT_OBJ) $(LFLAGS)
endif
%.o: %.c
$(CC) $(OPT_FLAGS) -c $< -o $@
lint:
astyle -n $(INT_SRC) $(INT_H)
cppcheck $(INT_SRC) $(INT_H)
clang-tidy $(INT_SRC) $(INT_H)
test:
## super overkill with the linking and building in all objects
clang -Wall $(INT_SRC) $(EXT_SRC) tests/*.c -o tester -lSDL2 -lSDL2_mixer -lm -lGLESv2
./tester
debug: all
$(SAN_OPT) lldb ./$(BIN_NAM)
clean:
rm $(INT_OBJ)
rm $(EXT_OBJ)