aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vgm+dev@devys.org>2024-04-04 15:21:48 +0200
committervg <vgm+dev@devys.org>2024-04-04 15:21:48 +0200
commitecd234dc9d0b1a763894e0db686a9e38054bdae8 (patch)
treef0a6eb7a750664dba912e825b95da24257edb276
parent8ea01476f31691fb628163e8dd2320abd76a901a (diff)
downloadscripts-ecd234dc9d0b1a763894e0db686a9e38054bdae8.tar.gz
scripts-ecd234dc9d0b1a763894e0db686a9e38054bdae8.tar.bz2
scripts-ecd234dc9d0b1a763894e0db686a9e38054bdae8.zip
add script to compile C single sources codes to use as script
-rwxr-xr-xscripts/C22
1 files changed, 22 insertions, 0 deletions
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" "$@"