alpha

Sets conventions for writing clean, portable GNU Make Makefiles: naming, structure, variables, phony targets, recipes and pitfalls to avoid.
description: "Best practices for authoring GNU Make Makefiles"
applyTo: "**/Makefile, **/makefile, **/*.mk, **/GNUmakefile"
Instructions for writing clean, maintainable, and portable GNU Make Makefiles. These instructions are based on the [GNU Make manual](https://www.gnu.org/software/make/manual/).
Makefile (recommended for visibility) or makefileGNUmakefile only for GNU Make-specific features incompatible with other make implementationsobjects, OBJECTS, objs, OBJS, obj, or OBJ for object file listsCC, CFLAGS, LDFLAGS)clean, install, test).PHONY to declare targets that don't represent files# Variables
CC = gcc
CFLAGS = -Wall -g
objects = main.o utils.o
# Default goal
all: program
# Rules
program: $(objects)
$(CC) -o program $(objects)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Phony targets
.PHONY: clean all
clean:
rm -f program $(objects)
:= (simple expansion) for immediate evaluation, = for recursive expansion?= to set default values that can be overridden+= to append to existing variables$(VARIABLE) not $VARIABLE (unless single character)$@, $<, $^, $?, $*) in recipes to make rules more generic# Simple expansion (evaluates immediately)
CC := gcc
# Recursive expansion (evaluates when used)
CFLAGS = -Wall $(EXTRA_FLAGS)
# Conditional assignment
PREFIX ?= /usr/local
# Append to variable
CFLAGS += -g
.c to .o)|) for directories and dependencies that shouldn't trigger rebuilds$^, so reference them explicitly if neededThe example below shows a pattern rule that compiles objects into an obj/ directory. The directory itself is listed as an order-only prerequisite so it is created before compiling but does not force recompilation when its timestamp changes.
# Normal prerequisites
program: main.o utils.o
$(CC) -o $@ $^
# Order-only prerequisites (directory creation)
obj/%.o: %.c | obj
$(CC) $(CFLAGS) -c $< -o $@
obj:
mkdir -p obj
.RECIPEPREFIX is changed@ prefix to suppress command echoing when appropriate- prefix to ignore errors for specific commands (use sparingly)&& or ; on the same line when they must execute together# Silent command
clean:
@echo "Cleaning up..."
@rm -f $(objects)
# Ignore errors
.PHONY: clean-all
clean-all:
-rm -rf build/
-rm -rf dist/
# Multi-line recipe with proper continuation
install: program
install -d $(PREFIX)/bin && \
install -m 755 program $(PREFIX)/bin
.PHONY to avoid conflicts with files of the same nameclean, install, test, all.PHONY: all clean test install
all: program
clean:
rm -f program $(objects)
test: program
./run-tests.sh
install: program
install -m 755 program $(PREFIX)/bin
%.o: %.c) for generic transformations.c to .o)CC, CFLAGS) rather than rewriting the rules# Use built-in implicit rules by setting variables
CC = gcc
CFLAGS = -Wall -O2
# Custom pattern rule for special cases
%.pdf: %.md
pandoc $< -o $@
\) to split long lines for readabilityIf you need to split a line without adding whitespace, you can use a special technique: insert $ (dollar-space) followed by a backslash-newline. The $ refers to a variable with a single-space name, which doesn't exist and expands to nothing, effectively joining the lines without inserting a space.
# Concatenate strings without adding whitespace
# The following creates the value "oneword"
var := one$ \
word
# This is equivalent to:
# var := oneword
# Variable definition split across lines
sources = main.c \
utils.c \
parser.c \
handler.c
# Recipe with long command
build: $(objects)
$(CC) -o program $(objects) \
$(LDFLAGS) \
-lm -lpthread
include directive to share common definitions across makefiles-include (or sinclude) to include optional makefiles without errorsinclude directives after variable definitions that may affect included filesinclude for shared variables, pattern rules, or common targets# Include common settings
include config.mk
# Include optional local configuration
-include local.mk
ifeq, ifneq, ifdef, ifndef) for platform or configuration-specific rules# Platform-specific settings
ifeq ($(OS),Windows_NT)
EXE_EXT = .exe
else
EXE_EXT =
endif
program: main.o
$(CC) -o program$(EXE_EXT) main.o
-MMD and -MP to generate .d files with dependencies-include $(deps) to avoid errors if they don't existobjects = main.o utils.o
deps = $(objects:.o=.d)
# Include dependency files
-include $(deps)
# Compile with automatic dependency generation
%.o: %.c
$(CC) $(CFLAGS) -MMD -MP -c $< -o $@
$(error text) or $(warning text) functions for build-time diagnosticsmake -n (dry run) to see commands without executingmake -p to print the database of rules and variables for debugging# Check for required tools
ifeq ($(shell which gcc),)
$(error "gcc is not installed or not in PATH")
endif
# Validate required variables
ifndef VERSION
$(error VERSION is not defined)
endif
clean target to remove generated filesclean as phony to avoid conflicts with a file named "clean"- prefix with rm commands to ignore errors if files don't existclean (removes objects) and distclean (removes all generated files) targets.PHONY: clean distclean
clean:
-rm -f $(objects)
-rm -f $(deps)
distclean: clean
-rm -f program config.mk
make -B to force rebuild all targets:= for variables that don't need recursive expansion (faster)$(shell ...) which creates subprocessesmake -j) safely by ensuring targets don't conflict# Makefile for building the example application
#
# Usage:
# make - Build the program
# make clean - Remove generated files
# make install - Install to $(PREFIX)
#
# Variables:
# CC - C compiler (default: gcc)
# PREFIX - Installation prefix (default: /usr/local)
# Compiler and flags
CC ?= gcc
CFLAGS = -Wall -Wextra -O2
# Installation directory
PREFIX ?= /usr/local
.PHONY for non-file targets.PRECIOUS to preserve intermediate files.INTERMEDIATE to mark files as intermediate (automatically deleted).SECONDARY to prevent deletion of intermediate files.DELETE_ON_ERROR to remove targets if recipe fails.SILENT to suppress echoing for all recipes (use sparingly)# Don't delete intermediate files
.SECONDARY:
# Delete targets if recipe fails
.DELETE_ON_ERROR:
# Preserve specific files
.PRECIOUS: %.o
CC = gcc
CFLAGS = -Wall -O2
objects = main.o utils.o parser.o
.PHONY: all clean install
all: program
program: $(objects)
$(CC) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
-rm -f program $(objects)
install: program
install -d $(PREFIX)/bin
install -m 755 program $(PREFIX)/bin
programs = prog1 prog2 prog3
.PHONY: all clean
all: $(programs)
prog1: prog1.o common.o
$(CC) -o $@ $^
prog2: prog2.o common.o
$(CC) -o $@ $^
prog3: prog3.o
$(CC) -o $@ $^
clean:
-rm -f $(programs) *.o
$(shell ls ...) to get file lists (use $(wildcard ...) instead).PHONY$(MAKE) -C subdir) unless absolutely necessary© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Sea turtle carrying floating film studio island
Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.
image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost
Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.
video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

Cozy Pixel Art Farm Island Village
Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.
image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape
Loading reviews…
Loading comments…