### this file is sourced not run
PKGVER=2.74.5
PKGBUILD=1
PKGARCH=x86_64

# source: BLFS 11.3
TARBALL=glib-$PKGVER.tar.xz
MD5SUM=7561501d9f63f3418ddb23d2903cc968
SRC_URL=https://download.gnome.org/sources/glib/2.74/$TARBALL
BUNDLE=

SLACKREQ='libffi libpcre2 libattr dbus'
SLACKDESC="glib: glib $PKGVER (GTK low-level library)  
glib:  
glib: The GLib package contains a low-level libraries useful for providing 
glib: data structure handling for C, portability wrappers and interfaces for 
glib: such runtime functionality as an event loop, threads, dynamic loading 
glib: and an object system.  
glib: 
glib: 
glib: 
glib: 
glib:
"

DEBUG= # yes to enable debug

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/glib* &&

	# BLFS 11.3 patch to suppress warnings
	patch -Np1 -i ../pkg/glib-2.74.5-skip_warnings-1.patch &&

	# Show /mnt and work without GVFS
	patch -Np1 -i ../pkg/jemimah-glib-patches-2.74.5.patch &&

	# allow bind mounts to show
	patch -Np1 -i ../pkg/allow-bind-mount-2.74.5.patch &&
	
	# fix bug - fixed in upstream already?
	# patch -Np1 -i ../pkg/user-mountable-detect-bug.patch &&

	# new strict enforcement of gparam_spec_is_valid_name crashes many non-compliant old apps
	# so disable it
	patch -Np1 -i ../pkg/dont-crash-on-gparam-spec-invalid-name.patch &&

	true
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/glib* &&

	export LANG=en_US.utf8 # this is required by python3, which is used by gtk-doc
	export CFLAGS="$CFLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CAST_CHECKS -DNDEBUG"

	# we want -g permanently, -O0 when debugging
	CFLAGS="$CFLAGS -g"
	[ $DEBUG ] && CFLAGS="$CFLAGS -O0"

	# The old autoconf way
<< "EOF"
	CONFFLAGS="$CONFFLAGS --with-pcre=system --enable-gtk-doc --enable-gtk-doc-html
		--disable-libmount" # glib's own parsing code is good. No need libmount.
	
	NOCONFIGURE=yes ./autogen.sh &&
	pkg_build_autoconf &&
EOF

	# The new meson/ninja way
	
	# james patch 2.74.5 - doc: kill gdbus_example when we build without tests
	sed -i -e '/gdbus.*example/ s/^/#/' docs/reference/gio/meson.build &&
	# appease gcc 12.2.x
	CFLAGS="$CFLAGS -Wno-declaration-after-statement" &&
	
	MESONFLAGS="$MESONFLAGS \
		--buildtype=release \
		-Dlibmount=disabled \
		-Dtests=false       \
		-Dman=true \
		-Dgtk_doc=true \
		-Dglib_assert=false \
	" &&	
	pkg_build_meson &&

	# BLFS 11.3: if we don't build gtk-doc, copy the xml docs
	#mkdir -p /usr/share/doc/glib-$PKGVER &&
	#cp -r ../docs/reference/{gio,glib,gobject} /usr/share/doc/glib-$PKGVER &&
	
	# keep debug symbols in devx
	cd /usr/$LIBDIR &&
	for LIB in \
		libgio-2.0.so.0.7400.5     \
		libglib-2.0.so.0.7400.5    \
		libgmodule-2.0.so.0.7400.5 \
		libgobject-2.0.so.0.7400.5 \
		libgthread-2.0.so.0.7400.5;
	do
		objcopy --only-keep-debug $LIB $LIB.dbg &&
		strip --strip-unneeded $LIB &&
		objcopy --add-gnu-debuglink=$LIB.dbg $LIB || return 1
	done &&

	pkg_build_slackdesc
}


