#!/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=gtk3
PKGVERSION=3.24.0
PKGREVISION=1
PKGLICENSE="LGPLv20"
PKGSUMMARY="multiplatform toolki"
PKGDOWNLOAD="https://download.gnome.org/sources/gtk+/3.24/gtk+-$PKGVERSION.tar.xz"
PKGDEPENDS="graphics/cairo"
PKGOPTIONS="CUPS NLS WAYLAND X"

: ${CC:=gcc}
: ${CFLAGS:=-O2}
: ${CXX:=g++}
: ${CXXFLAGS:=-O2}
: ${LDFLAGS:=}
: ${CUPS:=yes}
: ${NLS:=yes}
: ${WAYLAND:=yes}
: ${X:=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 $PKGDEPENDS"
	with_nls="--enable-nls"
else
	with_nls="--disable-nls"
fi

if [ "$WAYLAND" = "yes" ] || [ "$X" = "yes" ]; then
	PKGDEPENDS="graphics/pango $PKGDEPENDS"

	if [ "$WAYLAND" = "yes" ]; then
		PKGDEPENDS="graphics/wayland $PKGDEPENDS"
		with_wayland="--enable-wayland-backend"
	else
		with_wayland="--disable-wayland-backend"
	fi

	if [ "$X" = "yes" ]; then
		PKGDEPENDS="fonts/fontconfig $PKGDEPENDS"
		PKGDEPENDS="x11/libx11 $PKGDEPENDS"
		PKGDEPENDS="x11/libxcomposite $PKGDEPENDS"
		PKGDEPENDS="x11/libxcursor $PKGDEPENDS"
		PKGDEPENDS="x11/libxdamage $PKGDEPENDS"
		PKGDEPENDS="x11/libxext $PKGDEPENDS"
		PKGDEPENDS="x11/libxinerama $PKGDEPENDS"
		PKGDEPENDS="x11/libxfixes $PKGDEPENDS"
		PKGDEPENDS="x11/libxi $PKGDEPENDS"
		PKGDEPENDS="x11/libxrandr $PKGDEPENDS"

		with_x="--enable-x11-backend"
	else
		with_x="--disable-x11-backend"
	fi
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=/usr \
		$with_nls \
		$with_wayland \
		$with_x
	make
	make install DESTDIR=$DESTDIR
	rm -f $DESTDIR/usr/lib/{gtk,gdk}-3.la
	rm -f $DESTDIR/usr/lib/gtk-3.0/3.0.0/immodules/*.la
	rm -f $DESTDIR/usr/lib/gtk-3.0/3.0.0/printbackends/*.la

	popd
	rm -rf gtk+-$PKGVERSION
}

