Skip to content

Commit d6a0155

Browse files
authored
feat: more human friendly makefile output prompts (#65)
1 parent 5ced34d commit d6a0155

File tree

1 file changed

+68
-13
lines changed

1 file changed

+68
-13
lines changed

Makefile

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,96 @@
1+
# Makefile basic env setting
2+
.DEFAULT_GOAL := help
3+
4+
5+
# Makefile ARGS
16
OR_EXEC ?= $(shell which openresty)
27
LUA_JIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*)/nginx\s+--' | grep -Eo '/.*/')luajit
38
LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.")
49
LUA_PATH ?= ./lib/?.lua;./deps/lib/lua/5.1/?.lua;./deps/share/lua/5.1/?.lua;;
510
LUA_CPATH ?= ./deps/lib/lua/5.1/?.so;;
611

712

8-
### help: Show Makefile rules.
13+
# Makefile ENV
14+
ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
15+
ENV_RESTY ?= LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty
16+
17+
# AWK patch for mawk
18+
ifneq ($(shell command -v gawk),)
19+
ENV_HELP_AWK_RULE ?= '{ if(match($$0, /^\s*\#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-15s : %-10s\n", res[1], res[2]) } }'
20+
else
21+
ENV_HELP_AWK_RULE := '{ if(match($$0, /^\#\#\#([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^\#\#\#[ ]*/, "", res[1]); _desc=$$0; gsub(/^\#\#\#([^:]+):[ \t]*/, "", _desc); printf(" make %-15s : %-10s\n", res[1], _desc) } }'
22+
endif
23+
24+
# ENV patch for darwin
25+
ifeq ($(ENV_OS_NAME), darwin)
26+
ENV_HELP_AWK_RULE := '{ if(match($$0, /^\#{3}([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^\#{3}[ ]*/, "", res[1]); _desc=$$0; gsub(/^\#{3}([^:]+):[ \t]*/, "", _desc); printf(" make %-15s : %-10s\n", res[1], _desc) } }'
27+
endif
28+
29+
30+
# Makefile basic extension function
31+
_color_red =\E[1;31m
32+
_color_green =\E[1;32m
33+
_color_yellow =\E[1;33m
34+
_color_blue =\E[1;34m
35+
_color_wipe =\E[0m
36+
37+
38+
define func_echo_status
39+
printf "[$(_color_blue) info $(_color_wipe)] %s\n" $(1)
40+
endef
41+
42+
43+
define func_echo_warn_status
44+
printf "[$(_color_yellow) info $(_color_wipe)] %s\n" $(1)
45+
endef
46+
47+
48+
define func_echo_success_status
49+
printf "[$(_color_green) info $(_color_wipe)] %s\n" $(1)
50+
endef
51+
52+
53+
# Makefile target
54+
### help : Show Makefile rules
955
.PHONY: help
1056
help:
11-
@echo Makefile rules:
57+
@$(call func_echo_success_status, "Makefile rules:")
58+
@echo
59+
@awk $(ENV_HELP_AWK_RULE) Makefile
1260
@echo
13-
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'
1461

1562

16-
### dev: Create a development ENV
63+
### dev : Create a development ENV
1764
.PHONY: deps
18-
dev:
65+
deps:
66+
@$(call func_echo_status, "$@ -> [ Start ]")
1967
git submodule update --init --recursive
2068
mkdir -p deps
69+
2170
ifeq ($(LUAROCKS_VER),luarocks 3.)
2271
luarocks install --lua-dir=$(LUA_JIT_DIR) rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local
2372
else
2473
luarocks install rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local
2574
endif
2675

76+
@$(call func_echo_success_status, "$@ -> [ Done ]")
2777

28-
### test: Run the test case
78+
79+
### test : Run the test case
80+
.PHONY: test
2981
test:
30-
LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty t/draft4.lua
31-
LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty t/draft6.lua
32-
LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty t/draft7.lua
33-
LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty t/default.lua
34-
LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty t/200more_variables.lua
82+
@$(call func_echo_status, "$@ -> [ Start ]")
83+
$(ENV_RESTY) t/draft4.lua
84+
$(ENV_RESTY) t/draft6.lua
85+
$(ENV_RESTY) t/draft7.lua
86+
$(ENV_RESTY) t/default.lua
87+
$(ENV_RESTY) t/200more_variables.lua
88+
@$(call func_echo_success_status, "$@ -> [ Done ]")
3589

3690

37-
### clean: Clean the test case
91+
### clean : Clean the test case
3892
.PHONY: clean
3993
clean:
94+
@$(call func_echo_status, "$@ -> [ Start ]")
4095
@rm -rf deps
41-
96+
@$(call func_echo_success_status, "$@ -> [ Done ]")

0 commit comments

Comments
 (0)