#! /bin/sh
# $Id: ins_mak,v 12.5 2010/07/04 12:55:34 tom Exp $
#
# Install the td_lib make include-file.  We adjust the symbols that refer
# to the location of the include- and lib-directory.

if test $# = 0 ; then
	echo '? No INSTALL program given'
	exit 1
fi
PRG="$1"
shift

if test $# = 0 ; then
	echo '? No DESTDIR given'
	exit 1
fi
DESTDIR=$1
shift

if test $# = 0 ; then
	echo '? No DATADIR given'
	exit 1
fi
CFGDIR=$1
my_CFG=$1
test -n "$DESTDIR" && my_CFG=`echo "$CFGDIR" | sed -e "s,$DESTDIR,,"`
shift

if test $# = 0 ; then
	echo '? No LIBDIR given'
	exit 1
fi
LIBDIR=$1
my_LIB=$1
test -n "$DESTDIR" && my_LIB=`echo "$LIBDIR" | sed -e "s,$DESTDIR,,"`
shift

if test $# = 0 ; then
	echo '? No INCLUDEDIR given'
	exit 1
fi
INCDIR=$1
my_INC=$1
test -n "$DESTDIR" && my_INC=`echo "$INCDIR" | sed -e "s,$DESTDIR,,"`
shift

if test $# = 0 ; then
	echo '? No SOURCE given'
	exit 1
fi

SED=${TMPDIR-/tmp}/sed$$
trap "rm -f $SED" 0 1 2 5 15

cat >$SED <<EOF
s@^TD_LIB[ 	]*=.*@TD_LIB = $my_LIB@
s@^TD_INC[ 	]*=.*@TD_INC = $my_INC@
EOF

for SRC in $*
do
	src=`basename $SRC`
	TMP=${TMPDIR-/tmp}/$src
	sed -f $SED $SRC > $TMP
	eval $PRG $TMP $CFGDIR
	rm -f $TMP
done
