# Build recipe for gperf.
#
# Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=gperf
version=3.1
release=2

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://ftp.gnu.org/pub/gnu/gperf/$tarname

description="
Perfect hash function generator.

GNU gperf is a perfect hash function generator.  For a given list of
strings, it produces a hash function and hash table, in form of C or
C++ code, for looking up a value depending on the input string.
The hash function is perfect, which means that the hash table has no
collisions, and the hash table lookup needs a single string comparison
only.

GNU gperf is highly customizable.  There are options for generating C
or C++ code, for emitting switch statements or nested ifs instead of a
hash table, and for tuning the algorithm employed by gperf.
"

homepage=https://www.gnu.org/software/gperf
license=GPLv3+

# Source documentation
docs="AUTHORS COPYING ChangeLog NEWS README"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" \
    LDFLAGS="$QILDFLAGS -static" \
     $configure_args \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make check
    make -j${jobs} DESTDIR="$destdir" install

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress manual page
    lzip -9 "${destdir}/${mandir}/man1/gperf.1"

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"

    for file in $docs
    do
        cp -p $file "${destdir}/$docsdir"
    done
}

