TMPL: A stupid-simple templator

Last modification on


While working on a new build system called just (aka. just build), I found the need to template build files to select between debug and release builds. Instead of integrating templating into the build system (like make), I figured creating a generalized templator could prevent feature bloat and perform better, since build files would only need to be "compiled" once during initial configuration. The result is tmpl.


The program fits inside a single, small C file (~240 LOC).

The syntax is intentionally similar to that of the C preprocessor, since it is easy to parse, familiar and intuitive.

Key-value pairs for templating are specified via commandline arguments using -D KEY=VALUE, through a config file using -c CONFIG, or the environment.

The source code is available at:


A Makefile to demonstrate templating:

#default PREFIX /usr/local
#default BINDIR /bin
#default CC gcc

#ifdef DEBUG
#define OPT_CFLAGS -Og -g
#define OPT_CFLAGS -O2

all: test

test: test.c
    #{CC} -o $@ $< #{OPT_CFLAGS} #{EXTRA_CFLAGS}

    rm -f test

    install -m755 -t "#{DESTDIR}#{PREFIX}#{BINDIR}"

    rm -f "#{DESTDIR}#{PREFIX}#{BINDIR}/test"

.PHONY: all clean install uninstall