Override Makefile for developer local environment
- Extend Makefile with overriding tasks
- Behave like make -f
make -f /path/to/git/ignored/Makefile - Override the project's Makefile tasks in local envirioment
- Unify commands for developer's local between different projects
- No more wrong selections from Ctrl-R's command line history
- Support
bash-completion
register makef to ~/.bashrc
git clone https://github.com/iberianpig/makef
echo -e "# makef\nsource $(find `pwd` -name makef.sh)" >> ~/.bashrc
source ~/.bashrcmakef use direnv to set $MAKEF_PATH to envirionment variables
see: https://github.com/direnv/direnv
For example, You have a Makefile like following in your project.
./Makefile
task1: ## Sample task
echo "this is Makefile"
task2: task1 ## task overridden in next step
echo "from ./Makefile"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/MakefileBy setting the $MAKEF_PATH environment variable, you can specify a custom path for your override Makefile for each project. If you use direnv, simply add the following to your project's .envrc:
export MAKEF_PATH=.git/MakefileThen allow the changes with:
direnv allow(You can also set $MAKEF_PATH manually if you prefer not to use direnv.)
Generate a new override Makefile at the path specified by $MAKEF_PATH by running:
makefinitAn example override Makefile (e.g., .git/Makefile) generated by this command might look like:
.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)After initialization, you can modify your override Makefile with:
makefeditFor example, you can redefine tasks as follows:
.PHONY: all
all: help
task2: task1 ## Overriding 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)Instead of running make directly, use makef. This command combines your original Makefile and the override Makefile, so tasks defined in both are executed together.
For example:
makef
Output might look like:
/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 overriding 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/MakefileTo execute a specific task, run:
makef task1or
makef task2When using makef, simply press the Tab key to auto-complete available task names from your override Makefile.
makef # then press Tab to see: help task1 task2By default, makef uses the Makefile in the current directory. If you want to use a different Makefile as your source, you can specify it by setting the $MAKEFILE environment variable in .envrc:
export MAKEF_PATH=.git/Makefile
export MAKEFILE=path/to/Makefile # Specify the desired MakefileThen reload your environment (for example, with direnv allow).
makef leverages the optional use of direnv to automatically manage the $MAKEF_PATH variable, simplifying the process of specifying a custom override Makefile for each project. Enjoy a smoother local development experience with makef!