37 lines
786 B
Bash
Executable File
37 lines
786 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ $# -lt 1 ]; then
|
|
cat<<EOF
|
|
Usage: ${0##*/} FILE [GCC_OPTS]
|
|
|
|
Simulate a C interpreter by compiling, executing and removing file in one run.
|
|
EOF
|
|
exit
|
|
fi
|
|
|
|
INPUT="$1"
|
|
|
|
shift
|
|
GCC_OPTS="-O0 -Wall -Wextra -Wshadow -pthread -lm"
|
|
if [ $# -ne 0 ]; then
|
|
GCC_OPTS="$@"
|
|
fi
|
|
|
|
FILE="$(mktemp)"
|
|
echo "==> gcc \"$INPUT\" -o \"$FILE\" $GCC_OPTS"
|
|
|
|
## Zsh compatibility. We need it otherwise word splitting of parameter GCC_OPTS
|
|
## will not work.
|
|
STATUS="$(set -o | grep 'shwordsplit' | awk '{print $2}')"
|
|
[ "$STATUS" = "off" ] && set -o shwordsplit
|
|
|
|
gcc "$INPUT" -o "$FILE" $GCC_OPTS
|
|
|
|
## 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"
|