SUMMARY="GLib is a cross-platform software utility library"
DESCRIPTION="GLib is a cross-platform software utility library that began as \
part of the GTK+ project. However, before releasing version 2 of GTK+, the \
project's developers decided to separate non-GUI-specific code from the GTK+ \
platform, thus creating GLib as a separate product. GLib was released as a \
separate library so other developers, those who did not make use of the \
GUI-related portions of GTK+, could make use of the non-GUI portions of the \
library without the overhead of depending on the entire GUI library.
Since GLib is a cross-platform library, applications using it to interface \
with the operating system are usually portable across different operating \
systems without major changes."
HOMEPAGE="https://www.gtk.org/"
COPYRIGHT="1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
	1991-2003 Free Software Foundation, Inc.
	1997-2006 University of Cambridge.
	1998-2001, 2003-2010 Red Hat, Inc.
	2007-2009 Nokia Corporation
	2008, 2010 Oracle and/or its affiliates, Inc. All rights
	2008-2010 Codethink Limited
	2008-2010 Collabora Ltd.
	1995-2010 Several others"
LICENSE="GNU LGPL v2"
REVISION="2"
SOURCE_URI="https://gitlab.gnome.org/GNOME/glib/-/archive/$portVersion/glib-$portVersion.tar.gz"
CHECKSUM_SHA256="73c10a1927c79d8c318bba9ad6f7bc96ff187013ee19377b3e82f684958b2c2c"
SOURCE_DIR="glib-$portVersion"
PATCHES="glib2-$portVersion.patchset"

ARCHITECTURES="all ?x86"
SECONDARY_ARCHITECTURES="x86"

libVersion="0.5701.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	glib2$secondaryArchSuffix = $portVersion
	cmd:gapplication$secondaryArchSuffix
	cmd:gdbus$secondaryArchSuffix
	cmd:gdbus_codegen$secondaryArchSuffix
	cmd:gio$secondaryArchSuffix
	cmd:gio_querymodules$secondaryArchSuffix
	cmd:glib_compile_resources$secondaryArchSuffix
	cmd:glib_compile_schemas$secondaryArchSuffix
	cmd:gresource$secondaryArchSuffix
	cmd:gsettings$secondaryArchSuffix
	lib:libgio_2.0$secondaryArchSuffix = $libVersionCompat
	lib:libglib_2.0$secondaryArchSuffix = $libVersionCompat
	lib:libgmodule_2.0$secondaryArchSuffix = $libVersionCompat
	lib:libgobject_2.0$secondaryArchSuffix = $libVersionCompat
	lib:libgthread_2.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	gettext$secondaryArchSuffix
	lib:libffi$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix >= 1
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	glib2${secondaryArchSuffix}_devel = $portVersion compat >= 0
	cmd:glib_genmarshal$secondaryArchSuffix
	cmd:glib_gettextize$secondaryArchSuffix
	cmd:glib_mkenums$secondaryArchSuffix
	cmd:gobject_query$secondaryArchSuffix
	cmd:gtester$secondaryArchSuffix
	cmd:gtester_report$secondaryArchSuffix
	devel:libgio_2.0$secondaryArchSuffix = $libVersionCompat
	devel:libglib_2.0$secondaryArchSuffix = $libVersionCompat
	devel:libgmodule_2.0$secondaryArchSuffix = $libVersionCompat
	devel:libgobject_2.0$secondaryArchSuffix = $libVersionCompat
	devel:libgthread_2.0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	glib2$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	cmd:perl
	cmd:python
	devel:libffi$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	lib:libffi$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libffi$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix >= 1
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	cmd:which
	"

defineDebugInfoPackage glib2$secondaryArchSuffix \
	$binDir/gapplication \
	$binDir/gdbus \
	$binDir/gio \
	$binDir/gio-querymodules \
	$binDir/glib-compile-resources \
	$binDir/glib-compile-schemas \
	$binDir/gresource \
	$binDir/gsettings \
	$libDir/libgio-2.0.so.$libVersion \
	$libDir/libglib-2.0.so.$libVersion \
	$libDir/libgmodule-2.0.so.$libVersion \
	$libDir/libgobject-2.0.so.$libVersion \
	$libDir/libgthread-2.0.so.$libVersion

BUILD()
{
	runConfigure ./autogen.sh CFLAGS=-D_BSD_SOURCE

	# There seem to be a problem with libtool, and without this some libraries
	# would not be found during the build.
	mkdir -p gobject/.libs gio/.libs
	ln -sf ../../glib/.libs gobject/.libs/lib

	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool library files
	rm $libDir/lib*.la

	prepareInstalledDevelLibs libgio-2.0 \
					libglib-2.0 \
					libgmodule-2.0 \
					libgobject-2.0 \
					libgthread-2.0
	fixPkgconfig

	# The libtool files reference other libraries using the wrong paths, which
	# creates a lot of confusion. Fix them so correct paths are used.
	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir=$(dirname $portPackageLinksDir)
	local ffiLinksDir="$packageLinksDir/${develPackageName}/devel~libffi$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i -e "s,^\(Libs.private.*\)-L.* \(-l.*\)$,\1-L$ffiLinksDir \2," \
		$developLibDir/pkgconfig/gobject-2.0.pc
	local zlibLinksDir="$packageLinksDir/${develPackageName}/devel~libz$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i -e "s,^\(Libs.private.*\)-L.* \(-l.*\)$,\1-L$zlibLinksDir \2," \
		$developLibDir/pkgconfig/gio-2.0.pc


	# move the glibconfig header into devel as well
	mv $libDir/glib-2.0 $developLibDir

	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir \
		$binDir/glib-genmarshal \
		$binDir/glib-gettextize \
		$binDir/glib-mkenums \
		$binDir/gobject-query \
		$binDir/gtester \
		$binDir/gtester-report

	rm $libDir/charset.alias
}

TEST()
{
	make check
}
