Override Makefile
MIT License
Override Makefile
for developer local environment
make -f /path/to/git/ignored/Makefile
bash-completion
register makef
to ~/.bashrc
$ git clone https://github.com/iberianpig/makef
$ echo -e "# makef\nsource $(find `pwd` -name makef.sh)" >> ~/.bashrc
$ source ~/.bashrc
makef
use direnv
to set $MAKEF_PATH
to envirionment variables
see: https://github.com/direnv/direnv
For example, You have a default Makefile.
./Makefile
task1: ## Sample task
echo "this is Makefile"
task2: task1 ## task overridden in next step
echo "from ./Makefile"
.envrc
Add export MAKEF_PATH=/path/to/hidden/Makefile
to .envrc
on your project
Edit .envrc
, use .git/Makefile
as MAKEF_PATH in this example.
export MAKEF_PATH=.git/Makefile
Then run direnv allow
$ direnv allow
direnv: loading .envrc
direnv: export +MAKEF_PATH
Generate a new Makefile to $MAKEF_PATH with makefinit
.
$ makefinit
following .git/Makefile
is a automaticaly generated by makefinit
.PHONY: all
all: help
help: ## show this messages
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
NO_PHONY = /^:/
PHONY := $(shell cat $(MAKEFILE_LIST) | awk -F':' '/^[a-z0-9_.-]+:/ && !$(NO_PHONY) {print $$1}')
.PHONY: $(PHONY)
show_phony:
@echo $(PHONY)
Then, edit Makefile($MAKEF_PATH) with makefedit
.
$ makefedit
Overwride your tasks.
.PHONY: all
all: help
task2: task1 ## orverriding task
echo "from .git/Makefile"
help: ## show this messages
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
NO_PHONY = /^:/
PHONY := $(shell cat $(MAKEFILE_LIST) | awk -F':' '/^[a-z0-9_.-]+:/ && !$(NO_PHONY) {print $$1}')
.PHONY: $(PHONY)
show_phony:
@echo $(PHONY)
makef
instead of make
$ makef
/tmp/tmp.u0vZq8mzkG:8: warning: overriding recipe for target 'task2'
/tmp/tmp.u0vZq8mzkG:5: warning: ignoring old recipe for target 'task2'
task1 sample task
task2 orverriding task
help show help
$ makef task1
/tmp/tmp.cQARE0rtXT:8: warning: overriding recipe for target 'task2'
/tmp/tmp.cQARE0rtXT:5: warning: ignoring old recipe for target 'task2'
echo "this is Makefile"
this is Makefile
$ makef task2
/tmp/tmp.CI2hKcYZIH:8: warning: overriding recipe for target 'task2'
/tmp/tmp.CI2hKcYZIH:5: warning: ignoring old recipe for target 'task2'
echo "this is Makefile"
this is Makefile
echo "from .git/Makefile"
from .git/Makefile
Tab
key$ makef # press Tab key
help task1 task2