### this file is sourced not run

# REMINDME: load pandoc sfs before building

PKGVER=20161019
PKGNAME=vimpager
TARBALL=$PKGNAME-$PKGVER.tar.gz # the package's tarball
MD5SUM=5d6cc5c4013fb77910762d2cab193331 # package's md5sum
SRC_URL=file:// # source URL to download the package
SLACKREQ='vim'
SLACKDESC= # see pkg_build
SLACKCON=
SLACKSUG=
SLACKINSTALL=

#PKG_NOBUILD=yes # don't run the build-step (don't enter chroot)
#PKG_NOSTRIP=yes # don't strip binaries
#PKG_NOMAKEPKG=yes # don't run makepkg, supposedly pkg_package will do actual packaging


# No assumption on where it is called, just use parameter 
# return 0=good, anything else=bad
# $1-where-to-save (absolute path) $2-tarball-name $SRC_URL-source url
# functions.sh provides default with wget
pkg_download() {
  # copy local git repo to tarball

  local repo tar commit
  repo="$(readlink -f "$1/../pkg/$PKG/link-to-repo")"
  # tar, gzip-compressed, no gzip timestamps, exclude .git files
  tar="env GZIP=-n tar -z --exclude-vcs"
  # save git HEAD info
  commit=$(cd "$repo" &&
    f=`mktemp -d` && f="$f/$PKGNAME" &&
    mkdir -p "$f" && f="$f/git_describe" &&
    git describe > "$f" &&
    echo "$f")
  [ -s "$commit" ] &&
    $tar -cf "$1/$2" \
      -C "${commit%/*}/.." "./$PKGNAME/git_describe" \
      -C "$repo/.." .
}

# Called within $CHROOT_DIR, $SRC_DIR, $PATCHES_DIR and $OUTPUT_DIR 
# with absolute path, to extract / patch package
# all path access *must* be relative otherwise it will affect host
# return 0=good, anything else=bad
# functions.sh provides default to check integrity and extract tarball 
pkg_prepare() {
  pkg_prepare_default
}

# Called within $CHROOT_DIR, $SRC_DIR and $OUTPUT_DIR available 
# with absolute path, to clean up stuff before it is packaged
# all path access *must* be relative otherwise it will affect host
# return 0=good, anything else=bad
# function.sh provides default that does nothing
# Note: pkg_package is optional, but if it exist it has to return success
pkg_package() {
	: do nothing
}

# Called from inside chroot, to build package. 
# Absolute path access is ok.
# return 0=good, anything else=bad
# functions.sh provides default that does configure make install and
# add slackdesc
pkg_build() { 
  local git_describe
  cd tmp/$PKGNAME &&
    # Make fails `git describe` because pkg_download didn't copy
    # the .git folder, so let's create a `git describe` stub first.
    > ./git printf '#!/bin/sh\n[ describe = "$1" ] && cat ./git_describe\n' &&
    chmod +x ./git &&

    PATH=.:$PATH make all install &&

    SLACKDESC="$PKGNAME: $PKGNAME $PKGVER - git $(cat git_describe) (text)
$PKGNAME:  
$PKGNAME: Command-line text viewer with vim syntax highlighting.
$PKGNAME: 
$PKGNAME: 
$PKGNAME: 
$PKGNAME: 
$PKGNAME: 
$PKGNAME: 
$PKGNAME: https://github.com/rkitover/vimpager 
$PKGNAME:
" && pkg_build_slackdesc
}

# vim: ft=sh:
