#!/bin/sh # This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2008 Jean Privat # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Separately recompile a bunch of c files then link them OPTS="-g" # option for compiler call objs="" # List of .o files CC="gcc --ansi --pedantic -Wall -Wextra -Wformat-security -Wcast-align -Wno-uninitialized -Wno-unused-variable -Wno-unused-label -Wno-unused-parameter" # Default compiler call ext="_savo _sav" # Default flavor to reuse out="a.out" # Default output binary filename dir="" # Default tmp dir nolibgc="false" # Try to use libgc ? CKSUM="cksum" # Tool that perfors checksum. cksum seems to be very portable usage() { e=`basename "$0"` cat< .tmp.c < #include 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 } stop=false while [ $stop = false ]; do case $1 in -O) OPTS="$OPTS -O2" ext="_savo"; shift;; -i) CC="/opt/intel/cc/10.1.015/bin/icc -O2" ext="_savi"; 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;; -h|"") usage; exit;; *) stop=true esac done if [ $nolibgc != true ] && test_libgc; then OPTS="$OPTS -DWITH_LIBGC -lgc" fi for i in "$@"; do j=`basename "$i" .c` found="false" # 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 cksumtry=`cat $cksumfile` if [ "x$cksum" = "x$cksumtry" ]; then found=true break fi fi done if [ $found = false ]; then echo "* $CC $OPTS -c $i -o $o" >&2 if $CC $OPTS -c $i -o $o; then echo "$cksum" > "$cksumfile" else exit 1 fi fi objs="$objs $o" done echo "* $CC $OPTS -lm $objs -o $out" >&2 $CC $OPTS -lm $objs -o "$out"