A self-hosting build system for C/C++ projects, configured entirely in a single build.c file.
The build executable will automatically rebuild itself when changes are detected in build.c.
- Simple, single-file build configuration (
build.c) - Supports debug and release builds
- Automatic dependency tracking via
-MD - Cleans output directory
- Passes arguments to the built executable
- Self-rebuilding when
build.cchanges - Optional multithreaded compilation
./build [dbg|rel|clean|no-threading|build-only|j [NUM]|version|help] -- [ARGS...]dbg: Build the target executable with-DDEBUGand debug inforel: Build the target executable with-DRELEASEand optimizationsclean: Remove the output directoryno-threading: Disable multithreaded compilationbuild-only: Only build the build executable, not the targetj [NUM]: Sets the number of threads to use for building source files\n"version: Print the build system versionhelp: Show help text--: Run the built executable, passing any arguments after--to it
./build dbg -- --input=foo.txt
./build rel
./build rel j64
./build clean
./build no-threadingEdit the top of build.c to set:
cc.c: C Compiler for target (default:"gcc")cc.cpp: C++ Compiler for target (default:"g++")exe: Name of the target executabledir: Output directorysrc[]: List of source files to compileflags[]: Compiler flagsincs[]: Directories to includelib_incs[]: Directories to include for linking to librarieslibs[]: Libraries to linkbuild.cc: Compiler forbuild.cbuild.file: Path tobuild.cbuild.exe: Name of the build executablebuild.ver: Version string
- On each invocation,
buildchecks ifbuild.cor the build mode has changed. - If so, it rebuilds itself, then re-invokes with the same arguments.
- Otherwise, it checks dependencies and only recompiles changed files.
- Output and intermediate files are placed in the directory specified by
dir. - Uses a lock file to track build state and avoid concurrent builds.
MIT License. See top of build.c or the LICENCE.md file for details.