-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile-full
85 lines (67 loc) · 2.08 KB
/
Makefile-full
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
## Makefile template
# place source and header files in src/
# place library files in ./
# objects will be built in obj/
# exec will be generated in ./
## you probably want to change these
# executable name to compile to
EXEC = executablename
# libraries in use
LDLIBS = -lm
LDLIBS += $(shell pkg-config --libs sdl2)
## you might want to change these
# compiler and linker
CC = gcc
# compiler flags
CFLAGS = -fno-omit-frame-pointer -std=c11 -Wall -Wextra -Wpedantic
CFLAGS += -Wformat -Wmissing-prototypes -Wshadow -Werror=vla
CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
CFLAGS += $(shell pkg-config --cflags sdl2)
# linker flags
LDFLAGS = -Wl,-rpath -Wl,/usr/local/lib
SANFLAGS = -fsanitize=address,leak,undefined
# bear -- make BEAR=1
# clangd doesn't like -fanalyzer because clang's flag is -Xanalyzer
ifndef BEAR
CFLAGS += -fanalyzer
endif
AFLAGS = -fsanitize=address,leak,undefined
ifdef RELEASE
CFLAGS += -O2
else
CFLAGS += -g3 -Og $(SANFLAGS)
LDFLAGS += $(SANFLAGS)
endif
## dont change these
SRCDIR = src
OBJDIR = obj
SOURCES = $(wildcard $(SRCDIR)/*.c)
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
HEADERS = $(wildcard $(SRCDIR)/*.h)
# the first target is run when we type "make"
# the dependencies on sources and executable force us to compile those things first
all: $(EXEC)
# the executable depends on the objects, so we go to compile them first
$(EXEC): $(OBJECTS)
$(CC) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $(EXEC)
# this finds all source files and compiles them into objects in the object dir
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(COMPILE.c) $(OUTPUT_OPTION) $<
# create object dir if it doesn't exist
$(OBJDIR):
mkdir -p $@
# $@ is the left side of the :
# $^ is the right side of the :
# the $< is the first item in the dependencies list
# $@: $< $^
.PHONY: clean oclean release remake check test
clean: oclean
rm -f $(EXEC)
oclean:
rm -f $(OBJDIR)/*.o
release: all oclean
remake: clean all
check: $(SOURCES) $(HEADERS)
cppcheck --enable=all --std=c11 --inline-suppr \
--suppress=missingIncludeSystem $^
codespell $^