#!/bin/sh
#
# 	Copyright (c) 2003-2005 The SCO Group, Inc. All Rights Reserved. 
#ident	"@(#)opensrc:src/squid/squid.sh /main/uw714mp/4"
#
# This directory contains:
#
# dist/		2.5.STABLE9 distribution from http://www.squid-cache.org/.
# patches/*	Patches to be applied.
# squid.sh	Build script -- this file.
# squid.depend	Depend file.
# squid.init	/etc/init.d/script script.
# squid.desktop	Metadata file for docview.
# squid.html	Documentation dated 12-Mar-2003 from:
#		http://squid-docs.sourceforge.net/
#		       latest/zip-files/book-full-html.zip
#
#set -x
# These must get set in the UW build but we need them set here
INSTALL=/usr/ucb/install
VER=2.5.STABLE9
ROOT=/var/tmp/squid-${VER}-root
# We need GNU make.
MAKE=/usr/gnu/bin/make
export MAKE
[ ! -x $MAKE ] && {
	error "ERROR: $MAKE not found" >&2
	exit 1
}
# Set auth schemes and helpers.
#case "$PROJECT" in
#uw711* | uw713*)
#	PAM=
#	;;
#uw714*)
#	PAM="PAM"
#	;;
#*)
#        echo "ERROR: project $PROJECT not known" >&2
#        exit 1 ;;
#esac
# Auth schemes.
PAM=
AUTH="basic ntlm digest"
# Basic auth helpers.  We are excluding LDAP and SASL.
BASIC_AUTH_HELPERS="LDAP MSNT NCSA $PAM SMB YP getpwnam multi-domain-NTLM winbind"
CFLAGS='-O2 -Xa -Dasm=__asm -DANSICPP'
LDFLAGS=' '
CC="cc -Kthread -Kalloca"
export CFLAGS LDFLAGS CC
#set -e
# Extract source
SOURCE=squid-${VER}
cd dist
bzcat $SOURCE.tar.bz2 | tar xf -
# Apply patches.
cd $SOURCE
for patch in ${VER}-port ${VER}-dns_assert
do
        [ -f ../patches/${patch}.applied ] || {
            [ -f ../patches/${patch}.patch ] && {
                echo "Applying Patch ${patch}.patch"
                /bin/patch -c -p1 -i ../patches/${patch}.patch
                /bin/date > ../patches/${patch}.applied
            }
        }
done
for patch in squid-${VER}-uw squid-${VER}-getspnam
do
    [ -f ../patches/${patch}.applied ] || {
      [ -f ../patches/${patch}.patch ] && {
        echo "Applying Patch ${patch}.patch"
        /usr/gnu/bin/patch -p0 -b -i ../patches/${patch}.patch
        /bin/date > ../patches/${patch}.applied
      }
    }
done
# Configure and build in a separate work directory.
cd ../..
rm -rf work
/bin/mkdir -p work
cd work
#
# Note:
# Do not use --with-samba-sources option to point to samba-3.0.10.
#
../dist/$SOURCE/configure \
	--cache-file=/dev/null \
	--host=i686-sco-sysv5 \
	--build=i686-sco-sysv5 \
	--prefix=/usr \
	--libexecdir=/usr/bin \
	--datadir=/usr/share/squid \
	--sysconfdir=/etc/squid \
	--localstatedir=/var/squid \
	--enable-gnuregex \
	--enable-carp \
	--with-pthreads \
	--with-dl \
	--enable-removal-policies \
	--enable-icmp \
	--enable-delay-pools \
	--enable-useragent-log \
	--enable-referer-log \
	--enable-kill-parent-hack \
	--enable-snmp \
	--disable-apr-acl \
	--enable-htcp \
	--enable-ssl \
	--enable-cache-digests \
	--enable-poll \
	--enable-auth="$AUTH" \
	--enable-basic-auth-helpers="$BASIC_AUTH_HELPERS" \
	--enable-ntlm-auth-helpers \
	--enable-digest-auth-helpers \
	--enable-external-acl-helpers="ip_user ldap_group unix_group"

# Make and install.
$MAKE DESTDIR=$ROOT/$MACH install

cd ../dist/$SOURCE

# Install copyright files.
$INSTALL -d $ROOT/$MACH/usr/share/squid
$INSTALL -m 0444 COPYING COPYRIGHT $ROOT/$MACH/usr/share/squid

cd ..

# Install /etc/init.d script.
$INSTALL -d $ROOT/$MACH/etc/init.d
$INSTALL -m 0444 squid.init $ROOT/$MACH/etc/init.d/squid

# Install documentation.
DOCDIR=/usr/share/squid/doc
$INSTALL -d $ROOT/$MACH/$DOCDIR
$INSTALL -m 0444 squid.html $ROOT/$MACH/$DOCDIR/squid.html
mkdir FAQ
cd FAQ
tar xjvf ../squid-FAQ.tar.bz2 FAQ/FAQ.txt FAQ/FAQ.ps.gz
mv FAQ/* .
rmdir FAQ
gzip -d FAQ.ps.gz
bzip2 -9 FAQ.ps FAQ.txt
cd ..

# Install docview glue.
INTGroup=/usr/share/meta/doc/HelpTopics/INThome/INTgroup
$INSTALL -d $ROOT/$MACH/$INTGroup
$INSTALL -m 0444 squid.desktop $ROOT/$MACH/$INTGroup/SquidDoc.desktop

exit 0
