Makefile Debugging, Parallelism & CI

Debug make behavior, inspect variables, run parallel builds safely, and build reliable CI targets.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Debugging commands
Trace target execution
make --trace test

# Show when each target is considered and updated.

Full debug output
make --debug=a

# Print broad internal diagnostics.

Inspect variable value with info
$(info OBJ=$(OBJ))

# Emit a variable during parsing.

Inspect origin and flavor together
$(info CFLAGS origin=$(origin CFLAGS) flavor=$(flavor CFLAGS) value=$(value CFLAGS))

# See where a value came from and how it expands.

Disable built-in rules for clearer debugging
make -rR --warn-undefined-variables

# Eliminate implicit rule noise.

## Parallel builds and CI patterns
Respect jobserver in recursive make
subdirs:
  $(MAKE) -C api
  $(MAKE) -C web

# Propagate parallelism automatically using `$(MAKE)`.

Synchronized parallel output
make -j8 --output-sync=target

# Keep log lines grouped by target when running with jobs.

CI aggregate target
.PHONY: ci
ci: lint test build

# Create a single target for consistent pipeline execution.

Local override include for CI-safe defaults
-include .env.mk

# Load machine-specific settings without hardcoding them in shared files.

Reproducible dependency install target
.PHONY: deps
deps:
  npm ci

# Use lockfile-based install inside a phony or stamp target.

## Defensive recipes
Set shell and flags
SHELL := /usr/bin/env bash
.SHELLFLAGS := -eu -o pipefail -c

# Use bash with strict flags for recipes.

Use strict flags inside one-shell recipe
.ONESHELL:
release:
  set -euo pipefail
  pnpm build
  aws s3 sync dist/ s3://my-bucket

# Fail fast in multi-line recipes.

Guard required variables
ifndef VERSION
$(error VERSION is required. Usage: make release VERSION=1.2.3)
endif

# Abort early when a required variable is missing.

Recommended next

No recommendations yet.