From 8fbb5a310600ed221bfb4886d151008a66ee9968 Mon Sep 17 00:00:00 2001 From: leslie tsang Date: Sat, 25 Sep 2021 10:32:44 +0800 Subject: [PATCH 1/5] feat: more human friendly makefile output Signed-off-by: leslie tsang --- Makefile | 74 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 7ebc585..8edbc19 100644 --- a/Makefile +++ b/Makefile @@ -1,41 +1,81 @@ +# 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;;" +# LUAROCKS PATCH +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 + + +# Makefile ENV +ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') +ENV_RESTY ?= LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty + + +# 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 -### help: Show Makefile rules. + +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: - @echo Makefile rules: + @$(call func_echo_success_status, "Makefile rules:") + @echo + @if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \ + awk '{ if(match($$0, /^#{3}([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^#{3}[ ]*/, "", res[1]); _desc=$$0; gsub(/^#{3}([^:]+):[ \t]*/, "", _desc); printf(" make %-25s : %-10s\n", res[1], _desc) } }' Makefile; \ + else \ + awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-25s : %-10s\n", res[1], res[2]) } }' Makefile; \ + fi @echo - @grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /' -### dev: Create a development ENV +### dev : Create a development ENV .PHONY: deps dev: 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 -### test: Run the test case +### test : Run the test case test: - LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty t/draft4.lua - LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty t/draft6.lua - LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty t/draft7.lua - LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty t/default.lua - LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty t/200more_variables.lua + $(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 -### clean: Clean the test case +### clean : Clean the test case .PHONY: clean clean: @rm -rf deps - From eb462c6244ca368cbe973c668a658ccf6f0dd9ee Mon Sep 17 00:00:00 2001 From: leslie Date: Thu, 13 Jan 2022 18:11:58 +0800 Subject: [PATCH 2/5] feat: add support for mawk --- Makefile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8edbc19..c060752 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,17 @@ endif 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 @@ -51,11 +62,7 @@ endef help: @$(call func_echo_success_status, "Makefile rules:") @echo - @if [ '$(ENV_OS_NAME)' = 'darwin' ]; then \ - awk '{ if(match($$0, /^#{3}([^:]+):(.*)$$/)){ split($$0, res, ":"); gsub(/^#{3}[ ]*/, "", res[1]); _desc=$$0; gsub(/^#{3}([^:]+):[ \t]*/, "", _desc); printf(" make %-25s : %-10s\n", res[1], _desc) } }' Makefile; \ - else \ - awk '{ if(match($$0, /^\s*#{3}\s*([^:]+)\s*:\s*(.*)$$/, res)){ printf(" make %-25s : %-10s\n", res[1], res[2]) } }' Makefile; \ - fi + @awk $(ENV_HELP_AWK_RULE) Makefile @echo From 78e3e1c3e585c13210b014a7bceb3109ea58422f Mon Sep 17 00:00:00 2001 From: leslie Date: Thu, 13 Jan 2022 18:14:33 +0800 Subject: [PATCH 3/5] chore: add more prompts --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index c060752..f95b3e2 100644 --- a/Makefile +++ b/Makefile @@ -69,20 +69,26 @@ help: ### dev : Create a development ENV .PHONY: deps dev: + @$(call func_echo_status, "$@ -> [ Start ]") git submodule update --init --recursive mkdir -p deps + @$(call func_echo_success_status, "$@ -> [ Done ]") ### test : Run the test case 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 ]") From a35154337c96437b707c3f5f944501ac2703fa09 Mon Sep 17 00:00:00 2001 From: leslie Date: Fri, 14 Jan 2022 11:03:36 +0800 Subject: [PATCH 4/5] chore: fix CI --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f95b3e2..a03a313 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ 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;;" +LUA_PATH ?= ./lib/?.lua;./deps/lib/lua/5.1/?.lua;./deps/share/lua/5.1/?.lua;; +LUA_CPATH ?= ./deps/lib/lua/5.1/?.so;; # LUAROCKS PATCH ifeq ($(LUAROCKS_VER),luarocks 3.) @@ -19,7 +19,7 @@ endif # Makefile ENV ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') -ENV_RESTY ?= LUA_PATH=$(LUA_PATH) LUA_CPATH=$(LUA_CPATH) resty +ENV_RESTY ?= LUA_PATH="$(LUA_PATH)" LUA_CPATH="$(LUA_CPATH)" resty # AWK patch for mawk ifneq ($(shell command -v gawk),) @@ -33,6 +33,7 @@ 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 @@ -76,6 +77,7 @@ dev: ### test : Run the test case +.PHONY: test test: @$(call func_echo_status, "$@ -> [ Start ]") $(ENV_RESTY) t/draft4.lua From 5e88ec67b3e6b5f23be0f3aa7240bfd4e8ea0c35 Mon Sep 17 00:00:00 2001 From: leslie Date: Fri, 14 Jan 2022 11:46:31 +0800 Subject: [PATCH 5/5] chore: fix CI and typo --- Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a03a313..a697ce9 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,6 @@ 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;; -# LUAROCKS PATCH -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 - # Makefile ENV ENV_OS_NAME ?= $(shell uname -s | tr '[:upper:]' '[:lower:]') @@ -69,10 +62,17 @@ help: ### dev : Create a development ENV .PHONY: deps -dev: +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 ]")