https://github.com/iberianpig/makef
Override Makefile
https://github.com/iberianpig/makef
bash cli make makefile override shell task-runner
Last synced: 3 months ago
JSON representation
Override Makefile
- Host: GitHub
- URL: https://github.com/iberianpig/makef
- Owner: iberianpig
- License: mit
- Created: 2019-06-15T06:15:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-15T23:54:34.000Z (4 months ago)
- Last Synced: 2025-03-25T15:21:13.280Z (4 months ago)
- Topics: bash, cli, make, makefile, override, shell, task-runner
- Language: Shell
- Homepage:
- Size: 11.7 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# makef
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`## Installation
### 1. Install makef
register `makef` to `~/.bashrc`
```sh
git clone https://github.com/iberianpig/makef
echo -e "# makef\nsource $(find `pwd` -name makef.sh)" >> ~/.bashrc
source ~/.bashrc
```### 2. Install direnv
`makef` use `direnv` to set `$MAKEF_PATH` to envirionment variables
see: https://github.com/direnv/direnv
## Usage
For example, You have a Makefile like following in your project.
`./Makefile`
```Makefile
task1: ## Sample task
echo "this is Makefile"task2: task1 ## task overridden in next step
echo "from ./Makefile"
```### Export MAKEF_PATH in `.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.
```sh
export MAKEF_PATH=.git/Makefile
```By 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:
```sh
export MAKEF_PATH=.git/Makefile
```Then allow the changes with:
```sh
direnv allow
```(You can also set $MAKEF_PATH manually if you prefer not to use direnv.)
### 1. Initializing the Override Makefile
Generate a new override Makefile at the path specified by $MAKEF_PATH by running:
```sh
makefinit
```An example override Makefile (e.g., .git/Makefile) generated by this command might look like:
```Makefile
.PHONY: allall: 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)
```### 2. Editing and Overriding Tasks
After initialization, you can modify your override Makefile with:
```sh
makefedit
```For example, you can redefine tasks as follows:
```Makefile
.PHONY: allall: 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)
```### 3. Running Tasks with makef
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:
```sh
/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/Makefile
```To execute a specific task, run:
```sh
makef task1
```or
```sh
makef task2
```### 4. Bash Completion
When using makef, simply press the Tab key to auto-complete available task names from your override Makefile.
```sh
makef # then press Tab to see: help task1 task2
```### 5. Changing the Source Makefile
By 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:
```sh
export MAKEF_PATH=.git/Makefile
export MAKEFILE=path/to/Makefile # Specify the desired Makefile
```Then 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!