-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
65 lines (43 loc) · 1.59 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
BUILDDIR = build
SRCDIR = src
INCDIR = include
CC = clang
CXX = clang++
ASANFLAGS = -fsanitize=address # buffer overflows, use-after-free, use-after-scope, and memory leaks
ASANFLAGS += -fsanitize=undefined # integer overflows, invalid pointer arithmetic, ...
# ASANFLAGS += -fsanitize=memory # uninitialized memory reads (only supported on Linux).
# ASANFLAGS += -fsanitize=thread # Detects data races in multi-threaded programs
ASANFLAGS += -fsanitize=leak # Specifically detects memory leaks (included in Address Sanitizer by
# default
CFLAGS = -Wall -Wextra -std=c11 -pedantic -g -O0 -I$(INCDIR) $(ASANFLAGS)
CXXFLAGS = -Wall -Wextra -std=c++20 -pedantic -g -O0 -I$(INCDIR) $(ASANFLAGS)
CXXFLAGS += `pkg-config --cflags sdl2`
LDLIBS = `pkg-config --libs sdl2` -ldl
CXX_SOURCES = $(wildcard $(SRCDIR)/*.cpp)
C_SOURCES = $(wildcard $(SRCDIR)/*.c)
CXX_OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(BUILDDIR)/%.o, $(CXX_SOURCES))
C_OBJECTS = $(patsubst $(SRCDIR)/%.c, $(BUILDDIR)/%.o, $(C_SOURCES))
TARGET = $(BUILDDIR)/prog
OBJECTS = $(CXX_OBJECTS) $(C_OBJECTS)
define compile
echo '[Deps] Generating dependency files...'; \
echo '[CtoO] $@'; \
$(1) $(2) -MMD -c $< -o $@
endef
define link
echo '[Link] $^ -> $@'; \
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)
echo [DONE]
endef
all: $(TARGET)
$(TARGET): $(OBJECTS)
@$(call link)
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
@$(call compile,$(CXX),$(CXXFLAGS))
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
@$(call compile,$(CC),$(CFLAGS))
# Include dependency files if they exist
-include $(OBJECTS:.o=.d)
clean:
$(RM) -v $(BUILDDIR)/*
.PHONY: all clean