#! /bin/sh
# -*- Mode: Shell-script -*-

# Copyright (C) 2002-2010 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

case "$0" in
*/* )
  progdir=`echo "$0" | sed 's@/[^/]*$@@'`
  cd ${progdir}
  progdir=`pwd`
  prognam=`echo "$0" | sed 's@.*/@@'`
  ;;

* )
  progdir=`pwd`
  prognam="$0"
  ;;
esac

# kill the patriarch process.  If we are not the patriarch,
# then exit 1 too.
#
func_die()
{
  echo "${prognam} failure:  $*" >&2
  kill -${SIGTERM} ${progpid}
  exit 1
}

func_init()
{
  progpid=$$
  glibdir=`cd .. >/dev/null ; pwd`
  SIGTERM=15

  git --version >/dev/null 2>&1 \
    || func_die "git is not operational"

  test -d _b && rm -rf _b

  case "$*" in
  *'--clean'* | *'--clob'* )
    git clean -f -x -d .
    test $# -eq 1 && exit 0
    ;;
  esac

  case "$-" in
  *x* ) dashx=-x ;;
  * ) dashx= ;;
  esac
}

func_bootstrap()
{
  PS4='>bs> ' \
    /bin/sh ${dashx} ./bootstrap \
      || func_die bootstrap failure
}

func_mkdistro()
{
  mkdir _b               || func_die mkdir _b
  cd _b
  ../configure           || func_die configure
  make                   || func_die make
  make distcheck         || func_die make distcheck
  mv libposix*.tar.gz .. || func_die cannot move tarball
}

func_init ${1+"$@"}
func_bootstrap
func_mkdistro

:

## 
## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

# end of mk-tarball
