Site Tools


wiki:makefile

Table of Contents

Makefile

Make is a build automation tool that tracks dependencies and rebuilds only what changed. Define targets (build products), prerequisites (source files), and recipes (compile commands). Make avoids expensive recompilation by detecting what's out of date and rebuilding the minimum necessary.

Instead of typing compilation commands by hand or writing fragile shell scripts, write a Makefile. make reads it, identifies which files changed, and runs the appropriate recipes. On the next build, unchanged files are skipped—critical for large projects where recompiling everything takes minutes.

app: main.o util.o
	gcc -o app main.o util.o
 
main.o: main.c
	gcc -c -o main.o main.c
 
util.o: util.c
	gcc -c -o util.o util.c
 
clean:
	rm -f *.o app

Run make to build, make clean to delete build artifacts. Make automatically detects which .c files changed and recompiles only those object files and the final executable.

Concepts

wiki/makefile.md · Last modified: by Ivan Janevski