#! /bin/ksh
# Script to configure Apache as distributed by SCO.
#
# Prerequisites: OpenSSL, MM installed (i.e. gwxlibs package)
#                mod_ssl configured
#
# mod_ssl has an OSDBUILD script too. Use it. All other modules are
# configured post-apache compilation (and most probably installtion)
# using APXS.
#
[ $# -eq 1 ] || {
  echo "Usage: OSR5BUILD /path/to/xenv"
  exit 1
}

[ "$1" != "/" -a -d $1 ] || {
  echo "ERROR: $1 does not exist"
  exit 1
}

[ "$1" != "/" ] && {
  [ -d "$1/bin" ] || mkdir -p $1/bin
  sed -e "s,@OSDPFX@,$1," osdapxs.in > $1/bin/osdapxs
  sed -e "s,@OSDPFX@,$1," osdapxsinc.in > $1/bin/osdapxsinc
  chmod 755 $1/bin/osdapxs $1/bin/osdapxsinc
}

shift

: ${GWXCC:='gcc -L/usr/gnu/lib'}
: ${GWXCXX:='g++ -L/usr/gnu/lib'}
: ${GWXCFLAGS:="-O6 -fomit-frame-pointer -mcpu=i586 -march=i586"}
: ${GWXCXXFLAGS:="-O6 -fomit-frame-pointer -mcpu=i586 -march=i586"}
: ${GWXSHELL:=/usr/bin/bash}
GWXCFLAGS="$GWXCFLAGS -D_REENTRANT -DFD_SETSIZE=11000"
GWXCXXFLAGS="$GWXCXXFLAGS -D_REENTRANT -DFD_SETSIZE=11000"
SHELL="${GWXSHELL}" CONFIG_SHELL="${GWXSHELL}" CC="${GWXCC}" CXX="${GWXCXX}" \
CFLAGS="${GWXCFLAGS}" CXXFLAGS="${GWXCXXFLAGS}" \
LIBS="-ljdbm -lgdbm -ldb -lmm -lsocket" \
SSL_BASE=SYSTEM EAPI_MM=SYSTEM \
${GWXSHELL} ./configure \
  --with-layout=Apache \
  --prefix=/usr/lib/apache \
  --enable-module=all \
  --disable-module=example \
  --enable-shared=max \
  --enable-shared=ssl \
  --server-uid=nouser \
  --server-gid=nogroup \
  --with-port=80 \
  --enable-suexec \
  --suexec-caller=nouser \
  --suexec-docroot=/usr/lib/apache/htdocs \
  --suexec-logfile=/usr/lib/apache/logs/suexec_log \
  --suexec-safepath="/bin:/usr/bin:/usr/gnu/bin" \
  --mandir=/usr/man \
  --manualdir=/usr/lib/apache/manual \
  --enable-rule=EAPI \
  --enable-rule=SSL_SDBM \
  --disable-rule=SSL_COMPAT "$@" || exit 1

echo "OSD: changing conf/httpd.conf to conf/cf.d"
sed -e 's,conf/httpd.conf,conf/cf.d,g' src/apaci > foo
mv foo src/apaci
chmod +x src/apaci
