OPTS="-g" # option for compiler call
objs="" # List of .o files
-CC="gcc --ansi --pedantic" # Default compiler call
+CC="gcc --ansi --pedantic -Wall -Wextra -Wformat-security -Wcast-align -Wno-uninitialized -Wno-unused-variable -Wno-unused-label -Wno-unused-parameter -Wno-missing-field-initializers -Wno-array-bounds -Wno-unused-but-set-variable" # Default compiler call
ext="_savo _sav" # Default flavor to reuse
out="a.out" # Default output binary filename
dir="" # Default tmp dir
+nolibgc="true" # Disable boehm libgc?
CKSUM="cksum" # Tool that perfors checksum. cksum seems to be very portable
+recompile="false"
usage()
{
e=`basename "$0"`
cat<<END
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
+-nolibgc Do not include libgc
+-v Verbose (show compilation steps)
+-vv Verbose+ (show gcc calls)
-h This help
END
}
+test_libgc() {
+cat > .tmp.c <<END
+#include <stdlib.h>
+#include <gc/gc.h>
+int main(void) {
+ void *r = GC_malloc(1);
+ return r == NULL;
+ }
+END
+gcc .tmp.c -lgc -o .tmp.bin 2> /dev/null
+res=$?
+rm .tmp.c
+if [ $res = 0 ]; then
+ ./.tmp.bin
+ res=$?
+ rm .tmp.bin
+fi
+return $res
+}
+
+cache=true
+if ccache -V 2>/dev/null >/dev/null; then
+ cache=ccache
+fi
+
stop=false
+verbose=false
+vverbose=false
while [ $stop = false ]; do
case $1 in
- -O) CC="gcc --ansi --pedantic -O2" ext="_savo"; shift;;
+ -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;;
+ --nolibgc) nolibgc=true; shift;;
-x) OPTS="$OPTS $2"; shift; shift;;
+ -vv) vverbose=true; verbose=true; shift;;
+ -v) verbose=true; shift;;
-h|"") usage; exit;;
*) stop=true
esac
done
+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 "
+ /\.nit_compile\/.*_sep\.c/s/\.nit_compile\/\(.*\)\._sep\.c/Module \1/
+ /\.nit_compile\/.*_glob\.c/s/\.nit_compile\/\(.*\)\._glob\.c/Module \1/
+ /\.nit_compile[1-9]\/.*_sep\.c/s/\.nit_compile[1-9]\/\(.*\)\._sep\.c/Module \1/
+ /\.nit_compile[1-9]\/.*_glob\.c/s/\.nit_compile[1-9]\/\(.*\)\._glob\.c/Module \1/
+ /\/nit_main\.c/s/.*\/nit_main\.c/Main/
+ /\.nit_compile\/.*\._tables\.c/s/.*/Tables/
+ /\.nit_compile[1-9]\/.*\._tables\.c/s/.*/Tables/
+ /\/\/.*_nit\.c/s/.*\/\/\(.*\)_nit.c/Native \1/
+ s/.*\/gc.c/Garbage Collector/
+ s/.*\/gc_static_objects_list.c/Garbage Collector object list/
+ "`
+
found="false"
- cksum=`gcc -E $i 2> /dev/null | $CKSUM`
+ 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
o="$dir$j.$e.o"
cksumfile="$dir$j.$e.cksum"
- if [ -f "$cksumfile" -a -f "$o" ]; then
+ if [ -f "$cksumfile" -a -f "$o" -a "x$recompile" != "xtrue" ]; then
cksumtry=`cat $cksumfile`
if [ "x$cksum" = "x$cksumtry" ]; then
+ if [ $vverbose = true ] ; then
+ echo "* $transformed up-to-date"
+ fi
found=true
break
fi
fi
done
if [ $found = false ]; then
- echo "* $CC $OPTS -c $i -o $o" >&2
+ if [ $verbose = true ] ; then
+ if [ $vverbose = true ] ; then
+ echo "* $CC $OPTS -c $i -o $o" >&2
+ else
+ echo "* $transformed"
+ fi
+ fi
if $CC $OPTS -c $i -o $o; then
echo "$cksum" > "$cksumfile"
else
exit 1
fi
fi
+fi
objs="$objs $o"
done
-echo "* $CC $OPTS -lm $objs -o $out" >&2
+if [ $vverbose = true ] ; then
+ echo "* $CC $OPTS -lm $objs -o $out" >&2
+fi
$CC $OPTS -lm $objs -o "$out"