Skip to content

iberianpig/makef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

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

$ 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 default 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.

export MAKEF_PATH=.git/Makefile

Then run direnv allow

$ direnv allow
direnv: loading .envrc
direnv: export +MAKEF_PATH

Init a new Makefile

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)

Override default tasks

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)

Use 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

bash-completion with Tab key

$ makef # press Tab key
help   task1  task2