From ecd234dc9d0b1a763894e0db686a9e38054bdae8 Mon Sep 17 00:00:00 2001 From: vg Date: Thu, 4 Apr 2024 15:21:48 +0200 Subject: add script to compile C single sources codes to use as script --- scripts/C | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 scripts/C (limited to 'scripts') diff --git a/scripts/C b/scripts/C new file mode 100755 index 0000000..00fbd41 --- /dev/null +++ b/scripts/C @@ -0,0 +1,22 @@ +#!/bin/sh + +src="$1" +shift + +filename="${src##*/}" +filename="${filename%.*}" +runcache="$HOME/.cache/C" +CC=cc + +# need to compile? (use not -ot to circumvent inexisting file the first time) +if [ ! "$src" -ot "$runcache/$filename" ]; then + mkdir -p "$runcache" + # get rid of shebang line in C program and compile it + tail -n +2 "$src" > "$runcache/$filename.c" + if [ -r /usr/bin/clang ]; then + CC=clang + fi + "$CC" -Wall -std=c99 $CC_OPTS -o "$runcache/$filename" "$runcache/$filename.c" +fi + +exec "$runcache/$filename" "$@" -- cgit v1.2.3