#! /bin/sh

SRCDIR=/mit/crypto/src/gnupg-1.0.0
PACKAGE=gnupg-1.0.0

# grr, DSTDIR must be SRCDIR
echo "set DSTDIR=SRCDIR"
exit 254

#set the build dir (DSTDIR) to /var/tmp, unless we're on akom
HOST=`hostname`
if [ $HOST = "a-kind-of-magic" ]; then
    DSTDIR=/mit/crypto/build.tmp/${USER}/builds/${PACKAGE}
    rm -rf $DSTDIR
    mkdir /mit/crypto/build.tmp/${USER}
    mkdir /mit/crypto/build.tmp/${USER}/builds
    mkdir /mit/crypto/build.tmp/${USER}/builds/${PACKAGE}
    cd ${DSTDIR}
    PATH=/afs/sipb/project/gnu/arch/vax_bsd43/bin/:${PATH}
else

    DSTDIR=/var/tmp/${USER}/builds/${PACKAGE}

    # check for SRCDIR
    if [ ! -d ${SRCDIR} ]; then
	    echo "Couldn\'t access ${SRCDIR}"
	    exit 255
    fi


    # make sure dstdir is new
    if [ -d ${DSTDIR} ]; then 
    echo "${DSTDIR} already exists, moving"
	rm -rf ${DSTDIR}.old >> /dev/null
	mv ${DSTDIR} ${DSTDIR}.old
	#exit 255
    fi

    # prepare to configure
    mkdir -p ${DSTDIR} 
    cd ${DSTDIR}
    #rm -f config.cache

fi

MACHTYPE=`machtype`


# set varibles that are static for all platforms
WISH=/afs/sipb.mit.edu/project/tcl/wish

# setup the command line flags
OPTS="$OPTS --prefix=/mit/crypto"
OPTS="$OPTS --exec-prefix=/mit/crypto/arch/${ATHENA_SYS}"
OPTS="$OPTS --with-etcdir=/mit/crypto/etc"

# use none since we'll build rndunix and load it as a module
OPTS="$OPTS --enable-static-rnd=none"

# we seem to have problems finding libintl. fix...
OPTS="$OPTS --disable-nls"

# hrm
#OPTS="$OPTS --export-dynamic"

# do platform specific stuff
if [ ${MACHTYPE} = "sgi" ]; then
    CC=cc
    #OPTS="$OPTS --disable-asm"
fi


attach gnu
PATH=${PATH}:`athdir /mit/gnu gbin`

pwd
echo ${SRCDIR}/configure $OPTS

# run the configure
${SRCDIR}/configure $OPTS


#post configure stuff                
#if [ ${MACHTYPE} = "sgi" ]; then
#    find ./ -type f -exec perl -pi.bak -e 's/n32/o32/g' {} \;
#fi

# fix the make install permissions
#find ./ -type f -name Makefile -exec perl -pi.bak -e 's/\-o root//g' {} \;


# and now build!
gmake 

