#!/bin/sh
#############################
## Build script for: gnucash
## Creator: Jay Scott Raymond
## Adapted from examples from linuxpackages.net
## Date: 19 Sept 2005
## Builds package: Yes
## Source location: http://www.gnucash.org/
## Downloads source: No
## Build script version: v1
## Requirements: 
##
## Notes: 
##

## Include the slackware-pkg conf file
if [ -a /etc/slack-package.conf ]; then
. /etc/slack-package.conf
  else
  echo "Sorry you need to have the slack-package.conf file to run these"
  echo "please install the slackbuilds package from LinuxPackages.net"
  exit
fi

# Set initial variables:
NAME=slib
#VERSION=2.0.5
VERSION=3b1
BUILD=1${MYIN}
ARCH=noarch

## Location to download the sources
#SRC_LOC=""

PKG=$TMP/package-$NAME

## Lets Grab the Source if needed
#if [ -a $CWD/$NAME-$VERSION.tar.gz ]; then
#  echo "Source present not downloading"
#  else
#  $WGET $SRC_LOC || true
#fi

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

unpack() {
cd $TMP
rm -rf $NAME
# choose one
unzip $CWD/$NAME-$VERSION.zip
#tar xjvf $CWD/$NAME-$VERSION.tar.bz2
#tar xzvf $CWD/$NAME-$VERSION.tar.gz
cd $NAME
patch -p0 < $CWD/Makefile.patch || exit 1
fix_source
}

config() {
    cd $TMP/$NAME
}

compile() {
    cd $TMP/$NAME
    make || exit 2
    make slib.html || exit 3
}

install() {
    cd $TMP/$NAME
    make prefix=/usr/ libdir=/usr/share/guile/site/ DESTDIR=$PKG install infoz || exit 4
    rm $PKG/usr/info/dir
    cp README $PKG/usr/share/guile/site/slib
}

# use this for packages that don't respect DESTDIR or need additional fixup
construct() {
echo -e "no construct step"
}

prepare() {
create_docs $PKG $NAME-$VERSION
echo "cp $TMP/$NAME/slib.html $PKG/usr/doc/$NAME-$VERSION"
cp $TMP/$NAME/slib.html $PKG/usr/doc/$NAME-$VERSION

## Some package cleanup
( cd $PKG
#strip_bin
#strip_lib
#strip_static
gzip_man $PKG
gzip_info $PKG
bin_perms $PKG
sbin_perms $PKG
)
}

description() {
mkdir -p $PKG/install 
        cat > $PKG/install/slack-desc << END 
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.

    |-----handy-ruler------------------------------------------------------|
slib: SLIB $VERSION
slib:
slib: SLIB is a portable scheme library meant to provide compatibiliy and
slib: utility functions for all standard scheme implementations.  Slib
slib: conforms to Revised^5 Report on the Algorithmic Language Scheme and
slib: the IEEE P1178 specification.  Slib supports Unix and similar systems,
slib: VMS, and MS-DOS.
slib: 
slib: The maintainer can be reached at agj @ alum.mit.edu.
slib: 	    http://swiss.csail.mit.edu/~jaffer/SLIB.html
slib: 

END
}

doinst() {
mkdir -p $PKG/install 
        cat > $PKG/install/doinst.sh << END 

usr/bin/guile -c "(use-modules (ice-9 slib)) (require 'new-catalog)" "/\${ROOT}"

# Update the /usr/info/dir info-database, so that we will see the new
# "autoconf" item in info root structure, if we type "info".
if [ -x usr/bin/install-info ] ; then
  install-info --info-dir=usr/info usr/info/slib.info.gz 2>/dev/null
elif fgrep "gnucash-design" usr/info/dir 1> /dev/null 2> /dev/null ; then
  GOOD=yes # It seems to be entered in the /usr/info/dir already
else # add the info to the dir file directly:
cat << EOF >> usr/info/dir

Programming
* slib: (slib).       Portable scheme library.
EOF
fi

END
}

cpslackbuild() {
mkdir -p $PKG/usr/src/slackbuilds/$NAME
cp $CWD/$NAME.SlackBuild $PKG/usr/src/slackbuilds/$NAME
}

build() {
# Build the package:
cd $PKG
makepkg -l y -c n /$PKG_DIR/$NAME-$VERSION-$ARCH-$BUILD.tgz
echo "Your $NAME package is complete, make sure you open it up before installing it."
echo "It is located in $PKG_DIR thanks for your support The Linuxpackages.net Folks"
}

unpack
config
compile
install
construct
prepare
description
doinst
cpslackbuild
build


