#!/bin/sh
## Advanced.PkgBuild script for: 	GCC-2.95.3
##
## Amigo PkgBuild-0.3 - Gilbert Ashley <amigo@ibiblio.org>
##
##### ------------Standard Package Variables-------------------
# Most source code only needs these  4 variables set.
# Set  SRC_SUFFIX  to ".tar.gz" ".tgz" ".tar.bz2" or ".tbz"

BUILD="1"
NAME="gcc295"
VERSION="2.95.3"
SRC_SUFFIX=".tar.bz2"

#####--------Common Overrides and Options----------------------
PRE_FIX="/opt/gcc-2.95.3"
TARGET=i486-slackware-linux
HOST=i486-slackware-linux
# EXTRA_CONFIGS="--enable-shared \
# --with-gnu-ld --enable-threads --verbose \
# --target=${TARGET} --host=${HOST}"
# DOCLIST=""
# GROUP_NAME=""
#######----------------Processing------------------------------
# Get functions and read in configuration files
source /usr/libexec/src2pkg/FUNCTIONS ;
# This template calls each process individually so you can add
# extra instructions between processes, or even leave out steps.

pre_process ;
find_source ;
make_dirs ;
unpack_source ;
fix_source_perms ;

OBJ_BUILD_DIR=$SRC_BUILDS_DIR/$NAME-$VERSION-obj-$BUILD$SIG ;
mkdir -p $OBJ_BUILD_DIR ;

(cd $OBJ_BUILD_DIR;
  CFLAGS="-Wall -O2" LDFLAGS=-s \
    ../$NAME-$VERSION-src-$BUILD$SIG/configure \
					   --prefix=$PRE_FIX \
					   --enable-shared \
					   --with-gnu-ld \
                       --enable-languages=c,c++ \
					   --enable-threads \
                       --verbose \
                       --target=${TARGET} \
                       --host=${HOST}
  make bootstrap;
  # make info;
  make check;
  make install prefix=$PKG_DIR$PRE_FIX ;
  # make install-info prefix=$PKG_DIR$PRE_FIX ;
)

# configure_source ;
# compile_source ;
# fake_install ;

fix_pkg_perms ;
rm -rf $PKG_DIR$PRE_FIX/i486-slackware-linux
( cd $PKG_DIR$PRE_FIX/lib ; ln -sf /opt/gcc-2.95.3/bin/cpp cpp )

( cd $PKG_DIR$PRE_FIX/bin
mv g++ g++-gcc-2.95.3
mv gcc gcc-2.95.3
ln -sf g++-gcc-2.95.3 g++
ln -sf gcc-2.95.3 gcc
ln -sf g++ c++
ln -sf gcc cc
ln -sf gcc-2.95.3 i486-slackware-linux-gcc
rm -rf include/objc
strip -g *
chown root.bin * .
)

( cd $PKG_DIR$PRE_FIX/lib/gcc-lib/i486-slackware-linux/2.95.3
strip -g cc1* collect2 cpp0
)

strip_bins ;
create_docs ;

cp $CWD/Resources/GCC295 $PKG_DIR/usr/doc/$NAME-$VERSION

# compress_man_pages ;
( cd $PKG_DIR$PRE_FIX/man/man1 ; gzip -9 *)

make_description ;
make_doinst ;
make_package ;

# Make a PiggyBack package
mkdir -p $PKG_BUILDS_DIR/cxx32-libs/install
cp $CWD/Resources/cxx32-libs.slack-desc $PKG_BUILDS_DIR/cxx32-libs/install/slack-desc
cp $CWD/Resources/cxx32-libs.doinst.sh $PKG_BUILDS_DIR/cxx32-libs/install/doinst.sh

mkdir -p $PKG_BUILDS_DIR/cxx32-libs/usr/i486-slackware-linux/lib
cp -a $PKG_DIR$PRE_FIX/lib/libstdc++-3-libc6.3-2-2.10.0.so $PKG_BUILDS_DIR/cxx32-libs/usr/i486-slackware-linux/lib

cd $PKG_BUILDS_DIR/cxx32-libs ;
makepkg -l n -c n ../cxx32-libs-3_2_2.10.0-i486-1.tgz
# end PiggyBack

post_process ;
exit 0

## See the Amigo PkgBuild documentation for help and examples.