-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
72 lines (55 loc) · 1.81 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
66
67
68
69
70
71
72
.PHONY: build run test fmt fmt-check lint %-lint clean help
.DEFAULT_GOAL := help
.EXTRA_PREREQS := $(MAKEFILE_LIST)
SLIB := out/libwebb.a
DLIB := out/libwebb.so
OBJS := $(sort $(patsubst src/%.c,out/obj/%.o,$(wildcard src/*.c)))
BINS := $(sort $(patsubst bin/%.c,out/bin/%,$(wildcard bin/*.c)))
TESTS := $(sort $(patsubst tests/%.c,out/tests/%,$(wildcard tests/*.c)))
FILES := $(sort $(wildcard src/* tests/* bin/* include/webb/*))
CC := gcc
CFLAGS := -std=gnu99 -pedantic -O3 -Wall -Wextra -Werror -Wcast-qual -Wcast-align -Wshadow -pthread -fPIC
out:
mkdir -p out/obj out/tests out/bin
out/obj/%.o: src/%.c src/internal.h include/webb/webb.h | out
$(CC) $(CFLAGS) -Iinclude -c $< -o $@
out/bin/%: bin/%.c $(SLIB)
$(CC) $(CFLAGS) -Iinclude $^ -o $@
out/tests/%: tests/%.c $(DLIB)
$(CC) $(CFLAGS) -Iinclude -Isrc $^ -o $@
$(SLIB): $(OBJS)
$(AR) rc $@ $^
$(DLIB): $(OBJS)
$(CC) -shared $^ -o $@
%-lint: %
clang-tidy $* -- -std=gnu99 -Isrc -Iinclude 2>/dev/null
#@ Compile everything
build: $(SLIB) $(DLIB) $(BINS) $(TESTS)
#@ Run the web server
run: out/bin/webb
./$< .
#@ Run all tests
test: $(TESTS)
$(subst $() $(), && ,$(^:%=./%))
#@ Format all source files, in place
fmt:
clang-format -style=file $(FILES) -i
#@ Check if sources files are formatted
fmt-check:
clang-format -style=file $(FILES) --dry-run -Werror
#@ Lint all source files, using clang-tidy
lint: $(FILES:=-lint)
#@ Remove all make artifacts
clean:
rm -rf out
#@ Display help information
help:
@echo 'usage: make [TARGET..]'
@echo 'Makefile used to build and lint libwebb'
@echo
@echo 'TARGET:'
@awk '{ \
if (desc ~ /^#@ /) \
printf " %s%s\n", $$1, substr(desc, 4, 100); \
desc = $$0 \
}' $(MAKEFILE_LIST) | column -t -s ':'