Info • Install • Usage • License
This is my opinionated template for initializing, building, and maintaining C projects. Powered by nob.h.
Important
This template is designed for myself specifically. I would recommend (if you're adopting this system yourself) that you fork or clone this repo and set it up to your own liking.
- Portable code.
- No external dependencies apart from a C compiler.
- Static file header generation.
- Project environment variables (inspired by uv and cargo).
- Configurable within nob.c.
- Accessible as pre-processor macros within your program.
Append this function to your .bashrc (or an equivalent file in your shell path) and you're good to go.
#!/usr/bin/env bash
cinit() {
set -x
local tmp=$(mktemp -d)
curl -L https://github.com/simon-danielsson/ctmp/archive/refs/heads/main.tar.gz \
| tar -xz --strip-components=1 ctmp-main/init
echo "#define PROJ_NAME \"$1\"" | cat - init/nob.c > init/tmp && mv -f init/tmp init/nob.c
if [[ -d init ]]; then
mv init "$1"
cd "$1"
gcc -o nob nob.c
git init -b main
git add --all
git commit -m init
git tag v0.1.0
cd ..
fi
set +x
}Run cinit with the name of your new project as an argument. A new project
folder will be created in the current directory.
cinit <project-name>The generated project will have the following hierarchy:
/root
├── .clangd
├── .git
├── .gitignore
├── LICENSE
├── nob
├── nob.c
├── nob.h
├── /src
│ ├── main.c
│ └── main.h
└── /tests
├── tests.c
└── tests.h
./nob [options|command]
* Execute without options to compile and run a debug build.
* Program arguments are passed after a divider '--'.
-h, --help Display help.
-v, --verbose Enable verbose output.
-n, --no-run Don't run binary after compilation.
test Run test(s) in 'tests.c'.
release Compile and run a release build.
embed Embed content of files in 'src/static' into header files.
This project is licensed under the MIT License.