#!/bin/sh
##
# Copyright 2000 Thomas "temas" Muldowney and The Jabber Team
#   Feel free to take parts of this and use it.  It's a quicky
#   so who knows if it's any good at all.  I'm not a super duper
#   shell hacker.
##
# THINGS I'VE LEARNED:
#   1)  echo is yucky, use printf
#   2)  test is cool, learn the XP version though
##
# You only need to run this once to setup your platforms options
##
printf "Running Jabber Configure\n"
printf "========================\n\n"

##
# Libxode check
##
printf "Getting libxode settings..."
XODE_CFLAGS=`libxode-config --cflags`
XODE_LDFLAGS=`libxode-config --ldflags`
XODE_LIBS=`libxode-config --libs`
if [ -n "$XODE_CFLAGS" ]; then
    printf "     Done.\n";
else
    printf "You are missing libxode-config.  This is obtained from the libxode package that can be found at http://download.jabber.org.  Please installed this package and then run configure again.\n";
    exit 1;
fi

##
# Libjabber check
##
printf "Getting libjabber settings..."
JABBER_CFLAGS=`jabber-config --cflags`
JABBER_LDFLAGS=`jabber-config --ldflags`
JABBER_LIBS=`jabber-config --libs`
if [ -n "$JABBER_CFLAGS" ]; then
    printf "   Done.\n";
else
    printf "You are missing jabber-config.  This is obtained from the libjabber package that can be found at http://download.jabber.org.  Please installed this package and then run configure again.\n";
    exit 1;
fi

##
# Pth check
##
printf "Getting pth settings..."
PTH_CFLAGS=`pth-config --cflags`
PTH_LDFLAGS=`pth-config --ldflags`
PTH_LIBS=`pth-config --libs`
if [ -n "$PTH_CFLAGS" ]; then
    printf "         Done.\n";
else
    printf "You are missing pth-config.  This is obtained from the pth package that can be found at http://www.gnu.org.  Please install this package and then run configure again.\n";
    exit 1;
fi

##
# Setup our initial flags
##
CFLAGS="-g -Wall -fPIC -I./ -I../ $XODE_CFLAGS $JABBER_CFLAGS $PTH_CFLAGS"
MCFLAGS="-shared"
LDFLAGS="$XODE_LDFLAGS $JABBER_LDFLAGS $PTH_LDFLAGS"
LIBS="$XODE_LIBS $JABBER_LIBS $PTH_LIBS"
XLDFLAGS=""

##
# Check the host type and change flags as necessary
##
printf "Setting Build Parameters..."
hosttype=`uname -s`
case $hosttype in
    Linux)
        CFLAGS="$CFLAGS"
        LIBS="$LIBS -ldl -lresolv"
        XLDFLAGS="$XLDFLAGS -Wl,--export-dynamic";;
    SunOS)
        LDTEST=`gcc -Wl,-V 2>&1 | grep GNU`
        if [ -n "$LDTEST" ]; then
            XLDFLAGS="$XLDFLAGS -Wl,-export-dynamic"
        fi
        CFLAGS="$CFLAGS"
        LIBS="$LIBS -ldl -lsocket -lnsl -lresolv";;
esac
printf "     Done.\n"
##
# Output our settings for usage
##
printf "Generating Settings Script..."
cat << EOF > platform-settings
#!/bin/sh
CFLAGS=$CFLAGS
MCFLAGS=$MCFLAGS
LDFLAGS=$LDFLAGS
LIBS=$LIBS
XLDFLAGS=$XLDFLAGS
EOF
chmod 0700 platform-settings
printf "   Done.\n\n"
printf "You may now type 'make' to build your new Jabber system.\n\n"
