4.2 KiB
4.2 KiB
AGENTS.md - kmake Development Guidelines
This document provides guidance for AI agents working on the kmake codebase.
Project Structure
kmake/
├── kmake.yml # Example/build configuration
├── CMakeLists.txt # Build configuration
├── README.md # User documentation
├── AGENTS.md # This file
└── src/
└── kmake/
├── kmake.hpp # Core includes and namespace
├── kmake.cpp # Main entry point
├── project/
│ ├── Project.hpp # Project configuration model
│ ├── Project.cpp # YAML parsing, variable resolution
│ ├── Distro.hpp # Per-distro build commands
│ └── Distro.cpp # Distro implementation
└── build/
├── Executor.hpp # Command execution engine
└── Executor.cpp # Parallel/serial execution logic
Key Concepts
Project Configuration (Project)
- Loads and parses
kmake.yml - Holds global
vars,buildsettings, anddistrosmap - Provides variable resolution with fallback: distro vars → global vars → defaults
Distro Configuration (Distro)
- Contains phase commands:
start,deps,compile,link,end - Has own
varsmap that overrides global variables - Commands use
{placeholder}substitution
Execution Model (Executor)
- Runs commands sequentially within a phase
compilephase runs in parallel (one thread per file, up tobuild.threads)- Other phases run serially
- Each command is a shell command with variable expansion
Variable Placeholders
Standard placeholders available in all commands:
{src_file}- Current source file{obj_file}- Current object file{obj_files}- All object files (link phase only){dep_file}- Current dependency file{rv_dep_file}- Reverse dependency file{out}- Output executable path{bin}- Binary directory{include}- Include paths{cflags}- Compiler flags{ldflags}- Linker flags
Custom variables from vars and distros.*.vars are also available.
Coding Conventions
C++ Style
- Use
ckitty::namespace utilities (string, vector, map, optional) - Follow existing naming:
PascalCasefor classes,camelCasefor methods/variables - Use
structfor plain data,classfor behavior - Prefer
std::optionalover pointers for nullable values
Error Handling
- Return
boolfor success/failure in loading/parsing - Use
ckitty::optionalfor lookup operations - Log errors via
desktoplib::terminalat appropriate verbosity
YAML Parsing
- Use existing YAML library (likely yaml-cpp)
- Validate required fields, provide defaults for optional
- Distro names are case-sensitive keys in the
distrosmap
Building and Testing
# On Windows, development is done on MSYS2 UCRT64.
# Please use the dedicated script to forward commands there.
./msys2.ps1 make
Common Tasks
Adding a New Build Phase
- Add field to
Distroclass (vector) - Add field to
Project::buildstruct if global config needed - Update
Project::load()to parse from YAML - Add execution in
Executoror main build loop - Document in README.md
Adding a New Placeholder Variable
- Add resolution logic in
Project::getVar()orDistro::getVar() - Ensure fallback chain works: distro → global → builtin
- Update command expansion to recognize new placeholder
Supporting New Dependency Style
- Add
styleenum/string toProject::build::deps - Implement generation in distro
depscommands - Implement parsing in reverse dependency tracking
Testing Checklist
- Valid kmake.yml loads without errors
- Variable substitution works in all phases
- Parallel compilation respects thread limit
- Dependency files generated correctly
- Distro-specific vars override globals
- Missing distro gives clear error
- Verbosity levels control output correctly
Debugging Tips
- Use
-verbosity debugto see all command expansions - Check generated dependency files in
{bin}/*.d - Verify placeholder expansion with
echoin start phase - Use
kmake -listto verify parsed config