turn GNU Make into a better task runner with one file
Find a file
2022-09-24 17:49:54 -05:00
.githooks build: add versioned hook 2022-09-07 15:53:13 -05:00
.github/workflows docs: updates site_url 2022-09-18 15:05:36 -05:00
assets docs: create documentation 2022-09-18 10:02:39 -05:00
docs fix: allow shorter syntax in usage/epilog 2022-09-24 16:52:00 -05:00
src fix: don't use ending faint 2022-09-24 17:49:54 -05:00
.gitignore add src 2022-09-05 12:23:17 -05:00
generate.py feat: add reusable config object 2022-09-24 16:20:23 -05:00
LICENSE chore: add LICENSE 2022-09-05 23:56:24 -05:00
Makefile fix: allow shorter syntax in usage/epilog 2022-09-24 16:52:00 -05:00
mkdocs.yml docs: make asciinema template based 2022-09-19 00:01:20 -05:00
README.md docs: add reference to default shell requirements 2022-09-21 16:31:54 -05:00
setup.cfg add src 2022-09-05 12:23:17 -05:00
task.mk fix: allow shorter syntax in usage/epilog 2022-09-24 16:52:00 -05:00

task.mk

help

the task runner for GNU Make you've been missing

Documentation


GNU make is an excellent build tool and the task runner we love to hate, but can't escape. So let's improve the UX to make it the best task runner it can be.

Task.mk, is a standalone Makefile you can deploy alongside your own to add some QOL improvements for your users and fellow maintainers.

Current Features:

  • ANSI escape code support (including NO_COLOR)
  • formatted help output
  • custom print function
  • confirmation prompt

Depends on GNU Make, obviously and Python >=3.7, and bash (or zsh).

Wait python?!?!, I'm not pip installing some package just to parse my makefile. I agree, all you need is one file .task.mk. You can automagically include it with just two additional lines to your Makefile (and probably one to your .gitignore) and your good to go.

Setup

You can include this as an optional dependency on your project by adding the below lines to the end of your Makefile. If someone tries to invoke make help it will download .task.mk for them.

-include .task.mk
$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.19/task.mk -o .task.mk))

You might also consider making it a consistently downloaded dependency if you plan to use any of it's advanced feature set, by dropping the $(MAKECMDGOALS) check.

-include .task.mk
$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v22.9.19/task.mk -o .task.mk)

For more info see the documentation.

Simpler Alternative

But I just want a basic help output, surely I don't need python for this... you would be right. Task.mk replaces my old make help recipe boilerplate which may better serve you (so long as you have sed/awk).

## h, help | show this help
### additional text printed with the help
.PHONY: help h
help h: Makefile
	@awk -v fill=$(shell sed -n 's/^## \(.*\) | .*/\1/p' $< | wc -L)\
		'match($$0,/^## (.*) \|/,name) && match($$0,/\| (.*)$$/,help)\
		{printf "\033[1;93m%*s\033[0m | \033[30m%s\033[0m\n",\
		fill,name[1],help[1];} match($$0,/^### (.*)/,str) \
		{printf "%*s   \033[30m%s\033[0m\n",fill," ",str[1];}' $<