#!/bin/bash

# module-init-tools.SlackBuild
# by Stuart Winter <mozes@slackware.com> for the Slackware porting Project.
# Heavily based on the original Slackware build script.
# 08-Jun-2004

#
# Build module-init-tools statically:
# LDFLAGS=-static ./configure && make

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

# Record toolchain & other info for the build log:
slackbuildinfo

# Determine the CFLAGS for the known architectures:
case $ARCH in
   arm)     export SLKCFLAGS="-O2 -march=armv4t"
            export LIBDIRSUFFIX="" ;;
   *)       export SLKCFLAGS="-O2" ;;
esac

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

# Extract source:
cd $TMPBUILD
tar xvvf $CWD/$PKGNAM-$VERSION.tar.?z*
#tar xvvf $PORTCWD/sources/$PKGNAM*$VERSION*orig*z*
cd $PKGNAM-* || exit 1
slackhousekeeping

# Exclude *.{old,new,bak} files (and a few others that obviously aren't
# valid for this...  Thanks to Marco d'Itri for the patch that it's based on
zcat $CWD/modprobe.ignore_some_suffixes.diff.gz | patch -p1 || exit 1

# Configure:
./configure \
   --prefix=/ \
   --enable-zlib \
   --bindir=/sbin \
   --docdir=/usr/doc/module-init-tools-$VERSION \
   --mandir=/usr/man \
   --build=$ARCH-slackware-linux-gnueabi || failconfig

# Build:
make $NUMJOBS || failmake

# Install into package:
make install DESTDIR=$PKG

# Create the config directory just in case
mkdir -p $PKG/etc/modprobe.d/

# Link lsmod into /bin
mkdir -p $PKG/bin
( cd $PKG/bin ; ln -sf /sbin/lsmod . )

mkdir -p $PKG/usr/doc/module-init-tools-$VERSION
cp -a \
  AUTHORS CODING COPYING FAQ README TODO \
    $PKG/usr/doc/module-init-tools-$VERSION

##############################################################

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh
slackmp         # run makepkg -l y -c n

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