# Build recipe for libz.
#
# Copyright (c) 2016-2017 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.

program=libz
version=1.2.8.2015.12.26
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/libs"

pkgversion=1.2.8

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

# Remote source(s)
fetch=http://sortix.org/libz/release/libz-1.2.8.2015.12.26.tar.gz

description="
A general purpose data compression library.

libz is a general purpose data compression library.  The data format
used by libz is described by RFC 1950 (zlib format), RFC 1951 (deflate
format), and RFC 1952 (gzip format).

Sortix libz is developed as part of the Sortix operating system by
Jonas 'Sortie' Termansen (sortie@maxsi.org) and contributors.
"

homepage=http://sortix.org/libz
license="Custom, zlib"

# Source documentation
docs="CHANGES FAQ README TODO"
docsdir="${docdir}/${program}-${pkgversion}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

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

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --enable-shared \
     --enable-static

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

    # Strip manually (LDFLAGS is not picked up)
    strip --strip-unneeded "${destdir}/usr/lib${libSuffix}"/libz.so*
    strip -g "${destdir}/usr/lib${libSuffix}/libz.a"

    # Fix library permissions
    chmod 755 "${destdir}/usr/lib${libSuffix}/libz.so.${pkgversion}"

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

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

