aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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" "$@"