-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
90 lines (76 loc) · 2.57 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
# --------------------
# Makefile for Grawkit
# --------------------
# Run `make help` for information on available actions.
# --------------------
# Variable definitions
# --------------------
# Default name for Grawkit executable.
AWK := awk
CMD := $(CURDIR)/grawkit
# Default executables to use.
SHELL := /bin/bash
DIFF := $(shell which colordiff 2> /dev/null || which diff)
# Test files to execute.
TESTS := $(shell find tests/*)
# Color & style definitions.
BOLD := \033[1m
UNDERLINE := \033[4m
RED := \033[31m
GREEN := \033[32m
BLUE := \033[36m
RESET := \033[0m
# ----------------
# Other directives
# ----------------
# Make `help` be the default action when no arguments are passed to `make`.
.DEFAULT_GOAL := help
.PHONY: $(TESTS) test help
# Awk script for extracting Grawkit documentation as Markdown.
define EXTRACT_MARKDOWN
/^(#|# .*)$$/ {
if (f==1) {f=0; printf "```\n\n"}
print substr($$0, 3)
}
/^[^#]/ {
if (f==0) {f=1; printf "\n```awk\n"}
print
}
!NF {
print
}
END {
if (f==1) {printf "```\n"}
}
endef
export EXTRACT_MARKDOWN
# ----------------
# Rule definitions
# ----------------
## Build documentation from source file in Markdown format.
doc:
@awk "$$EXTRACT_MARKDOWN" "$(CMD)"
## Execute test suite, accepts list of specific files to run.
test: $(TESTS)
$(TESTS):
@printf ">> $(BOLD)Testing file '$@'...$(RESET) "
@result=$$($(DIFF) -ud \
<(awk '/-->/ {f=1;getline;next} f' $@) <($(AWK) -f $(CMD) \
<(awk '/<!--/ {f=1;next} /-->/ {exit} f' $@)) | tail -n +3); \
if [ -z "$$result" ]; then \
printf "$(GREEN)OK$(RESET)\n"; \
else \
printf "$(RED)FAIL$(RESET)\n"; \
echo "$$result"; \
exit 1; \
fi \
## Show usage information for this Makefile.
help:
@printf "$(BOLD)Grawkit — The Awksome Git Graph Generator.$(RESET)\n\n"
@printf "This Makefile contains tasks for processing auxiliary actions, such as\n"
@printf "generating documentation or running test cases against the test suite.\n\n"
@printf "$(UNDERLINE)Available Tasks$(RESET)\n\n"
@awk -F \
':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%6s$(RESET) %s\n", $$1, c}' \
$(MAKEFILE_LIST)
@printf "\n"