ambevar-dotfiles/.scripts/crun

35 lines
747 B
Plaintext
Raw Normal View History

#!/bin/sh
if [ $# -lt 1 ]; then
cat<<EOF
2016-06-23 23:18:36 +02:00
Usage: ${0##*/} FILE [CFLAGS]
2013-06-25 22:56:10 +02:00
Simulate a C interpreter by compiling, executing and removing file in one run.
EOF
exit
fi
[ -z "$CC" ] && CC=gcc
INPUT="$1"
shift
2016-06-23 23:18:36 +02:00
[ $# -eq 0 ] && set -- -Wall -Wextra -Wshadow -pthread -lm -g3 -O0
FILE="$(mktemp)"
2016-06-23 23:18:36 +02:00
echo "==> $CC \"$INPUT\" -o \"$FILE\" $*"
## Zsh compatibility. We need it otherwise word splitting of parameter will not
## work.
STATUS="$(set -o | awk '/shwordsplit / {print $2}')"
[ "$STATUS" = "off" ] && set -o shwordsplit
2016-06-23 23:18:36 +02:00
$CC "$INPUT" -o "$FILE" "$@"
## Restore Zsh previous options. This will not turn off shwordsplit if it
## was on before calling the function.
[ "$STATUS" = "off" ] && set +o shwordsplit
echo "==> $FILE"
"$FILE"
rm "$FILE"