#!/bin/sh
#
# Copyright (c) 2019-2021 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

PKGNAME=gtk2
PKGVERSION=2.24.32
PKGREVISION=1
PKGLICENSE="LGPL-2.0-only"
PKGSUMMARY="multiplatform toolkit"
PKGDOWNLOAD="https://download.gnome.org/sources/gtk+/2.24/gtk+-$PKGVERSION.tar.xz"
PKGDEPENDS="atk
            cairo
            fontconfig
            freetype
            gdk-pixbuf
            glib
            libx11
            libxcomposite
            libxcursor
            libxdamage
            libxext
            libxfixes
            libxi
            libxinerama
            libxrandr
            libxrender
            pango"
PKGOPTIONS="CUPS NLS"
PKGTAGS="DEPRECATED"

: ${CC:=clang}
: ${CFLAGS:=-O2}
: ${CXX:=clanclang++}
: ${CXXFLAGS:=-O2}
: ${LDFLAGS:=}
: ${CUPS:=yes}
: ${NLS:=yes}

if [ "$CUPS" = "yes" ]; then
	PKGDEPENDS="cups $PKGDEPENDS"
	with_cups="--enable-cups"
else
	with_cups="--disable-cups"
fi

if [ "$NLS" = "yes" ]; then
	PKGDEPENDS="gettext $PKGDEPENDS"
	with_nls="--enable-nls"
else
	with_nls="--disable-nls"
fi

build()
{
	rm -rf gtk+-$PKGVERSION
	tar xvf gtk+-$PKGVERSION.tar.xz
	cd gtk+-$PKGVERSION

	CC="$CC" \
	CFLAGS="$CFLAGS" \
	CXX="$CXX" \
	CXXFLAGS="$CXXFLAGS" \
	LDFLAGS="$LDFLAGS" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix= \
		--localedir=/share/locale \
		$with_cups \
		$with_nls
	make
	make install localedir=/share/locale DESTDIR=$DESTDIR
	rm -f $DESTDIR/bin/gtk-update-icon-cache
	find $DESTDIR -type f -name "*.la" -delete

	cd ..
	rm -rf gtk+-$PKGVERSION
}

