ninja(1)
A small build system with a focus on speed, designed to drive compilation of large projects.
Synopsis
ninja [OPTION]... [TARGET]...Description
Ninja is a build system that emphasizes speed and simplicity. It reads a build manifest (usually generated by higher-level build systems like CMake, Meson, or Bazel) and executes the build graph as efficiently as possible, with built-in support for parallel execution and dependency tracking.
Unlike Make, Ninja uses a simpler syntax optimized for machine generation rather than hand-writing. It automatically parallelizes independent build tasks and reuses build results across incremental builds for speed.
Common options
| Flag | What it does |
|---|---|
-C DIR | Change to directory DIR before reading the build.ninja file |
-f FILE | Use FILE as the build manifest (default: build.ninja) |
-j NUM | Run NUM jobs in parallel (default: number of CPU cores) |
-v | Show all command lines while building |
-d MODE | Enable debugging output; MODE can be stats, explain, or keepdepfile |
-t TOOL | Run tool TOOL; useful tools include clean, deps, query, targets, rules, and graph |
-k NUM | Keep building until NUM jobs fail (default: 1; 0 builds everything) |
-n | Dry run; print commands that would be executed without running them |
Examples
Build all targets defined in build.ninja in the current directory
ninjaBuild the target 'mytarget' using 4 parallel jobs
ninja -j 4 mytargetBuild using custom.ninja manifest in the build/ subdirectory
ninja -C build -f custom.ninjaRemove all built files without rebuilding
ninja -t cleanGenerate a dependency graph of mytarget and visualize it as an image
ninja -t graph mytarget | dot -Tpng > deps.pngShow all commands that would execute for target1 and target2 without running them
ninja -v -n target1 target2Build as much as possible, stopping only after 10 jobs fail
ninja -k 10List all available targets and filter for those with 'test' in the name
ninja -t targets | grep test