-
Notifications
You must be signed in to change notification settings - Fork 28
feat: more human friendly makefile output prompts #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fbb5a3
feat: more human friendly makefile output
leslie-tsang 4116dab
Merge branch 'master' into feature/makefile-optimize
leslie-tsang eb462c6
feat: add support for mawk
leslie-tsang 78e3e1c
chore: add more prompts
leslie-tsang a351543
chore: fix CI
leslie-tsang 5e88ec6
chore: fix CI and typo
leslie-tsang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) } }' | ||
| 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 ]") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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