#!/bin/sh

args=
outfile=
ofiles=

die () {
  echo $1
  exit 1
}

while test $# -gt 0; do
  case $1 in
  -o)
    shift
    test $# -gt 0 || die "missing arg for -o"
    outfile=$1
    ;;
  *.o|*.o0)
    ofiles="$ofiles $1"
    args="$args $1"
    ;;
  *)
    args="$args $1"
    ;;
  esac
  shift
done

test X"$ofiles" != X || die "no input files"
test X"$outfile" != X || die "no output file"

outfile=`echo $outfile | sed -e 's/\.o$//'`.so

# PICFLAGS are important for collect2

ldcmd="gcc -shared -fPIC  -rdynamic -L/usr/local/lib -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -lglib -lXext -lX11 -lm -o $outfile \
 $args" # -lreadline -lncurses -ltermcap -lfl -ldl -lbsd -lnsl -lm 

echo $ldcmd
eval $ldcmd
ex=$?
test $ex = 0 || exit $ex
# for HP-UX
chmod 555 $outfile
