SUMMARY="C++ interface for glib2"
DESCRIPTION="A C++ API for parts of glib that are useful for C++."
HOMEPAGE="https://www.gtkmm.org/en/"
COPYRIGHT="2021 The gtkmm Development Team"
LICENSE="GNU LGPL v2.1
	GNU GPL v2"
REVISION="1"
SOURCE_URI="http://ftp.gnome.org/pub/GNOME/sources/glibmm/${portVersion%.*}/glibmm-$portVersion.tar.xz"
CHECKSUM_SHA256="b2a4cd7b9ae987794cbb5a1becc10cecb65182b9bb841868625d6bbb123edb1d"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

libVersion="1.3.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
apiVers="2.4"

PROVIDES="
	glibmm$secondaryArchSuffix = $portVersion
	lib:libgiomm$secondaryArchSuffix = $libVersionCompat
	lib:libgiomm_$apiVers$secondaryArchSuffix = $libVersionCompat
	lib:libglibmm$secondaryArchSuffix = $libVersionCompat
	lib:libglibmm_$apiVers$secondaryArchSuffix = $libVersionCompat
	lib:libglibmm_generate_extra_defs$secondaryArchSuffix = $libVersionCompat
	lib:libglibmm_generate_extra_defs_$apiVers$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libglib_2.0$secondaryArchSuffix
	lib:libgmodule_2.0$secondaryArchSuffix
	lib:libgobject_2.0$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libsigc_2.0$secondaryArchSuffix
	"

PROVIDES_devel="
	glibmm${secondaryArchSuffix}_devel = $portVersion
	devel:libgiomm$secondaryArchSuffix = $libVersionCompat
	devel:libgiomm_$apiVers$secondaryArchSuffix = $libVersionCompat
	devel:libglibmm$secondaryArchSuffix = $libVersionCompat
	devel:libglibmm_$apiVers$secondaryArchSuffix = $libVersionCompat
	devel:libglibmm_generate_extra_defs$secondaryArchSuffix = $libVersionCompat
	devel:libglibmm_generate_extra_defs_$apiVers$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	glibmm$secondaryArchSuffix == $portVersion base
	devel:libsigc_2.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libglib_2.0$secondaryArchSuffix
	devel:libgmodule_2.0$secondaryArchSuffix
	devel:libgobject_2.0$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libsigc_2.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:meson
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage glibmm$secondaryArchSuffix \
	"$libDir"/libgiomm-$apiVers.so.$libVersion \
	"$libDir"/libglibmm-$apiVers.so.$libVersion \
	"$libDir"/libglibmm_generate_extra_defs-$apiVers.so.$libVersion

BUILD()
{
	CFLAGS="-D_BSD_SOURCE" \
		LDFLAGS="-lbsd -lgnu -lnetwork" meson build \
		--prefix=$prefix --includedir=$includeDir \
		--libdir=$libDir --datadir=$dataDir --bindir=$binDir \
		-Dmaintainer-mode=false --buildtype=debugoptimized

	ninja $jobArgs -C build
}

INSTALL()
{
	ninja -C build install

	rm -rf $libDir/*.la

	mv $libDir/glibmm-$apiVers/include/*.h $includeDir/glibmm-$apiVers
	mv $libDir/giomm-$apiVers/include/*.h $includeDir/giomm-$apiVers
	rm -rf $libDir/{glibmm-$apiVers,giomm-$apiVers}

	prepareInstalledDevelLibs \
		libgiomm-$apiVers \
		libglibmm-$apiVers \
		libglibmm_generate_extra_defs-$apiVers

	fixPkgconfig

	sed -i -e 's|-I${libdir}/glibmm-$apiVers/include||' \
		$developLibDir/pkgconfig/glibmm-$apiVers.pc
	sed -i -e 's|-I${libdir}/giomm-$apiVers/include||' \
		$developLibDir/pkgconfig/giomm-$apiVers.pc

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	ninja -C build test
}
