#!/bin/sh 
#
#
#From marcs@znep.com Fri Aug 22 20:25:11 1997
#Date: Sun, 17 Aug 1997 23:12:32 -0600 (MDT)
#From: Marc Slemko <marcs@znep.com>
#Reply-To: new-httpd@apache.org
#To: TLOSAP <new-httpd@apache.org>
#Subject: binbuild.sh: script to build binary releases
#
#Pay attention now.  If you have access to build a binary on a particular
#platform, this is the easy way to do it.  Can't guarentee it will be
#right, but it will certainly make my life easier for building binary
#releases.
#
#
# $Id$
# Marc Slemko (marcs@znep.com)
#
# Script to make Apache binary releases.  The below variables must be
# set correctly, and both the tarball and the Configuration file that
# you wish to use must be present in the cwd before running the script
#

# setup to give them a warning that things didn't finish correctly
# since I am too lazy to put proper error messages everywhere
trap 'echo ERROR: abnormal exit, binary release not properly built; exit 1' 0 1 2 3 15

# release is the release of the Apache version that is being built.
# It must also be the base name of the tarball and the name of the
# directory that it is untarred into
release=apache_1.3.0
dir=$release
# conf is the Configuration file that you wish to use to build httpd
conf=Configuration
# gzcat should be set to something that will take a .tar.gz as an 
# argument and send the uncompressed .tar to stdout.  On some systems,
# it will be zcat
gzcat=gzcat
# if md5 exists, it will be used to generate a md5 hash for the
# generated files.  Full path is necessary.
md5=/sbin/md5

# ensure proper permissions
umask 022

echo untarring release tarball
$gzcat $release.tar.gz | tar xf -
if [ ! -d $release ] ; then
    echo ERROR: $release directory does not exist after untarring
    exit 1
fi
# system is the name of the system used to name both the binary and
# the generated tarballs.  GuessOS is not used because it gives 
# particularily nice names but because it is easy
system=`./$release/src/helpers/GuessOS | sed 's/\//_/g'` || exit 1

cd $dir/src || exit 1
echo running Configure
./Configure || exit 1
echo attempting to make httpd
make 2>&1 | tee ../../make.out-$system
if [ ! -f httpd ] ; then
    echo error: httpd binary not made
    exit 1
fi
echo making binaries in support
cd ./support || exit 1
# no, we don't make suexec or worry too much about errors here
# Marc is lazy.
make
cd .. || exit 1
echo make succeeded, saving the binary and doing a make clean
mv httpd httpd-$system
make clean || exit 1
cd ../.. || exit 1

echo creating tar file
tar cf - $release > $release-$system.tar || exit 1
echo creating tar.gz file
gzip -c $release-$system.tar > $release-$system.tar.gz || exit 1
echo creating tar.Z file
compress -c $release-$system.tar > $release-$system.tar.Z || exit 1

if [ ! -f $md5 ] ; then
    echo md5 not found, not generating hashes
else
    echo generating md5 hashes
    $md5 $release-$system.tar.gz > $release-$system.tar.gz.md5
    $md5 $release-$system.tar.Z > $release-$system.tar.Z.md5
fi

echo Binary build complete.  Remember to create the proper README
echo file for the build and sign it if appropriate.
trap 0 1 2 3 15

