dnl CF_ADD_LIB_AFTER version: 4 updated: 2025/06/14 06:46:23
dnl ----------------
dnl Add a given library after another, e.g., following the one it satisfies a
dnl dependency for.
dnl
dnl $1 = the first library
dnl $2 = its dependency
dnl $3 = variable to update (default $LIBS)
AC_DEFUN([CF_ADD_LIB_AFTER],[
cf_add_libs="[$]ifelse($3,,LIBS,[$3])"
CF_VERBOSE(...before $cf_add_libs)
for cf_add_1lib in $2; do
	# filter duplicates
	cf_found_2lib=no
	for cf_add_2lib in $cf_add_libs; do
		if test "x$cf_add_1lib" = "x$cf_add_2lib"; then
			cf_found_2lib=yes
			break
		fi
	done
	# if not a duplicate, find the dependent library
	if test "$cf_found_2lib" = no
	then
		cf_found_2lib=no
		cf_add_2libs=
		for cf_add_2lib in $cf_add_libs
		do
			test -n "$cf_add_2libs" && cf_add_2libs="$cf_add_2libs "
			cf_add_2libs="$cf_add_2libs$cf_add_2lib"
			if test "x$cf_add_2lib" = "x$1"
			then
				cf_found_2lib=yes
				cf_add_2libs="$cf_add_2libs $cf_add_1lib"
			fi
		done
		if test "$cf_found_2lib" = yes
		then
			cf_add_libs="$cf_add_2libs"
		else
			CF_VERBOSE(...missed $1)
		fi
	fi
done
CF_VERBOSE(...after  $cf_add_libs)
ifelse($3,,LIBS,[$3])="$cf_add_libs"
])dnl
