mkgen is a lightweight Makefile generator designed for my everyday C and C++ workflow.
I often start with a small C or C++ file. Then it grows. Suddenly there are multiple .c / .cpp files, header files, and sometimes a graphical library involved. At that point, compiling manually or rewriting a Makefile becomes repetitive and annoying.
So I built mkgen.
It’s written in Python and focuses on C and C++ projects, with optional support for graphical libraries when needed.
- I like coding in C and C++
- Small projects tend to grow faster than expected
- Writing Makefiles over and over is tiring
- Linking multiple source files and libraries manually is error‑prone
mkgen automates the boring part so I can focus on writing code.
- Automatically generates a Makefile for C and C++ projects
- Detects multiple source files and header files in a deterministic way using anchor files
- Supports both C and C++ compilation
- Designed to scale from tiny projects to larger ones
- Optional support for graphical libraries
- Simple and minimal by design
mkgen is not meant to replace advanced build systems like CMake or Meson.
It is meant to be:
- Simple
- Fast
- Opinionated toward C/C++
- Easy to understand and modify
It exists because I needed it.
- Python 3.11+
- A C compiler (
gcc,clang, etc.) - or a C++ compiler (
g++,clang++) makeusing posix environement on windows (msys2, git bash...etc)
- Clone the repository:
git clone https://github.com/gtRZync/mkgen.gitcd mkgen- Install globally for convenience:
pip install .Assuming MyProject is an existing C or C++ project:
cd MyProjectCreate anchor files to identify your project's modules and public include directories:
touch src/.module
touch src/entity/.module
touch src/objects/.module
touch include/.public
touch include/entity/.public
touch include/objects/.publicInitialize the project configuration:
mkgen init .Edit mkgen.toml to match your project's requirements.
Generate the Makefiles:
mkdir -p build
mkgen generate --root . --build-dir buildBuild the project:
mkgen build --build-dir build --target run --parallel 12Note
After the initial generate, structural changes (such as adding or removing modules or source files) are detected automatically by mkgen build, which regenerates the necessary generated files before invoking make.
Creates a mkgen.toml template in the project root.
Usage
mkgen init <ROOT-DIR>| Argument | Description |
|---|---|
root |
The project source directory. |
| Argument | Description | Default |
|---|---|---|
--force |
Force config file generation if exists. | False |
-h, --help |
show an help message and exit |
Generate a Makefile based on the current project's config.
Usage
mkgen generate [<options>]| Argument | Description |
|---|---|
--root |
The project source directory. |
--build-dir |
Directory where mkgen generates build files (including the Makefile). |
| Argument | Description | Default |
|---|---|---|
-l, --language |
Specify the programming language to use. Supported: C or C++. |
None |
-c, --compiler |
Specify the compiler to use. This value will be written into the generated Makefile. | None |
-std, --standard |
Specify the language standard to use (e.g., c11, c17, c++11, c++17, c++20). | None |
--gui |
Include GUI library flags in the Makefile. Supported backend: SDL2, SFML, RAYLIB. |
None |
--app-name |
Specify the name of the output binary/executable. | None |
--force |
Force makefile generation if exists | False |
-h, --help |
show an help message and exit |
Builds the project using make under the hood.
Usage
mkgen build [<options>]| Argument | Description |
|---|---|
--build-dir |
Directory where mkgen generates build files (including the Makefile). |
| Argument | Description | Default |
|---|---|---|
--parallel |
Indicate how many jobs make should run. | False |
--target |
Makefile recipe to build. | None |
-h, --help |
show an help message and exit |
Display mkgen's current version.
Usage
mkgen versionNote
The version command is equivalent to running mkgen --version.
| Flag | Description |
|---|---|
--banner |
Show ASCII banner |
--no-banner |
Disable ASCII banner |
| Flag | Description |
|---|---|
-v, --version |
Print version information and exit |
-h, --help |
Show help and exit |
mkgen generate --root . --build-dir build/Note
Uses mkgen config file (mkgen.toml)
A template of this file can be generated using the init command.
Caution
Not wired yet.
mkgen generate --root . \
--build-dir build/ \
--lang C++ \
-c clang++ \
-std c++17 \
--gui=SDL2 \
--app-name my_appmkgen generate --root . \
--build-dir build/ \
-l C \
-std c23 \
-c gccThis is a personal tool built for real projects. Features may evolve as my workflow evolves.
