# Build recipe for lzlib.
#
# Copyright (c) 2017-2021 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=lzlib
version=1.12
release=1

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

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

# Remote source(s)
fetch=https://download.savannah.gnu.org/releases/lzip/lzlib/$tarname

homepage=https://lzip.nongnu.org/lzlib.html
license=GPLv2+

description="
A data compression library for the lzip format.

Lzlib is a data compression library providing in-memory LZMA
compression and decompression functions, including integrity checking
of the decompressed data.  The compressed data format used by the
library is the lzip format.  Lzlib is written in C.

For more information, visit: $homepage
"

# 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="-Wall -W $QICFLAGS -fPIC" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --disable-shared \
     --disable-ldconfig \
     --build="$(gcc -dumpmachine)"

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

    # To install minilzip
    make -j${jobs} DESTDIR="$destdir" install-bin

    # Compress info documents

    rm -f "${destdir}/${infodir}/dir";	# Redundancy
    lzip -9 "${destdir}/${infodir}/lzlib.info"

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

