From 11485d940493c27debe3db28e3e57c627485aba1 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 26 Nov 2021 08:59:05 +0000 Subject: [PATCH] Add infrastructure for simple C-based tools --- .gitignore | 1 + .make-and-exec | 10 ++++++++++ .make-and-exec-Makefile | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 .gitignore create mode 100755 .make-and-exec create mode 100644 .make-and-exec-Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5d7e322 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.make-and-exec-binaries diff --git a/.make-and-exec b/.make-and-exec new file mode 100755 index 0000000..a88a967 --- /dev/null +++ b/.make-and-exec @@ -0,0 +1,10 @@ +#!/bin/bash +# Usage: create a file foo.c, make foo a symlink to this script +# When foo is executed, this script silently compiles foo.c into .make-and-exec-binaries/foo and execs that with the arguments provided. +# The compilation goes through make, so later invocations directly exec the binary with little delay. +# To customise the compilation, you can set a CFLAGS env var before running foo. +set -e +name="$(basename "$0")" +cd "$(dirname "$0")" +make --file .make-and-exec-Makefile --silent ".make-and-exec-binaries/${name}" +exec "./.make-and-exec-binaries/${name}" "$@" diff --git a/.make-and-exec-Makefile b/.make-and-exec-Makefile new file mode 100644 index 0000000..3a56375 --- /dev/null +++ b/.make-and-exec-Makefile @@ -0,0 +1,4 @@ +.make-and-exec-binaries/%: %.c .%-test + mkdir -p .make-and-exec-binaries + $(CC) -O3 -o $@ $< $(CFLAGS) + ./.$(notdir $(@))-test