Skip to content

Instantly share code, notes, and snippets.

@Virtlink
Last active November 4, 2025 12:25
Show Gist options
  • Select an option

  • Save Virtlink/b713707ede3f74bee2d902cf18f8d110 to your computer and use it in GitHub Desktop.

Select an option

Save Virtlink/b713707ede3f74bee2d902cf18f8d110 to your computer and use it in GitHub Desktop.
Makefile template
# See: https://gist.github.com/Virtlink/b713707ede3f74bee2d902cf18f8d110
# Make settings
SHELL := /usr/bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
.ONESHELL:
.DELETE_ON_ERROR:
.SILENT:
MAKEFLAGS += --no-print-directory
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --warn-undefined-variables
# Colors and formatting
NC := $(shell printf "\033[0m")
BOLD := $(shell printf "\033[1m")
DIM := $(shell printf "\033[2m")
ITALIC := $(shell printf "\033[3m")
ULINE := $(shell printf "\033[4m")
RED := $(shell printf "\033[1;31m")
GREEN := $(shell printf "\033[1;32m")
YELLOW := $(shell printf "\033[1;33m")
BLUE := $(shell printf "\033[1;34m")
MAGENTA:= $(shell printf "\033[1;35m")
CYAN := $(shell printf "\033[1;36m")
INFO := $(shell printf "$(BLUE)ℹ$(NC)")
OK := $(shell printf "$(GREEN)✓$(NC)")
WARN := $(shell printf "$(YELLOW)⚠$(NC)")
ERROR := $(shell printf "$(RED)✖$(NC)")
# Note: targets followed by `##` are documented in the help output
# lines starting with `##@` are used to group targets in the help output
.PHONY: help
help: ## Display this help text for this Makefile
awk 'BEGIN {FS = ":.*##";\
printf "\nUsage: make ${CYAN}<target>${NC}\n"}\
/^[a-zA-Z0-9_-]+:.*?##/ { printf " ${CYAN}%-15s${NC} %s\n", $$1, $$2 }\
/^##@/ { printf "\n${BOLD}%s${NC}\n", substr($$0, 5) } '\
$(MAKEFILE_LIST)
# Variables
# ...
### =============================================================================
##@ Development
### =============================================================================
.PHONY: build
build: ## Build the application
echo "${INFO} Building..."
# ...
echo "${OK} Built"
.PHONY: test
test: build ## Test the application
echo "${INFO} Testing..."
# ...
echo "${OK} Tested"
.PHONY: clean
clean: ## Clean the build directory
echo "${INFO} Cleaning..."
# ...
echo "${OK} Cleaned"
### =============================================================================
##@ Execution
### =============================================================================
.PHONY: run
run: ## Run the application
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment