#!/bin/bash

# x11-skel.SlackBuild
# Heavily based on the original Slackware build scripts,
# Modified by Stuart Winter <mozes@slackware.com>
# Please see changelog.txt for revisions to this package's build script history.

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

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

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

# Create package framework:
cd $PKG
mkdir -p etc/xdg
mkdir -p etc/X11
mkdir -p usr/lib/X11
mkdir -p usr/bin
mkdir -p var/log/setup
mkdir -p usr/man/man1
#cp -a $CWD/scripts/xorg.conf-fbdev etc/X11
cp -a $CWD/scripts/xorg.conf-vesa etc/X11
chown -R root:root etc/X11
find etc/X11 -type f -exec chmod 644 {} \;
cp -a $CWD/scripts/xorgsetup usr/bin
cp -a $CWD/scripts/xwmconfig usr/bin
chown root:root usr/bin/*
chmod 755 usr/bin/*
cp -a $CWD/scripts/setup.xwmconfig var/log/setup
chown root:root var/log/setup/setup.xwmconfig
chmod 755 var/log/setup/setup.xwmconfig
cat $CWD/manpages/xwmconfig.1 | gzip -9c > $PKG/usr/man/man1/xwmconfig.1.gz

# Patch the setup script to exit if it finds itself
# running on a headless platform:
# Don't do this anymore because it's useful to configure the default
# window manager for use with tightvnc
# in the 'extra' packages.
#( cd $PKG/var/log/setup
#  patch -p0 --verbose < $PORTCWD/arm/setup.xwmconfig.diff || exit 1)

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

# Apply generic Slackware packaging policies:
cd $PKG
slackdesc       # install slack-desc and doinst.sh

# Add in ARMedslack's xorg post install script which selects
# a default xorg.conf for the specific hardware you're using.
cat $PORTCWD/arm/doinst.sh.xorgconf >> install/doinst.sh
#install -vpm644 $PORTCWD/arm/xorg.conf-{versatile,openrd}* etc/X11/
install -vpm644 $PORTCWD/arm/xorg.conf* etc/X11/

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
slackmp         # run makepkg -l y -c n

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