-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
96 lines (72 loc) · 2.75 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
# Makefile basic env setting
.DEFAULT_GOAL := help
# Makefile ARGS
OR_EXEC ?= $(shell which openresty)
LUA_JIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*)/nginx\s+--' | grep -Eo '/.*/')luajit
LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.")
LUA_PATH ?= ./lib/?.lua;./deps/lib/lua/5.1/?.lua;./deps/share/lua/5.1/?.lua;;
LUA_CPATH ?= ./deps/lib/lua/5.1/?.so;;
# Makefile ENV
ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ENV_RESTY ?= LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty
# AWK patch for mawk
ifneq ($(shell command -v gawk),)
ENV_HELP_AWK_RULE ?= '{ if(match($$0, /^\s*\#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-15s : %-10s\n", res[1], res[2]) } }'
else
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) } }'
endif
# ENV patch for darwin
ifeq ($(ENV_OS_NAME), darwin)
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) } }'
endif
# Makefile basic extension function
_color_red =\E[1;31m
_color_green =\E[1;32m
_color_yellow =\E[1;33m
_color_blue =\E[1;34m
_color_wipe =\E[0m
define func_echo_status
printf "[$(_color_blue) info $(_color_wipe)] %s\n" $(1)
endef
define func_echo_warn_status
printf "[$(_color_yellow) info $(_color_wipe)] %s\n" $(1)
endef
define func_echo_success_status
printf "[$(_color_green) info $(_color_wipe)] %s\n" $(1)
endef
# Makefile target
### help : Show Makefile rules
.PHONY: help
help:
@$(call func_echo_success_status, "Makefile rules:")
@echo
@awk $(ENV_HELP_AWK_RULE) Makefile
@echo
### deps : Create a development ENV
.PHONY: deps
deps:
@$(call func_echo_status, "$@ -> [ Start ]")
git submodule update --init --recursive
mkdir -p deps
ifeq ($(LUAROCKS_VER),luarocks 3.)
luarocks install --lua-dir=$(LUA_JIT_DIR) rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local
else
luarocks install rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local
endif
@$(call func_echo_success_status, "$@ -> [ Done ]")
### test : Run the test case
.PHONY: test
test:
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_RESTY) t/draft4.lua
$(ENV_RESTY) t/draft6.lua
$(ENV_RESTY) t/draft7.lua
$(ENV_RESTY) t/default.lua
$(ENV_RESTY) t/200more_variables.lua
@$(call func_echo_success_status, "$@ -> [ Done ]")
### clean : Clean the test case
.PHONY: clean
clean:
@$(call func_echo_status, "$@ -> [ Start ]")
@rm -rf deps
@$(call func_echo_success_status, "$@ -> [ Done ]")