#!/bin/sh
# (C) 2001 Armin Biere ETH Zuerich
#
# This script may be used to link an executable wit ccmalloc

COMPILERS="g++ gcc"
PREFIX=/usr

echo "ccmalloc: installation prefix: $PREFIX"
echo "ccmalloc: valid C++ wrappers: $COMPILERS "
echo 'ccmalloc: $Id: ccmalloc.in,v 1.3 2001/03/05 12:05:09 biere Exp $'

if [ $# -lt 1 ]
then
  echo "*** ccmalloc: command line argument is missing" 1>&2
  exit 1
fi

found=no
base=`basename $1`
args="$*"
for CC in $COMPILERS
do
  if [ $CC = $base ]
  then
    found=yes
    break;
  fi
done

if [ $found = yes ]
then
  wrapper="$PREFIX/lib/ccmalloc-$CC.o"
  echo "ccmalloc: using '$wrapper' as C++ wrapper"
  cmd="$args $wrapper -L$PREFIX/lib -lccmalloc -ldl"
else
  echo "ccmalloc: no C++ wrapper for '$base' installed"
  cmd="$args -L$PREFIX/lib -lccmalloc -ldl"
fi

shift
found=no
while [ $# -gt 0 ]
do
  case $1 in
    *.o | *.c | *.cc) found=yes; break;;
    *) ;;
  esac
  shift
done

if [ $found = no ]
then
  echo "*** ccmalloc: missing source or object file" 1>&2
  exit 1
fi

echo $cmd
exec $cmd
