A Build System automates the process of converting human-readable source code into machine-executable binaries. In C, Make is the standard tool for this.
- Automation: Instead of typing
gcc src/scanner.c src/tokenizer.c ...every time, you just typemake. - Efficiency: Make only recompiles files that have changed. It checks the timestamps of the source files vs the object files.
- Dependency Management: It ensures libraries are built before the programs that link to them.
CC = gcc
CFLAGS = -Iinclude -Wall -Wextra -std=c99- Defines the compiler and flags once. If we want to switch to
clang, we change it in one place. -Iincludetells the compiler: "If you see#include "header.h", look in theincludefolder."
ar rcs $@ $^ar: Archiver tool.rcs: Replace, Create, Sort-index.- Creates a "bag" of
.ofiles. This is your library.
.PHONY: all clean- Tells Make: "
cleanis not a file name. It's an action." consistency.
- How to structure a Makefile for a C project.
- The difference between compiling (
.c->.o) and archiving (.o->.a). - How to separate build artifacts (
build/) from source code.