#include "build.h"

build.h

Declare C and C++ targets in build.c.

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

./build recompiles itself when build.c or build.h changes. ./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.

use adds a library, its dependencies, and its include directories.

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. GCC, Clang, or MinGW on Linux, macOS, or Windows. Compiler defaults can be changed with CC, CXX, and AR.

curl -LO https://includebuild.com/build.h