makefile
Makefile
Project automation with GNU Make.
Basic Structure
# Variables
APP_NAME := myapp
VERSION := 1.0.0
# Default target (first target)
.DEFAULT_GOAL := help
# Phony targets (not files)
.PHONY: help build run test clean
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build the application
go build -o bin/$(APP_NAME) ./cmd/$(APP_NAME)
run: ## Run the application
go run ./cmd/$(APP_NAME)
test: ## Run tests
go test -v ./...
clean: ## Clean build artifacts
rm -rf bin/ dist/
Common Patterns
Development Workflow
.PHONY: dev build test lint format
dev: ## Start development server
npm run dev
build: ## Build for production
npm run build
test: ## Run tests
npm test
lint: ## Run linter
npm run lint
format: ## Format code
npm run format
check: lint test ## Run all checks
Docker Targets
IMAGE_NAME := myapp
IMAGE_TAG := latest
.PHONY: docker-build docker-run docker-push
docker-build: ## Build Docker image
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
docker-run: ## Run Docker container
docker run -p 8080:8080 $(IMAGE_NAME):$(IMAGE_TAG)
docker-push: ## Push to registry
docker push $(IMAGE_NAME):$(IMAGE_TAG)
Database Tasks
.PHONY: db-up db-down db-migrate db-seed
db-up: ## Start database
docker compose up -d db
db-down: ## Stop database
docker compose down
db-migrate: ## Run migrations
npx prisma migrate dev
db-seed: ## Seed database
npx prisma db seed
Environment Setup
.PHONY: setup install deps
setup: install deps ## Full setup
@echo "Setup complete!"
install: ## Install tools
brew install go node
deps: ## Install dependencies
go mod download
npm install
Variables
# Simple assignment
CC := gcc
# Recursive (evaluated when used)
FILES = $(shell find . -name "*.go")
# Conditional
DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS += -g
endif
# Environment
export NODE_ENV := production
Dependencies
# Target depends on prerequisites
build: src/main.go src/utils.go
go build -o app $^
# Pattern rules
%.o: %.c
$(CC) -c $< -o $@
# Order-only (directory creation)
build: | bin
go build -o bin/app
bin:
mkdir -p bin
Conditionals
OS := $(shell uname -s)
ifeq ($(OS), Darwin)
OPEN := open
else
OPEN := xdg-open
endif
docs: ## Open documentation
$(OPEN) docs/index.html
Useful Recipes
Include Other Files
-include .env
include scripts/docker.mk
Silent Execution
install:
@echo "Installing..."
@npm install
Multi-line Commands
deploy:
@echo "Deploying..." && \
npm run build && \
aws s3 sync dist/ s3://bucket/
Run with Args
# make run ARGS="--port 3000"
run:
node server.js $(ARGS)
Project Template
.DEFAULT_GOAL := help
SHELL := /bin/bash
# ============================================
# Variables
# ============================================
APP_NAME := myapp
VERSION := $(shell git describe --tags --always)
# ============================================
# Development
# ============================================
.PHONY: dev build test lint
dev: ## Start dev server
npm run dev
build: ## Build project
npm run build
test: ## Run tests
npm test
lint: ## Run linter
npm run lint
# ============================================
# Docker
# ============================================
.PHONY: docker-build docker-up docker-down
docker-build: ## Build image
docker build -t $(APP_NAME):$(VERSION) .
docker-up: ## Start services
docker compose up -d
docker-down: ## Stop services
docker compose down
# ============================================
# Utilities
# ============================================
.PHONY: clean help
clean: ## Clean artifacts
rm -rf dist/ node_modules/
help: ## Show help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
More from 1mangesh1/dev-skills-collection
curl-http
HTTP request construction and API testing with curl and HTTPie. Use when user asks to "test API", "make HTTP request", "curl POST", "send request", "test endpoint", "debug API", "upload file", "check response time", "set auth header", "basic auth with curl", "send JSON", "test webhook", "check status code", "follow redirects", "rate limit testing", "measure API latency", "stress test endpoint", "mock API response", or any HTTP calls from the command line.
28database-indexing
Database indexing internals, index type selection, query plan analysis, and write-overhead tradeoffs across PostgreSQL, MySQL, and MongoDB. Use when user asks to "optimize queries", "create indexes", "fix slow queries", "read EXPLAIN output", "reduce query time", "index strategy", "database performance", "composite index", "covering index", "partial index", "index bloat", "unused indexes", or needs help diagnosing and resolving database performance problems.
13testing-strategies
Testing strategies, patterns, and methodologies across the full testing spectrum. Use when asked about unit tests, integration tests, e2e tests, test pyramid, mocking, test doubles, TDD, property-based testing, snapshot testing, test coverage, mutation testing, contract testing, performance testing, test data management, CI/CD testing, flaky tests, test anti-patterns, test organization, test isolation, test fixtures, test parameterization, or any testing strategy, approach, or methodology.
10secret-scanner
This skill should be used when the user asks to "scan for secrets", "find API keys", "detect credentials", "check for hardcoded passwords", "find leaked tokens", "scan for sensitive keys", "check git history for secrets", "audit repository for credentials", or mentions secret detection, credential scanning, API key exposure, token leakage, password detection, or security key auditing.
10terraform
Terraform infrastructure as code for provisioning, modules, state management, and workspaces. Use when user asks to "create infrastructure", "write Terraform", "manage state", "create module", "import resource", "plan changes", or any IaC tasks.
10kubernetes
Kubernetes and kubectl mastery for deployments, services, pods, debugging, and cluster management. Use when user asks to "deploy to k8s", "create deployment", "debug pod", "kubectl commands", "scale service", "check pod logs", "create ingress", or any Kubernetes tasks.
10