From: Cameron Katri Date: Fri, 8 Apr 2022 23:39:57 +0000 (-0400) Subject: Allow compiling stdin X-Git-Url: https://git.cameronkatri.com/cc-run.git/commitdiff_plain/60e2b04758e8389eb81cd6cd0f67df3c8b7f1c2d Allow compiling stdin --- diff --git a/cc-run.sh b/cc-run.sh index 7a59ed6..ee1d5fd 100755 --- a/cc-run.sh +++ b/cc-run.sh @@ -1,6 +1,5 @@ #!/bin/sh compiler=$(basename "$0" | sed 's|-run$||') -exe=$(mktemp -t cc-run) || exit 1 src="" args="" exeargs="" @@ -11,8 +10,8 @@ if ! command -v "$compiler" >/dev/null 2>&1; then fi for arg in "$@"; do - if [ -e "$arg" ] && [ "$src" = "" ]; then - src=$arg + if [ "$src" = "" -a -e "$arg" -o "$arg" = "-" ]; then + src="$arg" elif [ "$src" != "" ]; then exeargs="$exeargs $arg" else @@ -20,14 +19,24 @@ for arg in "$@"; do fi done -case "$compiler" in - cc|gcc|gcc-*|clang|clang-*) +case $compiler in + cc|gcc|gcc-*|clang|clang-*|tcc) + if [ "$src" = '-' ]; then + args="$args -x c" + fi args="$args $CPPFLAGS $CFLAGS $LDFLAGS";; c++|g++|g++-*|clang++|clang++-*) + if [ "$src" = '-' ]; then + args="$args -x c++" + fi args="$args $CPPFLAGS $CXXFLAGS $LDFLAGS" esac -$compiler $args $src -o $exe || exit 1 +exe=$(mktemp -t cc-run) || exit 1 +if ! $compiler $args $src -o $exe; then + rm -f $exe + exit 1 +fi $exe $exeargs ret=$?