#!/bin/bash

# Slackware build script for python2-markdown

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# This is the same software that used to be packaged as
# python/Markdown, maintained by Markus Reichelt. He abandoned it,
# and I wrote this new SlackBuild to replace it, as some things still
# required it.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=python2-markdown
SRCNAM=Markdown
VERSION=${VERSION:-2.6.11}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# There is no native code here, so no SLKCFLAGS. The only reason this
# isn't noarch is the lib vs. lib64 thing. Python is smart enough to
# figure it out, so there's no need for LIBDIRSUFFIX, either.

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-$VERSION
tar xvf $CWD/$SRCNAM-$VERSION.tar.gz --no-same-owner
cd $SRCNAM-$VERSION
find . ! -type l    -a \( \
  \(     -perm /111 -a ! -perm 755 -a -exec chmod -f 755 {} + \) -o \
  \(   ! -perm /111 -a ! -perm 644 -a -exec chmod -f 644 {} + \) \)

python2 setup.py install --root=$PKG

# Not gonna bother with the API docs, since this is outdated and
# only exists as a dependency for other outdated software.
PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
mkdir -p $PKGDOC
cp -a LICENSE.md MANIFEST.in $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
