-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (57 loc) · 2 KB
/
Makefile
File metadata and controls
72 lines (57 loc) · 2 KB
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
DEBUG ?= 0
TARGET := socketecho
SRCDIR = .
SRCS = $(TARGET).c
SRCS += uriparser.c
LIBS = libpcre2-8
BUILDDIR = ./.build
INCDIRS = $(SRCDIR)
CFLAGS = -O2 -std=gnu17 -fms-extensions -Wall -Wextra -Wpedantic
CFLAGS += $(shell pkg-config --cflags $(LIBS))
CFLAGS += -DDEBUG=$(DEBUG)
# This will turn all warnings into errors
#CFLAGS += -Werror
LDFLAGS = $(shell pkg-config --libs $(LIBS)) -Wl,--as-needed
CC := gcc
.PHONY: all clean tidy lint lint-all lint-oclint
# First target is default target when `make` is invoked with no target provided
all: $(TARGET)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c | $(BUILDDIR)
$(CC) $(CFLAGS) $(addprefix -I,$(INCDIRS)) -c $< -o $@
$(BUILDDIR)/$(TARGET): $(addprefix $(BUILDDIR)/,$(SRCS:.c=.o))
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
$(TARGET): $(BUILDDIR)/$(TARGET)
ln -sf $< $@
$(BUILDDIR):
mkdir -p $@
clean:
-rm -rf $(BUILDDIR)
tidy: clean
-rm -f $(TARGET)
# specifies linters to run on lint target
lint: lint-all
# target to run all linters
lint-all: | lint-clang-tidy lint-splint lint-oclint lint-cppcheck
_oclint := oclint
_splint := splint +checks $(addprefix -I ,$(INCDIRS))
_cppcheck := cppcheck -q -j$$(($$(nproc)+1)) $(addprefix -I,$(INCDIRS)) \
--platform=unix64 \
--enable=warning,style,performance,portability,information \
--std=c11 --language=c --verbose --inconclusive
_clang-tidy := clang-tidy --quiet --checks='*'
lint-oclint: $(addprefix $(SRCDIR)/,$(SRCS))
@echo -e "\e[1m\e[92m>>> OCLint report\e[38;5;130m"
$(_oclint) 2>/dev/null $^ | head -n -2 | tail -n +1
@echo -en "\e[0m"
lint-clang-tidy: $(addprefix $(SRCDIR)/,$(SRCS))
@echo -e "\e[1m\e[92m>>> Clang-Tidy report\e[38;5;130m"
$(_clang-tidy) $^ -- $(addprefix -I,$(INCDIRS)) $(CFLAGS) 2>/dev/null | cat
@echo -en "\e[0m"
lint-splint: $(addprefix $(SRCDIR)/,$(SRCS))
@echo -e "\e[1m\e[92m>>> SPLint report\e[38;5;130m"
$(_splint) 2>&1 $^ | tail -n +2
@echo -en "\e[0m"
lint-cppcheck: $(addprefix $(SRCDIR)/,$(SRCS))
@echo -e "\e[1m\e[92m>>> CPPCheck report\e[38;5;130m"
$(_cppcheck) $^ && echo
@echo -en "\e[0m"