-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (59 loc) · 1.74 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
CC = gcc
DBG_BIN = gdb
CFLAGS = # -D_GNU_SOURCE
CFLAGS += -std=gnu11
CFLAGS += -Wall
CFLAGS += -Wextra
CFLAGS += -pedantic
# CFLAGS += -Werror
CFLAGS += -Wmissing-declarations
ASANFLAGS=-fsanitize=address -fno-common -fno-omit-frame-pointer
CFLAGS += $(shell pkg-config --cflags sdl2 SDL2_image SDL2_ttf)
LDFLAGS = $(shell pkg-config --libs sdl2 SDL2_image SDL2_ttf) -lm
LIBS = -I./libs/
ifeq ($(shell uname -s),Darwin)
DBG_BIN = lldb
endif
SRC = ./src/*.c
BIN_DIR = ./bin
BIN = $(BIN_DIR)/3drenderer
TEST_DIR = ./tests
TEST_SRC = $(filter-out ./src/main.c, $(wildcard ./src/*.c)) $(TEST_DIR)/*.c
build: bin-dir
$(CC) $(CFLAGS) $(LIBS) $(SRC) -o $(BIN) $(LDFLAGS)
bin-dir:
mkdir -p $(BIN_DIR)
ifeq ($(shell uname -s),Darwin)
else
debug: debug-build
$(DBG_BIN) --args $(BIN) $(ARGS)
endif
debug-build: bin-dir
$(CC) $(CFLAGS) -g $(LIBS) $(SRC) -o $(BIN) $(LDFLAGS)
run-windowed: build
@$(BIN) true
run: build
@$(BIN) $(ARGS)
test:
$(CC) $(CFLAGS) $(LIBS) $(TEST_SRC) -o $(TEST_DIR)/tests $(LDFLAGS) && $(TEST_DIR)/tests
test-debug:
$(CC) $(CFLAGS) -g $(LIBS) $(TEST_SRC) -o $(TEST_DIR)/tests $(LDFLAGS) && lldb $(TEST_DIR)/tests $(ARGS)
memcheck:
@$(CC) $(ASANFLAGS) $(CFLAGS) -g $(LIBS) $(SRC) -o $(BIN_DIR)/memcheck.out $(LDFLAGS)
@$(BIN_DIR)/memcheck.out
@echo "Memory check passed"
valgrid:
$(CC) $(CFLAGS) -g $(LIBS) $(SRC) -o $(BIN_DIR)/memcheck.out $(LDFLAGS)
valgrind --leak-check=yes $(BIN_DIR)/memcheck.out
leakscheck:
leaks -atExit -- $(BIN)
clean:
rm -rf $(BIN_DIR)/* $(TEST_DIR)/tests*
gen-compilation-db:
bear -- make build
gen-compilation-db-make:
make --always-make --dry-run \
| grep -wE 'gcc|g\+\+' \
| grep -w '\-c' \
| jq -nR '[inputs|{directory:".", command:., file: match(" [^ ]+$").string[1:]}]' \
> compile_commands.json