-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
43 lines (34 loc) · 1.23 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
COMPILER = clang
APP = site-gen-c
SOURCE_LIBS = -Ilibs/ -Llibs/ -Isrc/
WARNINGS = -Wall -Wextra
DEBUG_BUILD = -g -v -std=c2x
LEAKS_BUILD = -fsanitize=address
RELEASE_FLAGS = -std=c2x -O3
CFILES = $(wildcard src/*.c)
# Discover all .c files in the libs directory
LIB_CFILES = $(wildcard libs/*.c)
OBJ_FLAGS = -g
export ASAN_OPTIONS := allocator_may_return_null=1
# Create object files list from CFILES and LIB_CFILES
OBJ = $(patsubst src/%.c, src/%.o, $(CFILES)) $(patsubst libs/%.c, libs/%.o, $(LIB_CFILES))
# Rule for compiling .c files into .o files
src/%.o: src/%.c
$(COMPILER) $(OBJ_FLAGS) -c $< -o $@
# Rule for compiling library .c files into .o files
libs/%.o: libs/%.c
$(COMPILER) $(OBJ_FLAGS) -c $< -o $@
$(APP): $(OBJ)
$(COMPILER) $^ -o $@ $(SOURCE_LIBS) $(DEBUG_BUILD) $(WARNINGS)
#leaks: OBJ_FLAGS = -ggdb
leaks: export ASAN_OPTIONS := allocator_may_return_null=1 # for debug -fsanitize=address
leaks: $(OBJ)
$(COMPILER) $^ -o $(APP)-$@ $(SOURCE_LIBS) $(DEBUG_BUILD) $(WARNINGS) $(LEAKS_BUILD)
# NOTE: make clean first
release: OBJ_FLAGS = -O3
release: $(OBJ)
$(COMPILER) $^ -o $(APP)-$@ $(RELEASE_FLAGS) $(SOURCE_LIBS)
clean:
rm -rf $(APP).* $(APP)* **/*.o *.o
check:
cppcheck --check-level=exhaustive --enable=style -j 8 ./src