# $NetBSD: libtool-post-logic,v 1.3 2003/09/19 22:49:22 jlam Exp $
#
# Workaround software authors that don't follow the libtool
# documentation and link against uninstalled libtool archives with:
#
#	-L../package/source/dir -lfoo
#
# instead of the correct (according to the libtool documentation)
#
#	../package/source/dir/libfoo.la
#
# We convert the former into the latter by remembering all "local"
# directories that are mentioned in -L* arguments to to libtool
# wrapper, and checking to see if <dir>/libfoo.la exists when we see
# "-lfoo" on the libtool command line.

case $arg in
-L.|-L./*|-L..*|-L[!/]*|-L${WRKSRC}*)
	case $fixlibpath in
	yes)
		case $arg in
		*/.libs)
			# ignore -L.../.libs
			;;
		*)
			$echo "*** [buildlink3] Warning: libtool detected $arg" >> $wrapperlog
			$echo "*** [buildlink3] Warning: libtool detected $arg" 1>&2
			lpath=`$echo "X$arg" | $Xsed -e "s/^-L//"`
			case "$rellpath" in
			*"$lpath "*)	;;
			*"$lpath"*)	;;
			*)		rellpath="$rellpath $lpath" ;;
			esac
			addtocache=no
			;;
		esac
		;;
	esac
	;;
-l*)
	case $fixlibpath in
	yes)
		lib=`$echo "X$arg" | $Xsed -e "s/^-l//"`
		for dir in $rellpath; do
			la="$dir/lib$lib.la"
			if $test -f "$la"; then
				$echo "*** [buildlink3] Warning: libtool replaced $arg with $la" >> $wrapperlog
				$echo "*** [buildlink3] Warning: libtool replaced $arg with $la" 1>&2
				arg="$la"
				cachesettings='skipcache=yes'
				break
			fi
		done
		;;
	esac
	addtoprivatecache=yes
	;;
esac
