IncludeBuild
A build system for C and C++ contained in one C header.
Build definitions are C programs. Include build.h, declare the targets,
compile build.c, and run the resulting executable.
Usage
build.c
#define BUILD_IMPLEMENTATION
#include "build.h"
int main(int argc, char** argv) {
build_init(argc, argv);
executable("app", "**.c");
return build();
}
Commands
cc -o build build.c
./build
./build release
./build run
./build clean
Compile build.c once. Subsequent runs rebuild and restart the build
executable when build.c or build.h changes.
Build behavior
- Compiler depfiles track included headers.
- Stored command lines detect changes to compilers, flags, modes, includes, and link inputs.
- Independent compile and link operations run in parallel.
- Targets can be executables, static libraries, or shared libraries.
- Library dependencies propagate include directories and determine link order.
- Source arguments accept paths and globs.
*and?match within a directory;**crosses directories. - Incremental state is stored in
.build/and can be deleted at any time.
./build -v prints commands and rebuild reasons.
API
build_init(argc, argv);
Target* executable(const char* name, const char* pattern);
Target* static_library(const char* name, const char* pattern);
Target* shared_library(const char* name, const char* pattern);
void sources(Target* target, const char* pattern);
void include_dir(Target* target, const char* path);
void compile_flags(Target* target, const char* flags);
void link_flags(Target* target, const char* flags);
void use(Target* target, Target* library);
int build(void);
Constructors take a target name and an initial source path or glob. Use
sources to add more. A pattern that matches no files is an error.
Configuration
Set configuration after build_init and before build.
Command-line options override the corresponding fields.
config.cc = "clang";
config.compile_flags = "-Wall -Wextra";
config.debug_flags = "-g -O0 -DDEBUG";
config.release_flags = "-O3 -DNDEBUG";
config.output_dir = "bin";
config.jobs = 8;
Command line
./build [debug|release] [build|run [target]|clean|compdb|help] [options]
-jN parallel jobs
-v, --verbose commands and rebuild reasons
-q, --quiet errors only
--color force color
--no-color disable color
-- pass remaining arguments to the program
compdb writes compile_commands.json. If that file exists,
successful builds keep it current.
Requirements
C99 and a GCC-compatible compiler driver: GCC, Clang, or MinGW. The tool reads
CC, CXX, and AR.
curl -LO https://includebuild.com/build.h