Skip to content

Instantly share code, notes, and snippets.

@ARHEIO
Last active August 28, 2022 04:51
Show Gist options
  • Save ARHEIO/c8f2c585061577a2e56f5297c4a0afb1 to your computer and use it in GitHub Desktop.
Save ARHEIO/c8f2c585061577a2e56f5297c4a0afb1 to your computer and use it in GitHub Desktop.
Makefile with a builtin help

Makefile

Usage

Create a file in the root directory of your repo called Makefile (or makefile). Then insert the contents of this gist's makefile.

You can then make new "targets" in the same way that test has been implemented.

Remember that makefiles need to be intended with TABS.

Any target followed with ## will be printed out in the usage.

The default usage looks like:

% make
Makefile

Usage:
  make help                           Shows this usage.
  make test                           Run tests.
# -----------------------------------
# MAKEFILE VARS
# -----------------------------------
.DEFAULT_GOAL := help
.PHONY: test
# -----------------------------------
# MAKE TARGETS
# -----------------------------------
test: ## Run tests
@echo "unimplemented"
# -----------------------------------
# MAKE HELPER TARGETS
# -----------------------------------
help: ## Shows this usage
@echo "Makefile"
@echo ""
@echo "Usage:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36mmake %-30s\033[0m %s.\n", $$1, $$2}'
.debug:
@echo "-------------------------"
@echo "DEBUG"
@echo "-------------------------"
@echo "PATH:" $(shell pwd) | awk '{printf "\033[36m%s\033[0m\n %s\n", $$1, $$2}'
@echo "HOSTNAME:" $(shell hostname) | awk '{printf "\033[36m%s\033[0m\n %s\n", $$1, $$2}'
@echo "USER:" $(shell whoami) | awk '{printf "\033[36m%s\033[0m\n %s\n", $$1, $$2}'
@echo "DIRECTORY:" | awk '{printf "\033[36m%s\033[0m\n", $$1}'
@ls -lah | sed 's/^/ /'
@echo "-------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment