]> git.cameronkatri.com Git - cc-run.git/blob - cc-run.sh
Fix some quotes
[cc-run.git] / cc-run.sh
1 #!/bin/sh
2 compiler=$(basename "$0" | sed 's|-run$||')
3 exe=$(mktemp -t cc-run) || exit 1
4 src=""
5 args=""
6 exeargs=""
7
8 if ! command -v "$compiler" >/dev/null 2>&1; then
9 echo "$(basename "$0"): error: can't find compiler: '$compiler'" >&2
10 exit 1
11 fi
12
13 for arg in "$@"; do
14 if [ -e "$arg" ] && [ "$src" = "" ]; then
15 src=$arg
16 elif [ "$src" != "" ]; then
17 exeargs="$exeargs $arg"
18 else
19 args="$args $arg"
20 fi
21 done
22
23 case "$compiler" in
24 cc|gcc|gcc-*|clang|clang-*)
25 args="$args $CPPFLAGS $CFLAGS $LDFLAGS";;
26 c++|g++|g++-*|clang++|clang++-*)
27 args="$args $CPPFLAGS $CXXFLAGS $LDFLAGS"
28 esac
29
30 $compiler $args $src -o $exe || exit 1
31
32 $exe $exeargs
33 ret=$?
34 rm -f $exe
35 exit $ret