35 lines
747 B
Bash
Executable File
35 lines
747 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ $# -lt 1 ]; then
|
|
cat<<EOF
|
|
Usage: ${0##*/} FILE [CFLAGS]
|
|
|
|
Simulate a C interpreter by compiling, executing and removing file in one run.
|
|
EOF
|
|
exit
|
|
fi
|
|
|
|
[ -z "$CC" ] && CC=gcc
|
|
INPUT="$1"
|
|
|
|
shift
|
|
[ $# -eq 0 ] && set -- -Wall -Wextra -Wshadow -pthread -lm -g3 -O0
|
|
|
|
FILE="$(mktemp)"
|
|
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
|
|
|
|
$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"
|