#!/bin/sh
#
# $Id: build,v 4.29 1996/05/14 19:22:13 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-1996 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    *
#    ***********************************************************************
# 
#


#
#  General build script for Pine
#

cat > .bld.hlp <<EOF
Usage: build <make-options> <target-platform>

<target-platform> may be one of the following:
    ult   Works on DECStations with Ultrix 4.1 or 4.2
    nxt   Works on NeXT 68030's and 68040's running Next Mach 2.0     
    sun   Works on SPARCs running SunOS 4.1
    ptx   Works on Sequent Symmetry running Dynix/PTX
    a32   Works on IBM RS/6000 running AIX 3.2
    ...   Others are available, see doc/pine-ports
  clean   Clean up object files and such.
          Also, a good way to rebuild Pine/Pico from scratch.

See the document doc/pine-ports for a list of other platforms that
Pine has been ported to and for details about these and other ports.

<make-options> are generally not needed. They are flags (anything
beginning with -) and are passed to make. "-n" is probably the most
useful, as it tells make to just print out what it is going to do and
not actually do it.

To build Pine and Pico the command "build xxx" should work where xxx
is one of the targets. For example "build ult" to build Pine for Ultrix.


The executables built by this are:

 pine   The Pine mailer. Once compiled this should work just fine on
        your system with no other files than this binary, and no
        modifications to your system. Optionally you may create two
        configuration files, /usr/local/lib/pine.conf and 
        /usr/local/lib/pine.info. See the documentation for details.
 
 pico   The standalone editor similar to the Pine message composer.
        This is a very simple straight forward text editor.
 
 pilot  The standalone file system navigator.
 
 imapd  The IMAP daemon. If you want to run Pine in client/server mode,
        this is the daemon to run on the server. Installing this
        requires system privileges and modifications to /etc/services.
        See doc/tech-notes for more details.
 
 mtest  The test IMAP client, an absolutely minimal mail client, useful
        for debugging.

In general you should be able to just copy the Pine and Pico binaries
to the place you keep your other local binaries. /usr/local/bin is a
likely place.
  
EOF
                 

maketarget="no-target"
makeargs=""
PHOME=`pwd`

args=$#
while [ $args -gt 0 ]
do
  case $1 in
 
    help) cat .bld.hlp
          exit ;;

    -*) makeargs="$makeargs $1" ;;

    clean|???)
         if [ $maketarget != no-target ]
         then
             echo "Can only make one target system at a time"
             echo 'Both "$maketarget" and "$1" were given'
             exit
         else
             maketarget=$1
         fi
       ;;

      
    *) makeargs="$makeargs $1" ;;

  esac
  
  shift
  
  args=`expr $args - 1`

done

case $maketarget in
   gul) makeargs="CC=gcc $makeargs" ;;
   gso) makeargs="CC=gcc $makeargs" ;;
   gas) makeargs="CC=gcc $makeargs" ;;
   gsu) makeargs="CC=gcc $makeargs" ;;
   lyn) [ -f /CYGNUS.bash ] && . /CYGNUS.bash; makeargs="CC=gcc $makeargs" ;;
     *) makeargs="CC=cc $makeargs" ;;
esac

echo 'make args are "'$makeargs'"'

case $maketarget in

   ???) 
        echo ''
        cd $PHOME
        if [ -s c-client ] ; then rm -f c-client ; fi
        if [ -s imapd    ] ; then rm -f imapd    ; fi
        ln -s imap/systype/c-client c-client
        ln -s imap/systype/imapd imapd
        echo "Making c-client library, mtest and imapd"
        cd $PHOME/imap
        make $makeargs $maketarget
        echo ''
        echo "Making Pico and Pilot"
        cd $PHOME/pico
        make $makeargs -f makefile.$maketarget
        echo ''
        echo "Making Pine".
        cd $PHOME/pine
        make $makeargs -f makefile.$maketarget
        cd $PHOME
        if [ ! -d bin ] ;  then    mkdir bin;        fi
        cd $PHOME/bin
        rm -f pine mtest imapd pico pilot
        if [ -s ../pine/pine ] ;      then ln ../pine/pine  pine      ; fi
        if [ -s ../c-client/mtest ] ; then ln ../c-client/mtest mtest ; fi
        if [ -s ../imapd/imapd ] ;    then ln ../imapd/imapd imapd    ; fi
        if [ -s ../pico/pico ] ;      then ln ../pico/pico pico ; fi
        if [ -s ../pico/pilot ] ;     then ln ../pico/pilot pilot ; fi
        cd $PHOME
        echo ''
        echo "Links to executables are in bin directory:"
        size bin/pine bin/mtest bin/imapd bin/pico bin/pilot
        echo "Done"
        ;;


    clean) # This only sort of works 
        echo "Cleaning c-client and imapd"
	cd $PHOME/imap
	make clean
        echo "Cleaning Pine"
        cd $PHOME/pine
        make -f makefile.ult clean
        echo "Cleaning pico"
        cd $PHOME/pico
        make $makeargs -f makefile.ult clean
        echo "Done"
        cd $PHOME
        ;;

    no-target)
        echo "No target plaform for which to build Pine given."
        echo 'Give command "build help" for help.'
        ;;

    *)  echo 'Do not know how to make Pine for target "'$maketarget'".'
        ;;
esac
