#!/bin/bash

# beecrypt.SlackBuild
# by Stuart Winter <stuart@armedslack.org> for the Slackware porting Project.
# Heavily based on the original Slackware build script.
# 09-Jun-2004

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/ap/rpm
export PORTCWD=$PWD

# Package meta-data:
export PACKAGE=beecrypt
export PKGSERIES=ap
export ARCH=${ARCH:=$PORTARCH}
export VERSION=3.1.0
export BUILD=1

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Determine the CFLAGS for the known architectures:
#case $PORTARCH in
#   arm)     ARCH_CFLAGS="-O2 -march=armv3 -mtune=xscale" 
#            MCPU=xscale
#            ARCHCPU=armv3 ;;
#   powerpc) ARCH_CFLAGS="-O2" ;;
#   sparc)   ARCH_CFLAGS="-O2" ;;
#   *)       ARCH_CFLAGS="-O2" ;;
#esac

# Untar source:
tar jxvvf $CWD/$PACKAGE-$VERSION.tar.bz2
cd $PACKAGE-$VERSION
slackhousekeeping

# Warning: For ARM do NOT add --with-cpu, --with-arch
#          because it will build a broken libeecrypt.so.
#          Thanks to Jim Hawkins for tracking this down.
#          I don't know if this affects other non x86 archs too.

# Configure:
#CFLAGS="$ARCH_CFLAGS" \
./configure \
   --prefix=/usr \
   --enable-shared=no \
   --enable-static=yes \
   --with-pic \
   $ARCH-slackware-linux || failconfig

# Build:
make || failmake

# Install into package:
make install DESTDIR=$PKG
strip -g $PKG/usr/lib/*.a

# Start fakeroot server:
start_fakeroot

# Slackware policies:
cd $PKG
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # set all files to root.root, chmod -R og-w, slackchown, slack644docs

# Build package.  We only build this in order to build RPM, so
# we'll just toss it into /tmp and leave it there.
makepkg -l y -c n /tmp/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
