Build Engine & Language Reference
RBS Syntax
How to write build.rbs scripts for rg-cc, from basic values and variables up to multi-platform builds and file generation.
The Reservoir Build System (RBS) is rg-cc's built-in build system. Instead of maintaining separate Makefiles, Pure C .PRJ files, or shell scripts for each host OS, you describe your targets and flags once in build.rbs. rg-cc then runs the full compile, assemble, and link pipeline inside one process with shared header caching.
Your First build.rbs
An .rbs file describes what to build and which compiler settings to use. Running rg-cc build reads build.rbs in the current directory:
executable hello {
sources = ["src/main.c", "src/util.c"]
include = ["include"]
opt = O2
}
Comments start with # and run to the end of the line.
Values: Scalars, Lists, and Maps
Every setting in RBS takes one of three kinds of value: a single scalar, an ordered list (vector), or a key-value map.
-
Scalars represent a single value:
- Strings:
"src/main.c","__ATARI__=1" - Integers:
1024,262144,0x7 - Booleans:
true,false - Unquoted identifiers/keywords:
O2,68000,fastcall,tos
- Strings:
-
Lists (vectors) hold zero or more values inside square brackets, separated by commas (trailing commas are allowed):
sources = [ "src/main.c", "src/util.c", ] -
Maps hold named key-value pairs inside curly braces, used for template substitutions and staging specs:
vars = { MAJOR = "0", MINOR = "44", }
Assignment, Appending, and Exclusion
Properties use = to set or replace a value, += to add to a list, and -= to remove items from an inherited list:
=(Assign / Replace): Sets a scalar property (opt = O2) or replaces a list completely (define = ["NDEBUG=1"]).+=(Append): Appends items to an existing list inherited from an outer block. Using=inside an inner block would wipe out the outer list;+=keeps it.-=(Exclude): Removes matching items from an inherited list (for example,define -= ["DEBUG"]orinclude -= ["legacy"]).
define = ["BASE=1", "DEBUG=1"]
executable tool {
define += ["TOOL=1"] # Effective defines: ["BASE=1", "DEBUG=1", "TOOL=1"]
define -= ["DEBUG"] # Effective defines: ["BASE=1", "TOOL=1"]
}
executable clean_tool {
define = ["ONLY_THIS=1"] # Replaces outer list: ["ONLY_THIS=1"]
}
Variables
Properties (like opt, cpu, and sources) configure the compiler and linker directly. User variables are declared with var to hold reusable values and drive conditionals:
var abi = fastcall
var buf_size = 1024
define = ["BUFFER_SIZE=${buf_size}"]
output_dir = "BIN/${PLATFORM}/${CONFIG}"
Use ${name} inside any string to interpolate a user variable or a built-in variable (such as ${PLATFORM}, ${CONFIG}, ${ROOT}, ${DIR}, or ${GEN_DIR}). You can override any var from the command line with -Dname=value or --set name=value:
rg-cc build.rbs -Dabi=cdecl -Dbuf_size=2048
Blocks, Scopes, and Inheritance
RBS scripts are organised into nested blocks. Settings written in an outer block are inherited by every block inside it, following this hierarchy from outermost to innermost:
project → config / platform / when → target (executable / library / object) → group → "file.c" { ... }
Inner blocks override scalars with = and extend inherited lists with +=:
project "myapp" {
cpu = 68000
opt = O2
define = ["__ATARI__"]
executable app {
# Inherits cpu=68000, opt=O2, define=["__ATARI__"]
define += ["APP=1"]
sources = ["src/main.c"]
}
}
Targets, Dependencies, and Imports
RBS defines three kinds of build target:
executable name { ... }— compiles sources and links a runnable program (.TOS,.PRG, or host binary).library name { ... }— archives compiled objects into a static library (.a).object name { ... }— produces a standalone relocatable object (.o), useful for custom startup modules such ascrt0.
Targets link against libraries or objects listed in deps = [...]. A library can declare export_include and export_define so every target that depends on it receives those headers and macros automatically:
library math {
sources = ["src/math.c"]
include = ["include"]
export_include = ["include"]
}
executable game {
sources = ["src/main.c"]
deps = ["math"] # Automatically adds "include" from math
}
Use import "path/to/other.rbs" to pull targets from another build file. You can also pass per-dependency overrides to build an isolated variant of a library for a specific target:
import "../LIBCMINI/build.rbs"
executable app {
sources = ["main.c"]
deps = ["cmini" { fastcall = false }]
}
Source Discovery (glob)
Instead of listing every file by hand, use glob(...) to match source files, with an optional exclude list and brace expansion:
sources = [
"src/init.c",
glob("src/**/*.c", exclude = ["src/coldfire/*.c", "src/unused.c"]),
glob("{aes,bdos,bios,vdi}/*.c", exclude = ["bios/coldfire.c"]),
]
RBS caches watched directory timestamps so incremental null builds skip re-scanning unchanged trees.
Configs, Platforms, and Conditionals (when)
A single script can define multiple build configurations (config) and conditional blocks (platform, when):
config name { ... }defines a named build profile (selected with--config=name). A config can extend another usinginherits = base.platform name { ... }applies settings only when building for that target platform (atari,linux,macos,windows).when expr { ... }conditionally applies settings using==,!=, orin.
config debug {
opt = O0
debug = true
define = ["DEBUG=1"]
}
config release {
opt = O2
opt_size = true
define = ["NDEBUG=1"]
}
config shipping {
inherits = release
strip = all
}
executable game {
name = "SPACE_WARS"
format = tos
output_dir = "BIN/${PLATFORM}/${CONFIG}"
sources = glob("src/*.c")
when platform == atari {
cpu = 68000
vice_labels = (config != shipping)
sources += glob("src/atari/*.S")
}
when platform != atari {
sources += glob("src/sdl/*.c")
}
}
File Operations
RBS provides built-in file operations so builds stay self-contained without shell scripts, sed, or cp. Pre-build operations (file_configure, files_copy, file_write) run in dependency order before any source file compiles and are idempotent: if the output bytes are unchanged, RBS preserves the file timestamp so downstream targets are not needlessly rebuilt. Post-link staging (files_stage) runs after linking completes.
file_configure(src, dst, vars?)
Pre-build template substitution. Reads a template file, replaces @KEY@ and ${KEY} placeholders, and writes the result before compilation.
src— Path to the input template file (e.g."mt_gem.h.in").dst— Output file path (commonly under${GEN_DIR}).vars(optional) — Map of placeholder keys to string values, e.g.{ MAJOR = "0", MINOR = "44" }.
library gem {
file_configure(
src = "mt_gem.h.in",
dst = "${GEN_DIR}/include/mt_gem.h",
vars = { MAJOR = "0", MINOR = "44" },
)
include = ["${GEN_DIR}/include", "."]
export_include = ["${GEN_DIR}/include"]
sources = glob("*.c")
}
files_copy(src, dst_dir, base_dir?, flatten?)
Pre-build file and tree copying. Copies files or glob(...) matches into a destination directory before compilation.
src/sources— Single path, list of paths, orglob(...)expression.dst_dir/dst— Destination directory path.base_dir(optional) — Directory prefix to strip whenflatten = false.flatten(optional, defaulttrue) — Whentrue, copies files directly intodst_dir; whenfalse, preserves subdirectory structure relative tobase_dir.
library gem {
// Flat copy into ${GEN_DIR}/include
files_copy(["gem.h", "gemx.h"], "${GEN_DIR}/include")
// Tree-preserving copy keeping paths relative to "include"
files_copy(
sources = glob("include/**/*.h"),
dst_dir = "${GEN_DIR}/include",
base_dir = "include",
flatten = false,
)
}
file_write(content, dst)
Pre-build literal file generation. Writes literal or interpolated text directly to a file (input content first, output path second) without needing a separate .in template.
content— String contents to write (supports${VAR}interpolation).dst— Output file path.
library gem {
file_write("#define BUILD_TAG 1\n", "${GEN_DIR}/include/tag.h")
}
files_stage = [{ sources, dst_dir }]
Post-link asset staging. Unlike the three pre-build operations above, files_stage is a target property rather than a statement. It copies runtime assets once target linking succeeds.
sources/src— List of runtime asset paths orglob(...)matches (such as.rsc,.inf, or data files).dst_dir/dst— Destination directory where the assets are staged after linking.
executable app {
deps = ["gem"]
sources = ["main.c"]
files_stage = [
{ sources = ["app.rsc", "app.inf"], dst_dir = "build/stage" },
]
}
Overrides
Use group to apply settings to a subset of files, or attach a block directly to a file path inside sources:
executable demo {
sources = [
glob("src/*.c"),
"src/loader.c" { opt = Os },
"src/raster.c" { opt = O3, cflags = ["--loop-unroll=4"] },
]
group "asm" {
asm_dialect = gas
sources = glob("src/asm/*.S")
}
}
Pure C & AHCC .PRJ Compatibility
rg-cc also parses classic Pure C and AHCC .PRJ project files directly into the RBS build graph, with case-insensitive path resolution, nested .PRJ support, and automatic mapping of standard runtime libraries (PCSTART.O, PCSTDLIB.LIB, PCTOSLIB.LIB, PCGEMLIB.LIB) when absent on disk.
rg-cc HIGHWIRE.PRJ
rg-cc HIGHWIRE.PRJ -O3 --cpu=68030
| Pure C / AHCC Directive | Translated RBS Property | Description |
|---|---|---|
.C [-2] / [-3] / [-4] / [-6] |
cpu = 68020 / 68030 / 68040 / 68060 |
Target CPU architecture selection |
.C [-8] |
fpu = hard (68881) |
Hardware floating-point coprocessor code generation |
.C [-D<macro>] / [-U<macro>] |
define = [...] / undef = [...] |
Preprocessor macro definitions and removals |
.C [-I<dir>] / [-i<dir>] |
include = [...] |
Include search directory paths (DOS \ normalised to /) |
.C [-Y] |
debug = true |
Generate DRI/GST symbol debug tables |
.L [-S=<bytes>] |
stack_size = <bytes> |
Sets program stack allocation in bytes |
.L [TTMALLOC / FASTLOAD] |
tos_flags = 0x7 |
Sets GEMDOS program header flags (FastRAM load & alloc) |
Reference
Formal Grammar Summary (EBNF)
File ::= Stmt*
Stmt ::= ImportStmt | VarDecl | PropAssign | FileOpStmt | WhenBlock
| ProjectBlock | ConfigBlock | PlatformBlock | TargetBlock | GroupBlock
ImportStmt ::= "import" StringLit
VarDecl ::= "var" Ident "=" Expr
ProjectBlock ::= "project" IdentOrString "{" Stmt* "}"
ConfigBlock ::= "config" Ident ("{" Stmt* "}")
PlatformBlock ::= "platform" Ident ("{" Stmt* "}")
TargetBlock ::= ("executable" | "library" | "object") IdentOrString "{" Stmt* "}"
GroupBlock ::= "group" IdentOrString "{" Stmt* "}"
WhenBlock ::= "when" CondExpr "{" Stmt* "}"
FileOpStmt ::= ("file_configure" | "files_copy" | "file_write") "(" (Arg ("," Arg)* ","?)? ")"
PropAssign ::= Ident ("=" | "+=" | "-=") Expr
Expr ::= StringLit | IntLit | BoolLit | Ident | ListExpr | MapExpr | CallExpr | SourceWithOverride
ListExpr ::= "[" (Expr ("," Expr)* ","?)? "]"
MapExpr ::= "{" (Ident "=" Expr ("," Ident "=" Expr)* ","?)? "}"
CallExpr ::= Ident "(" (Arg ("," Arg)* ","?)? ")"
Arg ::= (Ident "=")? Expr
SourceWithOverride ::= StringLit "{" Stmt* "}"
File Operations Reference
File operations accept either positional arguments or named key = value arguments. Pre-build operations run idempotently before compilation; files_stage is a target property evaluated after linking.
| Operation | Positional / Named Form | Phase & Semantics |
|---|---|---|
file_configure |
file_configure(src, dst, vars)file_configure(src = "...", dst = "...", vars = { ... }) |
Pre-build. Expands @KEY@ and ${KEY} placeholders in src and writes dst only if content changed (preserving mtime). |
files_copy |
files_copy(src, dst_dir)files_copy(sources = [...], dst_dir = "...", base_dir = "...", flatten = true) |
Pre-build. Copies files or globs into dst_dir idempotently. Set flatten = false with optional base_dir to preserve directory structure. |
file_write |
file_write(content, dst)file_write(content = "...", dst = "...") |
Pre-build. Writes literal or interpolated text content to dst idempotently (preserving mtime when unchanged). |
files_stage |
files_stage = [{ sources = [...], dst_dir = "..." }] |
Post-link property. Copies runtime assets (.rsc, .inf, data files) to dst_dir when target linking completes. |
Structured Property Reference
| Category | Property Name | Allowed Values / Type | Inheritance & Semantics |
|---|---|---|---|
| Architecture | cpu |
68000, 68020, 68030, 68040, 68060 |
Overrides outer scope. Sets 680x0 instruction set and addressing modes. |
| Architecture | fpu |
none, soft, hard, 68881, 68040 |
Overrides outer scope. Configures floating-point instruction generation. |
| ABI | abi |
fastcall, cdecl |
Overrides outer scope. fastcall passes arguments in registers (D0–D2 / A0–A1). |
| Dialect | std |
c89, c99, gnu99, c11 |
Sets C language standard conformance. |
| Dialect | dialect |
gcc, vbcc, purec |
Enables compiler-specific keyword extensions and built-in type behaviours. |
| Optimisation | opt |
O0, O1, O2, O3, Os |
Overrides outer scope. Sets global optimisation tier. |
| Optimisation | opt_size |
true, false |
Prioritises 68000 code byte size over cycle latency. |
| Optimisation | small_data |
true, false |
Enables 16-bit A4-relative small data model across compiler, assembler, and linker. |
| Optimisation | lto |
true, false |
Enables cross-module whole-program link-time optimisation. |
| Preprocessor | include |
List<String> |
Appends outer → inner. Adds header search directory paths. |
| Preprocessor | define |
List<String> |
Appends outer → inner. Predefines preprocessor macros (["FOO=1", "BAR"]). |
| Preprocessor | undef |
List<String> |
Removes previously inherited macro definitions. |
| Preprocessor | force_include |
List<String> |
Forces inclusion of specified headers before translation unit source text. |
| Assembler | asm_dialect |
vasm, gas |
Selects Motorola standard (vasm) or MIT/GNU (gas) assembly syntax parser. |
| Assembler | asm_define |
List<String> |
Defines assembly-level symbols during assembly passes. |
| Linker | format |
tos, prg, app, ttp, gtp |
Sets Atari GEMDOS binary executable format and extension. |
| Linker | tos_flags |
Int or List<Ident> |
GEMDOS program header flags ([fastload, fastram, fastram_alloc] or 0x7). |
| Linker | stack_size |
Int |
Sets executable stack allocation size in bytes. |
| Linker | sym |
gst, dri, extern, none |
Selects symbol table encoding format inside executable header. |
| Linker | relax_pcrel |
true, false |
Enables 16-bit PC-relative branch relaxation and stub elimination in linker. |
| Linker | crt0 |
builtin, none, or Target |
Selects C runtime startup code entry module. |
| Raw Escape | cflags, asflags, ldflags |
List<String> |
Raw CLI flag escape hatches. Use -= to remove an inherited flag. |
Built-in Variables Reference
| Variable | Example Value | Description |
|---|---|---|
${ROOT} |
/home/user/project |
Absolute directory path of the root .rbs script invoked on the CLI. |
${DIR} |
/home/user/project/lib |
Directory of the current .rbs file (enables self-contained imported modules). |
${GEN_DIR} |
.rbs-cache/gen/gem |
Isolated per-target generated file directory for file_configure(). |
${PLATFORM} |
ATARI |
Active target platform identifier (ATARI, LINUX, MACOS, WINDOWS). |
${CONFIG} |
RELEASE |
Active target configuration profile (DEBUG, RELEASE, SHIPPING, LOWMEM). |
${HOST_OS} |
linux |
Host operating system executing rg-cc (linux, macos, windows). |
Command-Line Interface (CLI) Reference
# Build default target in ./build.rbs:
rg-cc build
# Build from an explicit script:
rg-cc build.rbs
rg-cc myproject.rbs
# Build a specific target with configuration overrides:
rg-cc build.rbs mygame --platform=atari --config=shipping -O3
# Build a legacy Pure C / AHCC project:
rg-cc HIGHWIRE.PRJ
# List all targets, configurations, and platforms in the build graph:
rg-cc build.rbs --list-targets
# Perform parallel in-process syntax and semantic type check across all targets:
rg-cc build.rbs --syntax-only
# Emit compile_commands.json for clangd / language-server integration:
rg-cc build.rbs --compdb
# Clean project outputs and generated staging files (preserves CAS):
rg-cc build.rbs --clean
# Completely purge the content-addressed cache (.rbs-cache/):
rg-cc build.rbs --clean-cache
Complete Practical Examples
Three complete, self-contained build.rbs scripts showing how the language scales from a single-file utility to a multi-target cross-platform build.
Single-File TOS Utility
Minimal project compiling one C source file into an Atari ST .tos executable with default settings.
project "hello_st"
executable "hello.tos" {
cpu = 68000
sources = ["main.c"]
}
Static Library with Profiles
Splits rendering code into a reusable static library that exports headers and defines, configures debug and release profiles with when, and stages a resource file alongside the linked GEM application.
project "gem_viewer"
cpu = 68000
std = "c99"
warnings = ["all"]
when config == "debug" {
opt = "O0"
debug = true
define = ["DEBUG=1"]
}
when config == "release" {
opt = "O2"
strip = true
define = ["NDEBUG=1"]
}
library "gfx" {
include = ["include"]
export_include = ["include"]
export_define = ["HAS_GFX=1"]
sources = glob("src/gfx/*.c")
}
executable "viewer.app" {
deps = ["gfx"]
sources = ["src/main.c", "src/ui.s"]
files_stage = [
{ sources = ["assets/viewer.rsc"], dst_dir = "dist" },
]
}
Cross-Platform Multi-Target Build
A full cross-platform build with generated headers, a custom dependency variant, and per-file overrides:
project "tracker_suite"
std = "c99"
cflags = ["-Wall", "-Wextra"]
define = ["TRACKER_VER=2", "LEGACY_MIXER"]
when platform == "atari" {
cpu = 68030
fpu = "68882"
define += ["ATARI_TARGET=1"]
}
when platform != "atari" {
compiler = "gcc"
define += ["HOST_TARGET=1"]
}
library "mixer" {
include = ["src/mixer/include"]
export_include = ["src/mixer/include"]
sources = glob("src/mixer/*.c")
}
library "dsp_core" {
file_configure(
src = "src/dsp/config.h.in",
dst = "${GEN_DIR}/include/dsp_config.h",
vars = { CHANNELS = "8", SAMPLE_RATE = "49170" },
)
files_copy(["src/dsp/dsp_api.h"], "${GEN_DIR}/include")
file_write("#define DSP_BUILD_TAG 1\n", "${GEN_DIR}/include/dsp_tag.h")
include = ["${GEN_DIR}/include", "src/dsp/include"]
export_include = ["${GEN_DIR}/include"]
sources = glob("src/dsp/*.c")
}
executable "tracker.prg" {
// Exclude an inherited define and compiler flag for this target
define -= ["LEGACY_MIXER"]
cflags -= ["-Wextra"]
deps = [
"dsp_core",
// Request a custom variant of mixer without affecting other targets
"mixer" {
define += ["MIXER_CHANNELS=8"]
},
]
group "hot_path" {
opt = "O3"
sources = ["src/render.c", "src/mixer_glue.c"]
}
sources = [
"src/main.c",
"src/startup.s" {
asm_dialect = "vasm"
},
]
files_stage = [
{ sources = glob("assets/*.dat"), dst_dir = "dist/data" },
]
}