aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xngc62
1 files changed, 62 insertions, 0 deletions
diff --git a/ngc b/ngc
new file mode 100755
index 0000000..36ef94a
--- /dev/null
+++ b/ngc
@@ -0,0 +1,62 @@
+#!/bin/sh
+if [ -n "${NGC_DEBUG+x}" ]; then
+ set -x
+fi
+
+if [ -z "${NGC_CC+x}"]; then
+ NGC_CC=cc
+fi
+
+ARGS=
+SOURCES=
+OUTPUT=
+# we don't want our temporary files to end up in makefile rules so pick all
+# depflags out as well
+DEPFLAGS=
+
+# pick out some important options
+while true; do
+ case "$1" in
+ "") break;;
+ -M) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ -MM) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ -MF) DEPFLAGS="$DEPFLAGS $1 $2"; shift 2;;
+ -MG) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ -MP) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ -MT) DEPFLAGS="$DEPFLAGS $1 $2"; shift 2;;
+ -MQ) DEPFLAGS="$DEPFLAGS $1 $2"; shift 2;;
+ -MD) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ -MMD) DEPFLAGS="$DEPFLAGS $1" ; shift ;;
+ *.c) SOURCES="$SOURCES $1"; shift;;
+ -o) OUTPUT="$2"; shift 2;;
+ *) ARGS="$ARGS $1"; shift;;
+ esac
+done
+
+if [ -z "${SOURCES}" ]; then
+ # there must be an output, although I guess an assertion would be nice?
+ $NGC_CC $DEPFLAGS $ARGS -o "$OUTPUT"
+ exit 0
+fi
+
+TMPFILE1=$(mktemp --suffix=.i)
+TMPFILE2=$(mktemp --suffix=.c)
+
+cleanup() {
+ if [ -z "${NGC_LEAVE_DIRTY+x}" ]; then
+ rm "$TMPFILE1" "$TMPFILE2"
+ fi
+
+ exit $1
+}
+
+$NGC_CC -E $DEPFLAGS $ARGS $SOURCES -o "$TMPFILE1" || cleanup 1
+ngc1 "$TMPFILE1" > "$TMPFILE2" || cleanup 2
+
+if [ -z "$OUTPUT" ]; then
+ $NGC_CC $ARGS "$TMPFILE2" || cleanup 3
+else
+ $NGC_CC $ARGS "$TMPFILE2" -o "$OUTPUT" || cleanup 4
+fi
+
+cleanup 0