Skip to content
Novus Examples
mk608 B

Makefile Pattern Rules and Conditionals

Pattern rules with the automatic variables $@, $<, $^ and $*, ifeq/ifdef conditional directives, a vpath search path, and a define block invoked through $(call). All recipe lines are TAB-indented and echo-only.

Preview — first 35 linesmk
# Pattern rules, automatic variables, and conditional directives. Recipe lines use real TABs and
# are `echo` only. Included by the main Makefile in a real project; standalone here.

BUILD_DIR := build
VERBOSE   ?= 0

ifeq ($(VERBOSE),1)
QUIET :=
else
QUIET := @
endif

ifdef STRICT
CFLAGS += -Werror
endif

vpath %.c src

$(BUILD_DIR)/%.o: %.c
	$(QUIET)echo "compile $< -> $@ (stem $*)"

$(BUILD_DIR)/%.d: %.c
	$(QUIET)echo "depend $< -> $@"

%.checked: %
	$(QUIET)echo "check $< with prerequisites $^"

define announce
	@echo "== $(1) =="
endef

.PHONY: banner
banner:
	$(call announce,build $(BUILD_DIR))

Specifications

Pattern Rules
3
Automatic Variables
$@ $< $^ $*
Conditional Directives
2
Has Define Block
true
Has Vpath
true
Recipe Indent
TAB (U+0009)

Testing contract

Expected to pass
Scenario
Expand Makefile pattern rules and resolve the automatic variables inside their recipes
Expected result
Three pattern rules resolve and $* is reported as the stem, distinct from $@ (target) and $< (first prerequisite)

What is a .mk file?

A .mk file is a makefile fragment — the same syntax as a Makefile, meant to be pulled in with `include`. Rules pair a target with its prerequisites and a recipe whose lines must be indented with a literal tab, not spaces; variables are assigned with `=` (recursive), `:=` (immediate), or `?=` (conditional) and expanded with `$(...)`; and pattern rules, automatic variables such as `$@` and `$<`, and phony targets round out the language.

How to use this file

Use an example .mk file to test makefile parsers, build-graph extractors, and editor tooling, checking tab-versus-space recipe detection, variable expansion order, pattern-rule matching, and line continuations inside recipes.

How to use this file for testing

“Makefile Pattern Rules and Conditionals” is a deterministic Novus Examples fixture for Config parsing, Syntax highlighting, Editor testing. TOML and INI configuration files with nested sections and typed values — for testing config parsers and loaders.

Documented properties for this file: MK · 608 bytes. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.

Pipeline and infrastructure fixtures are inert configuration: steps reference fictional images and scripts, and nothing here executes. Run your linter, schema validator, migrator, or policy engine against them, and expect the deprecated-syntax and intentionally invalid variants to be rejected.

Point your config loader at the file and assert it reads the documented sections and typed values, including any deliberately-tricky nesting or comments.

Generated by generation/pipelines.py. Free for any use, no attribution required — license.