-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (95 loc) · 3 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
.DEFAULT_GOAL := all
GOPKG := github.com/jon-codes/getopt
BINDIR := bin
TMPDIR := tmp
OBJDIR := obj
CC := gcc
CFLAGS_BASE := -std=c23 -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wshadow -Wwrite-strings -Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs -Wjump-misses-init -Wlogical-op
CFLAGS := $(CFLAGS_BASE) -O2 $(TESTGEN_INCL)
CFLAGS_DEBUG := $(CFLAGS_BASE) -g -O0 $(TESTGEN_INCL)
TESTGEN_SRCDIR := testgen
TESTGEN_DATADIR := testdata
TESTGEN_BIN := $(BINDIR)/testgen
TESTGEN_DEBUG_BIN := $(BINDIR)/testgen-debug
TESTGEN_SRCS := $(wildcard $(TESTGEN_SRCDIR)/*.c)
TESTGEN_OBJS := $(patsubst $(TESTGEN_SRCDIR)/%.c,$(OBJDIR)/%.o,$(TESTGEN_SRCS))
TESTGEN_DEBUG_OBJS := $(patsubst $(TESTGEN_SRCDIR)/%.c,$(OBJDIR)/%_debug.o,$(TESTGEN_SRCS))
TESTGEN_INCL := -I$(TESTGEN_SRCDIR) -I/usr/include
TESTGEN_LIBS := -ljansson
TESTGEN_INPUT := $(TESTGEN_DATADIR)/cases.json
TESTGEN_OUTPUT := $(TESTGEN_DATADIR)/fixtures.json
## all: run development tasks (default target)
.PHONY: all
all: deps fmt vet test
.PHONY: check
check: deps-check fmt-check vet cover-check
## deps: clean deps
.PHONY: deps
deps:
go mod tidy -v
.PHONY: deps-check
deps-check:
go mod tidy -diff
go mod verify
## fmt: go fmt
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: fmt-check
fmt-check:
test -z "$(shell gofmt -l .)"
## vet: go vet
.PHONY: vet
vet:
go vet ./...
## test: go test
.PHONY: test
test:
go test ./...
.PHONY: test-check
test-check:
go test -race -count=1 -v ./...
## cover: go test coverage
.PHONY: cover
cover: $(TMPDIR)
go test -v -coverprofile $(TMPDIR)/cover.out $(GOPKG)
go tool cover -html=$(TMPDIR)/cover.out
.PHONY: cover-check
cover-check: $(TMPDIR)
go test -race -count=1 -v -coverprofile $(TMPDIR)/cover.out $(GOPKG)
## clean: clean output
.PHONY: clean
clean:
rm -rf $(BINDIR) $(TMPDIR) $(OBJDIR)
$(TMPDIR) $(BINDIR) $(OBJDIR):
mkdir -p $@
## testgen: generate test data
testgen: $(TESTGEN_OUTPUT)
$(TESTGEN_OUTPUT): $(TESTGEN_BIN) $(TESTGEN_INPUT)
$< -o $@ $(TESTGEN_INPUT)
## testgen-build: build testgen binary
.PHONY: testgen-build
testgen-build: $(TESTGEN_BIN)
.PHONY: testgen-debug
testgen-debug: $(TESTGEN_DEBUG_BIN)
$(TESTGEN_BIN): $(TESTGEN_OBJS) | $(BINDIR)
$(CC) $(CFLAGS) -o $@ $(TESTGEN_OBJS) $(TESTGEN_LIBS)
$(TESTGEN_DEBUG_BIN): $(TESTGEN_DEBUG_OBJS) | $(BINDIR)
$(CC) $(CFLAGS_DEBUG) -o $@ $(TESTGEN_DEBUG_OBJS) $(TESTGEN_LIBS)
$(OBJDIR)/%.o: $(TESTGEN_SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%_debug.o: $(TESTGEN_SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS_DEBUG) -c $< -o $@
## testgen-check: run testgen with valgrind
.PHONY: testgen-check
testgen-check: $(TESTGEN_DEBUG_BIN)
valgrind --leak-check=full --track-origins=yes $< -o $(TESTGEN_OUTPUT) $(TESTGEN_INPUT)
## testgen-debug: run testgen with gdb
.PHONY: testgen-debug
testgen-debug: $(TESTGEN_DEBUG_BIN)
gdb --args $< -o $(TESTGEN_OUTPUT) $(TESTGEN_INPUT)
## help: display this help
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'