# Build recipe for GTK+2.
#
# Copyright (C) 2018, MMPG <mmpg@vp.pl>
# Copyright (C) 2018-2019, 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=gtk+
version=2.24.33
release=1

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

# Difference package name with other series
pkgname=gtk2

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

# Remote source(s)
fetch="https://download.gnome.org/sources/gtk+/${version%.*}/$tarname"

description="
A multi-platform toolkit for creating graphical user interfaces.

Offering a complete set of widgets, GTK+ is suitable for projects
ranging from small one-off projects to complete application suites.
"

homepage=https://www.gtk.org
license=GPLv2+

# Copy documentation
docs="AUTHORS COPYING NEWS README* HACKING"
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" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --enable-static=no \
     --enable-shared=yes \
     --enable-debug=no \
     --enable-introspection=yes \
     --enable-xkb=yes \
     --with-xinput=yes \
     --disable-glibtest \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1 \
     RUN_QUERY_IMMODULES_TEST=false RUN_QUERY_LOADER_TEST=false

    make -j${jobs} \
     RUN_QUERY_IMMODULES_TEST=false RUN_QUERY_LOADER_TEST=false \
     DESTDIR="$destdir" install-strip

    # Add a basic configuration
cat << EOF > "${destdir}/etc/gtk-2.0/gtkrc"
gtk-icon-theme-name = "hicolor"

EOF

    # Manage dot new file(s) via graft(8)
    touch "${destdir}/etc/gtk-2.0/.graft-config"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

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

