What a Build Really Does
You type gcc hello.c -o hello and a program appears. Under that one command, four separate tools ran, a dozen files were read, and a binary was stitched together from your code and pieces of the C library. Every build system you will meet later (Make, Ninja, CMake, Gradle, Cargo, Bazel, npm) is a way of running steps like these in the right order, only when needed, with the right inputs. This course takes that machinery apart so the later tools stop being magic.
Who this course is for
You can write a small C program (C is enough; C++ works too), you are comfortable in a shell (Terminal & Command Line, Linux & Bash) and you know the basics of Git. You don't need to know any build tool yet. This is the first course of the Build & Release Engineering track, and every other course in the track assumes it.
One command, four stages
Ask GCC to keep its intermediate files with -save-temps and you can see the stages it normally hides:
mkdir -p hello && cd hello
cat > hello.c <<'SRC'
#include <stdio.h>
#define GREETING "Hello from a build"
int main(void) {
puts(GREETING);
return 0;
}
SRC
gcc -save-temps hello.c -o hello
ls
./hellohello
hello.c
hello.i
hello.o
hello.s
Hello from a build
| File | Made by | What it is |
|---|---|---|
hello.i |
the preprocessor | C source with every #include pasted in and every macro expanded |
hello.s |
the compiler proper (cc1) |
assembly language for the target CPU |
hello.o |
the assembler (as) |
an object file: machine code with holes where outside addresses go |
hello |
the linker (ld, via collect2) |
an executable: your object file plus start-up code and the C library, holes filled |
The section Source to Binary runs each stage on its own. -save-temps is also a real debugging tool: when a macro or a header does something you don't expect, hello.i shows exactly what the compiler saw.
What a build system adds
Compiling one file by hand is easy. A real project has hundreds of files, libraries that depend on other libraries, generated code, tests and several target platforms. A build system answers four questions for you:
- What depends on what? It keeps a build graph: which outputs are made from which inputs.
- What is out of date? After an edit, it rebuilds only what the edit can affect (an incremental build).
- What can run at the same time? Independent steps run in parallel.
- Where do the other pieces come from? Third-party code is found, versioned and locked by a package manager.
Here is the whole idea in a few lines of JavaScript: a graph of build steps, and an order that respects it. Later lessons grow this into a small Make, a scheduler and a cache.
const graph = { // output: [inputs]
"app": ["main.o", "libmath.a"],
"main.o": ["main.c", "math.h"],
"libmath.a": ["add.o", "mul.o"],
"add.o": ["add.c", "math.h"],
"mul.o": ["mul.c", "math.h"],
};
const done = new Set();
function build(target, depth = 0) {
if (done.has(target)) return;
for (const input of graph[target] ?? []) build(input, depth + 1);
done.add(target);
if (graph[target]) console.log(`${" ".repeat(depth)}make ${target} from ${graph[target].join(", ")}`);
}
build("app"); make main.o from main.c, math.h
make add.o from add.c, math.h
make mul.o from mul.c, math.h
make libmath.a from add.o, mul.o
make app from main.o, libmath.a
The steps print deepest first: every input exists before the step that needs it. That ordering is a topological sort of the graph, and it is the heart of every build tool.
How the lessons work
- Real tool sessions. Blocks marked
bash runwere executed with real GCC 13, Clang 18 and GNU binutils 2.42 on Ubuntu 24.04, offline. The site shows the recorded output; on your own Linux machine (or WSL) the same commands give the same results, apart from addresses and hashes that depend on the exact compiler build. - Runnable models. JavaScript and Python examples run in your browser. They model the ideas (a dependency graph, a timestamp check, a version resolver, a cache key) in a few dozen lines, so you can change them and see what happens.
- Links instead of repeats. Where another course already teaches something in depth (the C language, x86-64 assembly, shell basics), the lesson links to it.
What you need installed
To follow along locally: a Linux shell (native, a VM, or WSL on Windows) with gcc, clang, binutils and make. On Debian or Ubuntu, sudo apt install build-essential clang is enough. macOS uses Mach-O instead of ELF and a different linker, so some outputs in the Objects & Libraries section look different there; the Toolkit lesson lists the equivalents.
Test yourself
Which file produced by gcc -save-temps hello.c contains the source after #include and #define were processed?
hello.shello.ihello.ohello
What does an incremental build do?
- Rebuilds everything, but faster
- Rebuilds only the outputs that an edit can affect
- Builds one file per day
- Downloads prebuilt binaries
In the JavaScript model, why does add.o print before libmath.a?
- Alphabetical order
- Inputs are built before the steps that need them (topological order)
- It is smaller
- Objects are always first