# Build recipe for fossil.
#
# Copyright (c) 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=fossil-src
pkgname=fossil
version=2.20
release=1

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

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

# Remote source(s)
fetch=https://www.fossil-scm.org/home/tarball/210e89a0597f225f49722b096cf5563bf193e920e02a9bd38503a906deacd416/$tarname

homepage=https://www.fossil-scm.org

description="
A simple, high-reliability, distributed version control system.

Fossil is a distributed version control system (DVCS) with built-in forum,
wiki, ticket tracker, CGI/HTTP interface, and HTTP server.

For more information, please visit:
$homepage
"

license="BSD 2-clause"

# Source documentation
docs="COPYRIGHT* README.md VERSION"
docsdir="${docdir}/${pkgname}-${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" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --with-openssl=/usr \
     --with-zlib=/usr \
     --with-sqlite=/usr \
     --with-tcl=/usr \
     --with-tcl-private-stubs \
     --with-mman \
     --json \
     --disable-internal-sqlite \
     --build="$(gcc -dumpmachine)"

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

    # Install and compress manual page

    install -p -m 644 fossil.1 -D "${destdir}/${mandir}/man1/fossil.1"
    lzip -9 "${destdir}/${mandir}/man1/fossil.1"

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

