#!/bin/sh
#
# Copyright (c) 2019 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="LGPLv20"
PKGSUMMARY="multiplatform toolkit"
PKGDOWNLOAD="https://download.gnome.org/sources/gtk+/2.24/gtk+-$PKGVERSION.tar.xz"
PKGDEPENDS="accessibility/atk
            fonts/fontconfig
            graphics/gdk-pixbuf
            graphics/pango
            lib/glib
            x11/libx11
            x11/libxcomposite
            x11/libxcursor
            x11/libxdamage
            x11/libxext
            x11/libxfixes
            x11/libxi
            x11/libxinerama
            x11/libxrandr"
PKGOPTIONS="CUPS NLS"

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

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

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

build()
{
	rm -rf gtk+-$PKGVERSION
	tar xvaf gtk+-$PKGVERSION.tar.xz
	pushd gtk+-$PKGVERSION

	CC="$CC" \
	CFLAGS="$CFLAGS" \
	CXX="$CXX" \
	CXXFLAGS="$CXXFLAGS" \
	LDFLAGS="$LDFLAGS" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix= \
		$with_cups \
		$with_nls
	make
	make install DESTDIR=$DESTDIR
	rm -f $DESTDIR/bin/gtk-update-icon-cache
	rm -f $DESTDIR/lib/gtk-2.0/2.10.0/engines/*.la
	rm -f $DESTDIR/lib/gtk-2.0/2.10.0/immodules/*.la
	rm -f $DESTDIR/lib/gtk-2.0/2.10.0/printbackends/*.la
	rm -f $DESTDIR/lib/gtk-2.0/modules/*.la
	rm -f $DESTDIR/lib/libgailutil.la
	rm -f $DESTDIR/lib/lib{gdk,gtk}-x11-2.0.la

	popd
	rm -rf gtk+-$PKGVERSION
}

