-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
63 lines (47 loc) · 1.26 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
CC = clang
ifdef NDEBUG
# optimizations
override CFLAGS += -O3 -flto
else
# debug symbols
override CFLAGS += -g
endif
# warnings
override CFLAGS += -Wall -Wextra -Wpedantic -Wshadow -std=c11
# libraries
override CFLAGS += -pthread
VALGRIND ?= -v
BUILD_DIR ?= build
PORT ?= 8080
SRC_DIR = src
VPATH = $(SRC_DIR)
MAKEFILE=$(firstword $(MAKEFILE_LIST))
ROOT=$(realpath $(dir $(MAKEFILE)))
.PHONY: all
all: $(BUILD_DIR)/main
run: all
$(BUILD_DIR)/main $(PORT)
valgrind: all
valgrind --leak-check=full $(BUILD_DIR)/main $(PORT)
.PHONY: test-minimal
test-minimal: test.bats test.sh
./test.sh "$(MAKE)" $(VALGRIND)
.PHONY: test
test: test-minimal
# clang thinks that sscanf is insecure (??)
clang-tidy src/*.c -checks=-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
cppcheck --enable=all --error-exitcode=2 src/*.c
$(BUILD_DIR)/main: $(addprefix $(BUILD_DIR)/,main.o response.o parse.o dict.o str.o)
$(CC) -o $@ $^ $(CFLAGS)
$(BUILD_DIR):
mkdir -p $@
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $< -c -o $@
$(BUILD_DIR)/main.o: response.h parse.h
$(BUILD_DIR)/response.o: response.h parse.h dict.h str.h
$(BUILD_DIR)/parse.o: parse.h dict.h
$(BUILD_DIR)/dict.o: dict.h
$(BUILD_DIR)/str.o: str.h
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR) tmp