export MAJORVER="${PKGVER%%.*}"
abinfo "PostgreSQL major release: $MAJORVER"
if ! [[ "$MAJORVER" =~ ^[0-9]+$ ]] ; then
	abdie "Unexpected major version $MAJORVER."
fi

# Check if PKGDEP actually contains the release we want to point to.
if [ "${PKGDEP/postgresql-$MAJORVER/}" == "$PKGVER" ] ; then
	abdie "PKGDEP isn't updated - Check the defines file."
fi

# TODO: I think this step is not necessary since pkg-config files have the
#       location of the libraries. But this might be required if a user
#       wants to link with libpq without knowing the actual location of
#       libpq - however they must use -I/usr/lib/postgresql-17/include to
#       be able to compile programs that uses PostgreSQL headers.
# Can we supply a pg_config.h that contains the following line?
#
# #warning Please use "pkg-config --libs libpq" to obtain the correct library location
# #error Please use "pkg-config --cflags libpq" to obtain the correct include location
#
# That will produce an error if a user wants to use the header in the
# default location.
abinfo "Deploying shared library symlinks ..."
mkdir -pv "$PKGDIR"/usr/lib
for lib in \
	$(find /usr/lib/postgresql-"$MAJORVER"/lib \
		-maxdepth 1 -type f,l -name 'lib*.so*' -printf '%P\n')
	do
	ln -sv postgresql-"$MAJORVER"/lib/$lib \
		"$PKGDIR"/usr/lib/$lib
done
