#!/bin/sh
# Name: mkbindist
# Project: Sharity
# Author: Christian Starkjohann <cs@obdev.at>
# Creation Date: 1999-05-31
# Tabsize: 4
# Copyright: (c) 1999 by Christian Starkjohann, all rights reserved.
#     For details of the license see the file doc/License.txt.
# This Revision: $Id: mkbindist,v 1.8 2001/06/16 19:36:40 cs Exp $

# General Description:
# This script generates the binary distribution package.

PATH=$PATH:/etc:/usr/ucb     # extend search path

archspec="$1"

if [ -z "$archspec" ]; then
cat <<EOF
-----------------------------------------------------------------------
You have not specified your architecture as the first parameter. You'll
therefore be asked for an architecture description now. The naming
convention is as follows:

    <OperatingSystem>-<RunsOnVersions>-<CPU-Type>

The <RunsOnVersions> parameter can be anything that's understandable to
humans. If you don't know where it will run, just use the version where
you compiled. Examples:

next-3.3-4.2-i386
    means: Runs on Nextstep/Openstep for Intel processors on versions
    3.3, 4.0, 4.1 and 4.2

linux-glibc-i386
    means: Runs on Linux for Intel processors equipped with the new
    GNU-libc

EOF
    echo "Please enter the architecture specification now:"
    read archspec
    if [ -z "$archspec" ]; then
        echo "You did not specify an architecture."
        echo "Aborting."
        exit 1
    fi
fi


cd source
make clean
if make; then
    :
else
    echo "Make failed, should we continue anyway? [y/n]"
    read answer
    if [ "$answer" != y -a "$answer" != Y ]; then
        echo "Aborting"
        exit 1
    fi
fi
cd ..

tmpdir=/tmp/Sharitybin-`whoami`-$$

versionInt=`grep 'MAINCONST_VERSION' source/mainFramework/mainconst.h | awk '{print $3}'`
beta=`grep 'MAINCONST_BETA_VERSION' source/mainFramework/mainconst.h | awk '{print $3}'`
version=`echo "$versionInt $beta" | awk '{if($2 != 0){ printf("%d.%dBeta%d\n", $1/1000, $1%1000, $2)}else{printf("%d.%d\n", $1/1000, $1%1000)}}'`

mkdir "$tmpdir"
pkgdir="Sharity.$version.$archspec"
destdir="$tmpdir/$pkgdir"
mkdir "$destdir"
mkdir "$destdir/packages"

mv install/manual $destdir
mv install/setup $destdir

# strip only selected binaries
# We better strip the X GUI because debug info for GTK is LARGE
for i in install/[Ss]harity; do
    if [ -f "$i" -a -x "$i" ]; then
        strip "$i" 2>/dev/null
    fi
done

mv install/* $destdir/packages
cp Changelog $destdir
cp README $destdir
cp source/doc/License.txt $destdir
cp -rp icons $destdir

cd "$tmpdir"
tar cf "$pkgdir".tar "$pkgdir"
gzip -9 "$pkgdir".tar

cat <<EOF

Ready.
----------------------------------------------
The packed installation package is in
$tmpdir/$pkgdir.tar.gz.
This is the file intended for distribution.

The unpacked installation package is in
$tmpdir/$pkgdir.
It is suitable for immediate installation.
----------------------------------------------
EOF
