#!/bin/sh

# acpid.SlackBuild
# by Stuart Winter <stuart@armedslack.org> for the Slackware porting Project.
# Based on the original Slackware build script.
# 1-May-2004

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

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

# Untar source:
tar zxvvf $CWD/acpid-$VERSION.tar.gz
cd $PACKAGE-$VERSION
slackhousekeeping

# Create Package framework:
mkdir -p $PKG/usr/{sbin,doc/acpid-$VERSION,man/man8}
mkdir -p $PKG/etc/{acpi/events,rc.d}

# This won't be required once the armv3l toolchain is working:
sed -ie 's/^CFLAGS =\(.*\)$/CFLAGS = -march=armv3 -mtune=xscale \1/' Makefile

# Compile:
make

# Install binaries:
install -m755 acpid $PKG/usr/sbin

# Install man pages:
install -m644 acpid.8 $PKG/usr/man/man8

# Install docs:
cp -a Changelog README \
      $PKG/usr/doc/acpid-$VERSION

# Install other bits:
zcat $CWD/acpi_handler.sh.gz > $PKG/etc/acpi/acpi_handler.sh
chmod 755 $PKG/etc/acpi/acpi_handler.sh
zcat $CWD/default.gz > $PKG/etc/acpi/events/default

# Install run control script:
zcat $CWD/rc.acpid.gz > $PKG/etc/rc.d/rc.acpid
chmod 755 $PKG/etc/rc.d/rc.acpid

# Slackware policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # set all files to root.root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   . $PORTCWD/arm/pkger
 else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links

