#!/bin/sh
#
# link an ET++ application
#

PATH=/bin:/usr/bin:/local/bin
ET_DIR=${ET_DIR-/local/ET++}               # location of ET++

#---- configuration -------------------------------------------

#STATIC_OPT="-Bstatic -L${ET_DIR}/lib"      # for 4.0 (EXPORT)
STATIC_OPT="-Bstatic"                       # for 4.0 or 4.0.1       
MUNCH="/local/lib/munch"                    # location of munch
#LIBS="-lm -lC"                             # required libs
LIBS="-lsuntool -lsunwindow -lpixrect -lm -lC"
					    # libs for 4.0 and above when
					    # shared window libraries are used

#---- initialization ------------------------------------------

WHAT="et"
STATIC=
OUTPUT="a.out"
OFILES=
ETSRC=${ET_DIR}/src

while [ "$1" != "" ]
do
    case "$1" in
    -et)    WHAT="et"
	    ;;
    -col)   WHAT="col"
	    ;;
    -static) STATIC=$STATIC_OPT
	    ;;
    -o)     OUTPUT="$2"
	    shift
	    ;;
    -*)     LDFLAGS="$LDFLAGS $1"
	    ;;
    *.o)    OFILES="$OFILES $1"
	    ;;
    *)      echo "$0: unknown argument $1" 1>&2
	    exit 1
	    ;;
    esac
    shift
done

(nm -p $OFILES; cat $ETSRC/$WHAT.ctdt) | $MUNCH > /tmp/etld$$.c
cc -c /tmp/etld$$.c
cc $LDFLAGS -o $OUTPUT $STATIC $OFILES $ETSRC/$WHAT.o etld$$.o $LIBS
rm /tmp/etld$$.c etld$$.o

