|
| 1 | +# Makefile basic env setting |
| 2 | +.DEFAULT_GOAL := help |
| 3 | + |
| 4 | + |
| 5 | +# Makefile ARGS |
1 | 6 | OR_EXEC ?= $(shell which openresty) |
2 | 7 | LUA_JIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.*)/nginx\s+--' | grep -Eo '/.*/')luajit |
3 | 8 | LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.") |
4 | 9 | LUA_PATH ?= ./lib/?.lua;./deps/lib/lua/5.1/?.lua;./deps/share/lua/5.1/?.lua;; |
5 | 10 | LUA_CPATH ?= ./deps/lib/lua/5.1/?.so;; |
6 | 11 |
|
7 | 12 |
|
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 |
9 | 55 | .PHONY: help |
10 | 56 | help: |
11 | | - @echo Makefile rules: |
| 57 | + @$(call func_echo_success_status, "Makefile rules:") |
| 58 | + @echo |
| 59 | + @awk $(ENV_HELP_AWK_RULE) Makefile |
12 | 60 | @echo |
13 | | - @grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /' |
14 | 61 |
|
15 | 62 |
|
16 | | -### dev: Create a development ENV |
| 63 | +### dev : Create a development ENV |
17 | 64 | .PHONY: deps |
18 | | -dev: |
| 65 | +deps: |
| 66 | + @$(call func_echo_status, "$@ -> [ Start ]") |
19 | 67 | git submodule update --init --recursive |
20 | 68 | mkdir -p deps |
| 69 | + |
21 | 70 | ifeq ($(LUAROCKS_VER),luarocks 3.) |
22 | 71 | luarocks install --lua-dir=$(LUA_JIT_DIR) rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local |
23 | 72 | else |
24 | 73 | luarocks install rockspec/jsonschema-master-0.rockspec --only-deps --tree=deps --local |
25 | 74 | endif |
26 | 75 |
|
| 76 | + @$(call func_echo_success_status, "$@ -> [ Done ]") |
27 | 77 |
|
28 | | -### test: Run the test case |
| 78 | + |
| 79 | +### test : Run the test case |
| 80 | +.PHONY: test |
29 | 81 | 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 ]") |
35 | 89 |
|
36 | 90 |
|
37 | | -### clean: Clean the test case |
| 91 | +### clean : Clean the test case |
38 | 92 | .PHONY: clean |
39 | 93 | clean: |
| 94 | + @$(call func_echo_status, "$@ -> [ Start ]") |
40 | 95 | @rm -rf deps |
41 | | - |
| 96 | + @$(call func_echo_success_status, "$@ -> [ Done ]") |
0 commit comments