#!/bin/sh
#
# $Id: ldap-setup,v 1.7 1998/07/09 00:25:37 hubert Exp $
#
#            T H E    P I N E    M A I L   S Y S T E M
#
#   Laurence Lundblade and Mike Seibel
#   Networks and Distributed Computing
#   Computing and Communications
#   University of Washington
#   Administration Building, AG-44
#   Seattle, Washington, 98195, USA
#   Internet: lgl@CAC.Washington.EDU
#             mikes@CAC.Washington.EDU
#
#   Please address all bugs and comments to "pine-bugs@cac.washington.edu"
#
#
#   Pine and Pico are registered trademarks of the University of Washington.
#   No commercial use of these trademarks may be made without prior written
#   permission of the University of Washington.
#
#   Pine, Pico, and Pilot software and its included text are Copyright
#   1989-1998 by the University of Washington.
#
#   The full text of our legal notices is contained in the file called
#   CPYRIGHT, included with this distribution.
#
#
#   Pine is in part based on The Elm Mail System:
#    ***********************************************************************
#    *  The Elm Mail System  -  Revision: 2.13                             *
#    *                                                                     *
#    * 			Copyright (c) 1986, 1987 Dave Taylor               *
#    * 			Copyright (c) 1988, 1989 USENET Community Trust    *
#    ***********************************************************************
# 
#


#
#  Helper script for setting up LDAP
#
# Put a symlink called "ldap" to the University of Michigan LDAP source
# (ldap-3.3) in the top-level pine directory, where the pine build script
# is located. This script is called by the "build" script in that same
# top-level directory. It probably won't help much to run this script
# standalone. The script just checks to make sure things appear to be set
# up the way pine expects them and gives a small amount of advice if
# things aren't that way. This is designed with the ldap-3.3 directory
# structure in mind.
#

exitval=0
ptarget=xxx
btarget=xxx
if [ $# != "2" ]
then
    echo "Usage: contrib/ldap-setup pinetarget buildtarget"
    exit 1
fi

ptarget=$1
btarget=$2

if [ ! -d ldap ]
then
    exitval=1
elif [ ! -d ldap/libraries ]
then
    echo "Ldap-setup: Expected directory \"ldap/libraries\" is missing."
    exitval=1
fi


if [ -f ldap/libraries/liblber.a -a -f ldap/libraries/libldap.a ]
then
    exit 0
fi

if [ $exitval -eq 1 ]
then
    echo "If you are attempting to use an LDAP library other than ldap-3.3"
    echo "from the Univ of Michigan then the pine build script won't be able"
    echo "to help much. Instead, you will have to modify pine/makefile.$ptarget"
    echo "and set LDAPLIBS and LDAPCFLAGS correctly."
    echo "In order to build pine without LDAP functionality you may rename or"
    echo "remove the directory \"ldap\" and run the pine \"build $btarget\" command again."
    exit 1
fi

#
# Not all of these have been tried.
#
ldaptarget=unknown
case "$ptarget"
in
    a32) ldaptarget=aix-cc ;;
    a41) ldaptarget=aix-cc ;;
    bsf) ldaptarget=freebsd-gcc ;;
    gh9) ldaptarget=hpux-gcc ;;
    ghp) ldaptarget=hpux-gcc ;;
    gs4) ldaptarget=sunos5-gcc ;;
    gs5) ldaptarget=sunos5-gcc ;;
    gsu) ldaptarget=sunos4-gcc ;;
    gul) ldaptarget=ultrix-gcc ;;
    hpp) ldaptarget=hpux-cc ;;
    hpx) ldaptarget=hpux-cc ;;
    hxd) ldaptarget=hpux-cc ;;
    lnx) ldaptarget=linux-gcc ;;
    neb) ldaptarget=netbsd-cc ;;
    nxt) ldaptarget=nextstep-cc ;;
    os4) ldaptarget=osf1-cc ;;
    osf) ldaptarget=osf1-cc ;;
    s40) ldaptarget=sunos4-cc ;;
    sc5) ldaptarget=sco-cc ;;
    sco) ldaptarget=sco-cc ;;
    sgi) ldaptarget=irix-cc ;;
    shp) ldaptarget=hpux-cc ;;
    slx) ldaptarget=linux-gcc ;;
    sl5) ldaptarget=linux-gcc ;;
    so4) ldaptarget=sunos5-cc ;;
    so5) ldaptarget=sunos5-cc ;;
    sos) ldaptarget=osf1-cc ;;
    ssn) ldaptarget=sunos4-cc ;;
    sun) ldaptarget=sunos4-cc ;;
    sv4) ldaptarget=ncr-mp-ras-2-cc ;;
    ult) ldaptarget=ultrix-cc ;;
esac

if [ ! -f ldap/libraries/liblber.a -a ! -f ldap/libraries/libldap.a ]
then
    echo "The LDAP libraries \"ldap/libraries/liblber.a\" and"
    echo "\"ldap/libraries/libldap.a\" don't appear to be built yet."
elif [ ! -f ldap/libraries/liblber.a ]
then
    echo "The LDAP library \"ldap/libraries/liblber.a\""
    echo "doesn't appear to be built yet."
else
    echo "The LDAP library \"ldap/libraries/libldap.a\""
    echo "doesn't appear to be built yet."
fi

if [ "$ldaptarget" = unknown ]
then
    echo "Can't figure out which LDAP port to use for pine target \"$ptarget\"."
    echo "If you are able to figure out the target the following cmds may work."
    ldaptarget='<target_name>'
else
    echo "The following commands may work for you."
fi

echo "Be sure you are working on a copy of the LDAP source before trying this."
echo ""
echo "  cd ldap/build/platforms/$ldaptarget"
echo "  make platform"
echo "  make"
echo ""
echo "After you've successfully built the libraries \"liblber.a\" and"
echo "\"libldap.a\" you may try the \"build $btarget\" command again."
echo ""
echo "Only those two libraries are used by pine. The rest of the ldap make"
echo "doesn't have to succeed for pine to build successfully."
echo "In order to build pine without LDAP functionality you may rename or"
echo "remove the directory \"ldap\" and run the \"build $btarget\" command again."

exit 1
