# Build recipe for hldig.
#
# Copyright (c) 2020, 2022 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=hldig
version=20210616_9427c9cd
release=2

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

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

# Remote source(s)
fetch="
 https://dragora.mirror.garr.it/current/sources/$tarname
 rsync://rsync.dragora.org/current/sources/$tarname
"

homepage=https://github.com/solbu/hldig

description="
Internet search engine software (fork of htdig).

The ht://Dig system is a complete world wide web indexing and searching
system for a domain or intranet.  This system is not meant to replace
the need for powerful internet-wide search systems like Lycos, Infoseek,
Google and AltaVista.  Instead it is meant to cover the search needs for
a single company, campus, or even a particular sub section of a web site.
As opposed to some WAIS-based or web-server based search engines,
ht://Dig can easily span several web servers.  The type of these different
web servers doesn't matter as long as they understand common protocols
like HTTP.

ht://Dig was developed at San Diego State University as a way to search
the various web servers on the campus network.

hl://Dig is a fork of ht://Dig, a world-wide-web search system for an
intranet or small internet.  See:

$homepage
"

license=GPLv2+

# Source documentation
docs="AUTHORS.md CONDUCT.md CONTRIBUTING.md COPYING ChangeLog \
 ChangeLog.md README.md STATUS TESTING.md TRANSLATING.md VERSION"
docsdir="${docdir}/${program}-${version}"

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

    cd "$srcdir"

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

    #autoreconf -v
    #rm -f libhtdigphp/config.log libhtdigphp/config.status

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS -std=c++14" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --with-gnu-ld \
     --with-cgi-bin-dir=/usr/lib${libSuffix}/cgi-bin \
     --with-search-dir=/usr/share/doc/${program}-${version}/examples \
     --with-image-dir=/var/lib/hldig/www \
     --with-config-dir=/etc/hldig \
     --with-common-dir=/etc/hldig \
     --with-database-dir=/var/lib/hldig \
     --build="$(gcc -dumpmachine)"

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

    # Make symlink at usr/bin for hlsearch(1)
    (
        cd "${destdir}/usr/bin"
        ln -sf /usr/lib${libSuffix}/cgi-bin/hlsearch .
    )

    # Make symlinks for compatibility with htdig commands
    (
        cd "${destdir}/usr/bin"
        for name in hl*
        do
            name="${name#hl}"
            ln -sf hl${name} ht${name}
        done
    )

    # To handle config files (.new) via graft(1)

    touch "${destdir}/etc/hldig/.graft-config"

    # Compress manual pages, copy the documentation

    lzip -9 "${destdir}/${mandir}"/man?/*.?

    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

