Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ctmp

MIT License Last commit

InfoInstallUsageLicense


Info

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.

Features

  • Portable code.
    • No external dependencies apart from a C compiler.
  • Static file header generation.
    • nob.c collects all the files within 'src/static' and embeds their contents into header files for use within your program.
    • This feature is obviously not necessary if you're using c23.
  • Project environment variables (inspired by uv and cargo).
    • Configurable within nob.c.
    • Accessible as pre-processor macros within your program.

Install

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
}

Usage

Creating a new project

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

CLI commands (nob)

./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.

License

This project is licensed under the MIT License.

About

A project template for C powered by nob.h

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages