#
# Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# 3. The name "Carnegie Mellon University" must not be used to
#    endorse or promote products derived from this software without
#    prior written permission. For permission or any legal
#    details, please contact
#      Carnegie Mellon University
#      Center for Technology Transfer and Enterprise Creation
#      4615 Forbes Avenue
#      Suite 302
#      Pittsburgh, PA  15213
#      (412) 268-7393, fax: (412) 268-7395
#      innovation@andrew.cmu.edu
#
# 4. Redistributions of any form whatsoever must retain the following
#    acknowledgment:
#    "This product includes software developed by Computing Services
#     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
#
# CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
# FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# $Id: SMakefile,v 1.101 2010/01/06 17:01:26 murch Exp $

NEW_AUTOTOOLS=yes
export NEW_AUTOTOOLS

if test ! -x configure; then
# -nt deeply upsets normal sh.
#        -o configure.in -nt configure
#        -o acconfig.h -nt configure -o SMakefile -nt configure; then
  echo aclocal -I cmulocal
  aclocal -I cmulocal
  echo autoheader
  autoheader
  echo autoconf
  autoconf
fi

MAKE=gmake

if [ -r /.hostname ]; then
  # probably an andrew machine
  VER=`smake -D | sed 's;^.*\/;;'`
else
  # anonymous cvs?
  VER="anoncvs"
fi
LOCALDEFS="-DEXTRA_IDENT=\\\"$VER\\\""

# PERL CONFIGURATION
if perl -e 'exit ($] != 5.006001)'; then
   PERL_MM_OPT="INSTALLPRIVLIB=${DESTDIR}/usr/local/lib/perl5 INSTALLARCHLIB=${DESTDIR}/usr/local/lib/perl5/5.6.1 INSTALLSITELIB=${DESTDIR}/usr/local/lib/perl5/site_perl/5.6.1 INSTALLSITEARCH=${DESTDIR}/usr/local/lib/perl5/site_perl/5.6.1 INSTALLBIN=${DESTDIR}/usr/local/bin INSTALLSCRIPT=${DESTDIR}/usr/local/bin INSTALLMAN1DIR=${DESTDIR}/usr/local/man/man1 INSTALLMAN3DIR=${DESTDIR}/usr/local/man/man3"
else
  if perl -e 'exit ($] < 5.008005)'; then
    # MakeMaker now supports DESTDIR!
    PERL_MM_OPT=""
  else
    echo "no support for thus perl version in SMakefile"
  fi
fi
export PERL_MM_OPT
# end perl configuration

# Let's just assume we are using gcc...
if test "${WASH_CYRUS_INSURE}" = "t"; then
  CC="insure"
  CFLAGS="-g"
else
  CC="gcc"
  CFLAGS="${CFLAGS} -g -Wall -W"
fi

if test "${WASH_CYRUS_DEBUG}" = "t"; then
    CC="gcc"
    CFLAGS="-g"
    LDFLAGS="${LDFLAGS}"
    DEBUG="--enable-debug"
fi

case `uname` in	
    Linux) 
	LDFLAGS="${LDFLAGS}"
	LIBS="-lnsl" # for libwrap
    ;;
    SunOS)
        LDFLAGS="${LDFLAGS} -L/usr/local/lib -Wl,-R,/usr/local/lib"
	LIBS="-lkstat -ldoor"
    ;;
    *)
        CC=cc
    ;;
esac

case `sys` in
    i386_fc3)
	LIBS="$LIBS -ldes"
	OS_CONFIG="--with-krbdes"
    ;;
    sun4x_s10)
	LIBS="$LIBS -ldes"
	OS_CONFIG="--with-krbdes"
    ;; 
esac


# settings; we have to disable these on some platforms
DEBUG=""
WITHAUTH="--with-auth=pts --with-afs=/usr/local --enable-krb5afspts --without-krbdes"
SSL_CONFIG="--with-openssl=/usr/local/lib"

# the defaults are good enough for us
DB_CONFIG="" 

# the following is for staticly linking SASL only
SASL_CONFIG="--with-staticsasl=/usr/local --with-gssapi=/usr/local"
#KRB_CONFIG="--enable-statickrb --with-krb=/usr/local"
KRB_CONFIG="--with-krb=/usr/local"
FEATURE_CONFIG="--enable-murder --enable-cmulocal --enable-nntp --enable-idled --enable-replication"
EXT_PACKAGE_CONFIG="--with-inn=/usr/news --with-ucdsnmp=/usr/local"

MFCOMMAND="./configure $WITHAUTH $KRB_CONFIG $DB_CONFIG --enable-experiment --with-cyrus-group=staff $FEATURE_CONFIG $EXT_PACKAGE_CONFIG $SASL_CONFIG $DEBUG"

export CFLAGS CC VER LNCOMMAND LOCALDEFS LDFLAGS
export LIBS
