-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
74 lines (57 loc) · 1.78 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
ifndef CC
CC = gcc
endif
WARNINGS = -Wall -Wextra -Werror -Wshadow -Wstrict-prototypes -Wpointer-arith \
-Wcast-qual
OPT_FLAGS = -O3 -flto -ffast-math
CFLAGS = $(WARNINGS) -Werror -std=c99 -pedantic
LFLAGS = -lm
TEST_DIR = test/
SRC_DIR = src/
UI_SRC_DIR = $(SRC_DIR)ui/
OBJ_DIR = obj/
TEST_OBJ_DIR = $(OBJ_DIR)test/
SRCS = $(wildcard $(SRC_DIR)*.c)
OBJS = $(addprefix $(OBJ_DIR),$(notdir $(SRCS:.c=.o)))
TEST_SRCS = $(wildcard $(TEST_DIR)*.c)
TEST_OBJS = $(addprefix $(TEST_OBJ_DIR),$(notdir $(TEST_SRCS:.c=.o)))
EXECUTABLE = termplot
TEST_EXECUTABLE = testbin
MKDIR_P = mkdir -p
DEFAULT = ncurses
all: $(DEFAULT)
ncurses: OBJS += obj/ui_ncurses.o
ncurses: LFLAGS += -lncurses
ncurses: $(OBJ_DIR) | obj/ui_ncurses.o $(EXECUTABLE)
termbox: CFLAGS += -DINCL_TERMBOX
termbox: OBJS += obj/ui_termbox.o
termbox: LFLAGS += -ltermbox
termbox: $(OBJ_DIR) | obj/ui_termbox.o $(EXECUTABLE)
.PHONY: all clean debug travis ncurses termbox
clean:
rm -f $(OBJS) $(TEST_OBJS) $(EXECUTABLE) $(TEST_EXECUTABLE)
rm -r $(OBJ_DIR)
debug: OPT_FLAGS = -ggdb -O2
debug: termbox
travis: | ncurses test
$(OBJ_DIR):
${MKDIR_P} $@
$(TEST_OBJ_DIR): $(OBJ_DIR)
${MKDIR_P} $@
$(OBJ_DIR)%.o: $(SRC_DIR)%.c
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $<
$(OBJ_DIR)%.o: $(UI_SRC_DIR)%.c
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $<
$(TEST_OBJ_DIR)%.o: $(TEST_DIR)%.c
$(CC) $(CFLAGS) $(OPT_FLAGS) -c -o $@ $<
$(EXECUTABLE): $(OBJS)
$(CC) $(OPT_FLAGS) $(OBJS) -o $@ $(LFLAGS)
# We test with ncurses.
$(TEST_EXECUTABLE): OBJS := $(filter-out obj/termplot.o obj/ui_termbox.o, \
$(OBJS))
$(TEST_EXECUTABLE): $(OBJS) $(TEST_OBJS)
$(CC) $(OPT_FLAGS) $(OBJS) $(TEST_OBJS) -o $@ $(LFLAGS)
test: $(TEST_OBJ_DIR) | $(TEST_EXECUTABLE)
./$(TEST_EXECUTABLE)
valgrind: termbox
valgrind --leak-check=full --show-leak-kinds=all -v ./$(EXECUTABLE)