tool: use ccache in gccx, if available
[nit.git] / bin / gccx
index 6a5fe4c..6bcd9cf 100755 (executable)
--- a/bin/gccx
+++ b/bin/gccx
@@ -35,6 +35,7 @@ Usage: $e [options] modulename [options for module execution]
 -R          Force full recompilation
 -O          Compile with optimizations
 -i          Use the intel compiler instead of gcc
+-ll         Use the clang compiler (llvm) instead of gcc
 -I path     Add a include directory
 -o name     Call name the executable
 -d          Create temporary files in a specific directory
@@ -65,6 +66,11 @@ fi
 return $res
 }
 
+cache=true
+if ccache -V 2>&1 >/dev/null; then
+       cache=ccache
+fi
+
 stop=false
 verbose=false
 vverbose=false
@@ -73,6 +79,7 @@ while [ $stop = false ]; do
                -R) recompile=true; shift;;
                -O) OPTS="$OPTS -O2" ext="_savo"; shift;;
                -i) CC="/opt/intel/cc/10.1.015/bin/icc -O2" ext="_savi"; shift;;
+               -ll) CC="clang --ansi --pedantic -O3"; ext="_savll"; shift;;
                -I) OPTS="$OPTS -I $2"; shift; shift;;
                -o) out="$2"; shift; shift;;
                -d) dir="$2/"; shift; shift;;
@@ -89,6 +96,10 @@ if [ $nolibgc != true ] && test_libgc; then
        OPTS="$OPTS -DWITH_LIBGC -lgc"
 fi
 
+if [ $cache = "ccache" ]; then
+       CC="ccache $CC"
+fi
+
 for i in "$@"; do
        j=`basename "$i" .c`
        transformed=`echo "$i" | sed "
@@ -105,6 +116,13 @@ for i in "$@"; do
        "`
 
        found="false"
+       if [ $cache != true ]; then
+               o="$dir$j.o"
+               if [ $vverbose = true  ] ; then
+                       echo "* $CC $OPTS -c $i -o $o" >&2
+               fi
+               $CC $OPTS -c $i -o $o || exit 1
+       else
        # We remove starting # to be path independent (after preprocess, there are the only # remainings)
        cksum=`gcc -E $OPTS $i 2> /dev/null | grep -v "^#" | $CKSUM`
        for e in $ext; do
@@ -135,6 +153,7 @@ for i in "$@"; do
                        exit 1
                fi
        fi
+fi
        objs="$objs $o"
 done