#!/bin/sh
# -*- Mode: sh; indent-tabs-mode: nil; tab-width: 2 -*-
#
# © 2010,2011 Canonical Ltd
#
# 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; version 3 of the License.
#
# 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/>.
#
# Authors: Michael Terry <michael.terry@canonical.com>
# =====================================================================

# The package name could be set up multiple ways.
# AC_INIT([Example Project],[1.0],[http://bugs.example.com/],[example-project],[http://example.com/])
# AC_INIT([Example Project],[1.0])
# First is easy; we just grab the 4th field.  Second is harder and requires us
# to simplify the string as autoconf would.

tarname=$(pkgme_autoconf_initfield 4)
if [ -n "$tarname" ]; then
  echo "$tarname"
  exit 0
fi

# Now we mangle the project name into a tarball name. From the autoconf manual:
# "... with `GNU ' stripped, lower-cased, and all characters
#  other than alphanumerics and underscores are changed to `-'."

pkgname=$(pkgme_autoconf_initfield 1)
pkgname=$(echo "$pkgname" | sed 's/^GNU //')
pkgname=$(echo "$pkgname" | tr [:upper:] [:lower:])
pkgname=$(echo -n "$pkgname" | tr -c [:alnum:]_ -)
echo "$pkgname"
exit 0
