# -*-sh-*-
#ident	"@(#)smail:RELEASE-3_2_0_120:EDITME-netbsdpkg,v 1.42 2004/08/17 19:50:27 woods Exp"
#
# netbsdpkg -- a netbsd install under "$PREFIX" with lots of options
#
# This should also work for FreeBSD and OpenBSD, or by hand with
# $PREFIX set in the environment (which is what the pkgsrc do-build
# target does).  Note though that you'll probably want the
# "mailwrapper" program too since this package explictly does *not*
# replace sendmail directly but installs in $PREFIX/libexec/smail.
#
# First a silly little hack to make things safer and easier in my test
# environment (which is also my home network's production mail server! ;-)
#
if [ -z "$PREFIX" -a "$(domainname)" = ".weird.com" ]; then
	case "$(hostname)" in
	most)
		export PREFIX=/usr
		export USE_CYRUS_IMAPD=YES
		;;
	sometimes|starting-out|becoming)
		export PREFIX=/usr
		;;
	*)
		export PREFIX=/usr/pkg
		;;
	esac
	if [ $(uname -r) = "1.3.3" ]; then
		BUILD_OS_TYPE=bsd4.4-lite
	fi
fi
#
# And then a check to make sure the pkgsrc environment is semi-sane.
#
if [ -z "$PREFIX" ] ; then
        echo "You have not set PREFIX in the environment!!!"
        exit 2
fi
#
CC=${CC:-gcc}
# 
# these are all OK on NetBSD-1.3.2 thorugh 1.6.x
# (with only minor cast-qual warnings from old gcc (2.7.2* and older?))
# 
CWARNS=${CWARNS:-"-pedantic -W -Wall -Wshadow -Wswitch -Wreturn-type -Wpointer-arith -Wconversion -Wimplicit -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wcast-qual -Wno-format-extra-args"}
# Smail does not care about 'const' in enough places, yet....
#CWARNS="$CWARNS -Wwrite-strings
#
if ${CC} -o conftest.o -c -Wnetbsd-format-audit ${ROOT}/compat/dummy.c > /dev/null 2>&1 ; then
	# format-audit is also only on newer systems (egcs-1.x?),
	# only in the stock NetBSD compiler,
	# and only on some architectures (eg. not sparc64).
	CWARNS="$CWARNS -Wnetbsd-format-audit"
fi
rm -f conftest.o
# 
# Note that -pipe _may_ slow down small-memory systems
# 
CFLAGS="${CFLAGS:--g -O2 -pipe} $CWARNS"
LDFLAGS="${LDFLAGS:--g -O2 -pipe} -static"
#
# don't waste time searching the sysem default directories twice for
# package libident and libwhoson.
#
# XXX this still needs updating to handle pkgsrc buildlink
#
if [ "$PREFIX" != /usr ]; then
	CPPFLAGS="-I${PREFIX}/include"
	LDFLAGS="${LDFLAGS} -L${PREFIX}/lib"
fi
#
# Set BUILD_OS_TYPE in the environment for other systems.
# e.g. use BUILD_OS_TYPE=netbsd for older systems, such as 1.3.3
# or BUILD_OS_TYPE=freebsd4 for FreeBSD-4.x systems.
#
OS_TYPE=${BUILD_OS_TYPE:-netbsd1.5}
#
# pick up optional settings from pkgsrc Makefile...  (remember EDITME
# variables are unset before EDITME is read, so the ones we use from
# the environment must have different names)
#
MISC_DEFINES="$BUILD_DEFINES"
HAVE="$BUILD_HAVE"
LIBS="$BUILD_LIBS"
case "${USE_CYRUS_IMAPD}" in
[Yy][Ee][Ss]|[Yy]|1)
	MISC_DEFINES="$MISC_DEFINES:USE_CYRUS_IMAPD"
	CYRUS_USER=${SMAIL_CYRUS_USER}
	CYRUS_DELIVER_PATH=${SMAIL_CYRUS_DELIVER_PATH}
	CYRUS_NOQUOTA_PASSPHRASE=${SMAIL_CYRUS_NOQUOTA_PASSPHRASE}
	;;
esac
#
MISC_DEFINES="$MISC_DEFINES:SMAIL_LOG_STYLE=2"
MISC_DEFINES="$MISC_DEFINES:NO_FORWARDTO_FILE"
MISC_DEFINES="$MISC_DEFINES:USE_LSEARCH_REGEXCMP"
MISC_DEFINES="$MISC_DEFINES:LOG_SMTP_NON_COMPLIANCE"
MISC_DEFINES="$MISC_DEFINES:LOG_SMTP_INVALID_OPERAND_WARNING"
#
HAVE=$HAVE:EHLO
#
# This can be turned off very easily at run-time so build it in by default.
#
HAVE=$HAVE:RFC1413
LIBS="$LIBS -lident"
# 
# Smail requires PCRE
#
LIBS="$LIBS -lpcreposix -lpcre"
# 
# It would be nice to be able to force this to /etc/smail if
# PREFIX=/usr, but that cannot yet be done with NetBSD's pkg tools.
# (PLIST entries always have the value of $PREFIX added to them)
#
LIB_DIR=$PREFIX/etc/smail
# 
UTIL_BIN_DIR=$PREFIX/libexec/smail
# 
# force everything into $PREFIX/libexec/smail
# note that the pkgsrc Makefile will fix a couple things up for us...
#
SMAIL_BIN_DIR=$UTIL_BIN_DIR
# 
# Override the conf/os/bsd4.4 replacement of sendmail in /usr
# Note that the following two settings depend on having mailwrapper to
# replace sendmail.
#
NEWALIASES="$UTIL_BIN_DIR/newaliases"
OTHER_SMAIL_NAMES="$UTIL_BIN_DIR/sendmail"
# 
# set SMAIL_NAME empty to use $SMAIL_BIN_DIR/smail
# set SMAIL_NAME to an empty string to use $UTIL_BIN_DIR/smail
#
SMAIL_NAME=''
# 
# Note that the pkg_* tools will not know about these /var places, but
# that's OK because they get created at run-time....
#
SPOOL_DIRS=/var/spool/smail
TMP_DIR=/var/spool/smail/tmp
LOG_DIR=/var/log/smail
UNSHAR_MAP_DIR=/var/spool/uumaps
NEWS_SPOOL_DIR=/var/spool/news
UUWHO_FILE=/var/spool/smail/uuwho
MAN1=$PREFIX/man/man1
MAN1_EXT=1
MAN5=$PREFIX/man/man5
MAN5_EXT=5
MAN8=$PREFIX/man/man8
MAN8_EXT=8
# 
# The pkg_* tools won't know about /etc/aliases either, but we're
# simply stealing it from sendmail anyway so there's no need to
# include it in the binary package.
# 
if [ -f /etc/mail/aliases ] ; then
	ALIASES_FILE=/etc/mail/aliases
else
	ALIASES_FILE=/etc/aliases
fi
# 
# ... note we are eliminating the use of db for alias files
#
ALIASES_TYPE=lsearch
# 
REWRITE_FILE=rewrite
REWRITE_TYPE=lsearch
#
# this assumes you use the HDB UUCP style config, which is
# the only one that will work with UUCP_SYSTEM_FILE anyway...
# (and if this file does not exist "uuname" is used instead)
#
UUCP_SYSTEM_FILE=/etc/uucp/Systems
