-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (34 loc) · 1.17 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
# https://en.wikipedia.org/wiki/Makefile
SRC_DIR := ./src
OBJ_DIR := ./out
EXE := renderer
SRC_FILES := $(shell find $(SRC_DIR) -name "*.c")
SRC_NAMES := $(filter-out test%.c, $(notdir $(SRC_FILES)))
OBJ_FILES := $(SRC_NAMES:%.c=$(OBJ_DIR)/%.o)
TEST_EXE := test_renderer
TEST_SRC_NAMES := $(filter-out main.c, $(notdir $(SRC_FILES)))
TEST_OBJ_FILES := $(TEST_SRC_NAMES:%.c=$(OBJ_DIR)/%.o)
LDFLAGS := -lX11 -lm
space :=
VPATH := $(subst $(space),:,$(shell find . -type d))
GCCFLAGS := -std=gnu17 -Wall -Wextra -Werror -Wshadow -Wpedantic -Wnull-dereference -Wunused -Wconversion -Wno-pointer-sign
ifeq ($(config), debug)
GCCFLAGS += -g3 -pg -fsanitize=address,leak
else
GCCFLAGS += -O2
endif
# TARGETS
.PHONY: all renderer test
all: out/$(EXE) out/$(TEST_EXE)
renderer: out/$(EXE)
test: out/$(TEST_EXE)
test: GCCFLAGS += --coverage
out/$(EXE): $(OBJ_FILES)
gcc $(GCCFLAGS) $(OBJ_FILES) -o $@ $(LDFLAGS)
out/$(TEST_EXE): $(TEST_OBJ_FILES)
gcc $(GCCFLAGS) $(TEST_OBJ_FILES) -o $@ $(LDFLAGS)
$(OBJ_DIR)/%.o: %.c
gcc $(GCCFLAGS) -c $< -o $@
.PHONY: clean
clean:
@rm -f out/* && echo "[CL] out/"