#! /bin/sh
#
# Convenience script, to help generate SLgtk builds against latest-n-greatest
# GTK distributions w/out having to install them in the "proper" locations.
# Can be used to build both GTK, it's dependencies, and SLgtk.
#
# Requires that pkg-config be present in the experimental install tree,
# so that it can 'find' the latest experimental Glib, etcetera.

if [ x$1 = x ] ; then
   echo "Usage: `basename $0` [-nox] root_of_install_tree"
   exit
fi

if [ x$1 = x-nox ] ; then
   omit_x_includes=true
   shift
fi

PREFIX=$1

if [ -x /bin/uname ] ; then
   System=`/bin/uname`
elif [ -x /usr/bin/uname ] ; then
   System=`/usr/bin/uname`
else
   echo "Sorry, I cannot determine what kind of system you're on!"
   exit 1
fi


if [ "$System" = "SunOS" ] ; then

   # Hacks so I don't have to remember much when building on Solaris
   case `hostname` in
	bleda|dunlap|tucana)

		if [ "$CC"  = "" ] ; then
		   CC=cc
		   CXX=CC
		   CFLAGS=-xO2
		fi
	;;

	fleadh | ifr)

		OTS=/data/moca/ots

		if [ "$CC"  = "" ] ; then
		   CC=$OTS/gcc.v2.95.2.SunOS5.8/bin/gcc
		   CXX=$OTS/gcc.v2.95.2.SunOS5.8/bin/g++
		fi
	;;
    esac

   if [ x$omit_x_includes != xtrue ] ; then
	   XLIBS="--x-libraries=/usr/X/lib"
	   XINCS="--x-includes=/usr/X/include"
   fi

   CPPFLAGS="-I${PREFIX}/include $CPPFLAGS"
   LD_LIBRARY_PATH="${PREFIX}/lib:${XLIBS_LOC}:${LD_LIBRARY_PATH}"

elif [ "$System" = "Darwin" ] ; then

   #-no-cpp-precomp can be useful to avoid "errors during smart preprocessing"
   CPPFLAGS="-I${PREFIX}/include"
   LD_LIBRARY_PATH="${PREFIX}/lib"

elif [ "$System" = "OSF1" ] ; then

   CPPFLAGS="-I${PREFIX}/include -mieee $CPPFLAGS"
   LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH}"

else

   CPPFLAGS="-I${PREFIX}/include"
   LD_LIBRARY_PATH="${PREFIX}/lib:${LD_LIBRARY_PATH}"
fi

if [ -z "$PKG_CONFIG_PATH" ] ; then
   PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
fi

LDFLAGS=
for dir in `echo $LD_LIBRARY_PATH | tr ':' '\n'` ; do
    LDFLAGS="$LDFLAGS -L$dir"
done

PATH="${PREFIX}/bin:$PATH"
export CC CXX CFLAGS CPPFLAGS LDFLAGS PKG_CONFIG_PATH LD_LIBRARY_PATH PATH
./configure --prefix=$PREFIX $XINCS $XLIBS $2 $3 $4 $5 $6 $7 $8
