Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 68 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,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;;


### help: Show Makefile rules.
# 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) } }'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am you, I will prompt that people should use gawk instead. mawk is faster. But it doesn't support UTF8 well and one day you will find the support of mawk should be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, thanks for suggestion.

I add it for run test in container, I had change my mind. no necessary to increase maintenance costs

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:
@echo Makefile rules:
@$(call func_echo_success_status, "Makefile rules:")
@echo
@awk $(ENV_HELP_AWK_RULE) Makefile
@echo
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'


### dev: Create a development ENV
### 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 ]")

### test: Run the test case

### test : Run the test case
.PHONY: test
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
@$(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
### clean : Clean the test case
.PHONY: clean
clean:
@$(call func_echo_status, "$@ -> [ Start ]")
@rm -rf deps

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