#!/bin/sh
#
# $Id: ldap-setup,v 1.10 1999/01/25 20:07:54 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
#
# Pine has been successfully compiled with the University of Michigan
# LDAP source (ldap-3.3) and with the Netscape Directory SDK 1.0.
#
# The setup for use with the Univ. of Michigan source is as follows.
# 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. The script you are reading is called by the "build" script
# in that same top-level directory. If you haven't previously compiled the
# LDAP library this ldap-setup script may be able to give you a small amount
# of help in the form of a hint. Try setting up the symlink to the source
# and then type the "build <target>" command. The script will try to figure
# out the command you need to use to compile the LDAP library.
#
# The setup for use with the Netscape SDK is as follows. Make a directory
# called ldap in the same place where the "build" script is located.
# That directory should have subdirs "libraries" and "include". "Include"
# is where ldap.h and friends from the Netscape SDK should go, and "libraries"
# should contain libldap.a.
#
# And there is also the SDK from mozilla.org. It is based on the Netscape
# SDK but for some reason has reverted to the Michigan style of having
# two separate libraries. The setup for mozilla is the same as for
# the Netscape SDK with ldap/include and ldap/libraries. This script will
# look for liblber.a and exit with return value 1 if it finds it.
#
# And there is also OpenLDAP. As of version 1.0, it looks just like the
# Michigan setup so no changes here for it. Set it up just like you
# would set up umich.
#
# The build script is looking for an exit value of either 1 or 2 from this
# script. 1 means this is a UMICH-style setup (with liblber.a) and 2 means
# there is no liblber.a, just libldap.a. Anything else is an error. This
# script won't be called unless there is an ldap directory next to build.
#

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

ptarget=$1
btarget=$2

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


# Figure out if this is the Umich ldap-3.3 tree or something else, like
# the Netscape SDK. Style 1 is umich, style 2 is Netscape SDK, style 3 is
# mozilla.org.
style=2
if [ $exitval -eq 0 -a -d ldap/libraries/liblber ]
then
    style=1
fi

if [ $exitval -eq 0 -a \( $style -eq 2 -a -f ldap/libraries/liblber.a -a -f ldap/libraries/libldap.a \) ]
then
    style=3
fi

# This is a successful exit. The value of style tells build whether to include
# the liblber.a library or not.
if [ $exitval -eq 0 -a \( \( $style -eq 1 -a -f ldap/libraries/liblber.a -a -f ldap/libraries/libldap.a \) -o \( $style -eq 2 -a -f ldap/libraries/libldap.a \) -o \( $style -eq 3 \) \) ]
then
    if [ $style -eq 3 ]
    then
      exit 1
    fi

    exit $style
fi

if [ $exitval -eq 5 ]
then
    echo "Read the file contrib/ldap-setup for some help in setting"
    echo "up LDAP."
    exit 5
fi

if [ $style -eq 1 ]
then
#
# 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."

else

# Come here if style is 2, which means we're trying to use the non-UMICH
# setup which doesn't include a liblber.a.
if [ ! -f ldap/libraries/libldap.a ]
then
    echo "The LDAP library \"ldap/libraries/libldap.a\""
    echo "is missing."
fi

fi
exit 5
