# $NetBSD: cmd-sink-osf1-cc,v 1.2 2006/11/03 07:28:53 rillig Exp $

# Empty out the command buffer and build up the command line in $cmd.
osf1runpath=
while ! queue_is_empty cmdbuf; do
	pop_queue cmdbuf arg
	$debug_log $wrapperlog "    (cmd-sink-osf1-cc) pop:  $arg"
	case $arg in
	##############################################################
	# OSF1 ld doesn't support multiple rpath parameters, accumulate
	# them into a single -rpath /path1:/path2:...:pathn
	##############################################################
	-rpath)
		pop_queue cmdbuf dir
		case $osf1runpath in
		"")	osf1runpath="$dir" ;;
		*)	osf1runpath="$osf1runpath:$dir" ;;
		esac
		$debug_log $wrapperlog "    (cmd-sink-osf1-cc) drop: $dir [adding to osf1runpath]"
	;;

	-R*|-Wl,-R*|-Wl,-rpath,*|-Wl,-rpath-link,*|-Wl,--rpath,*)
		case $arg in
		-R*)			R="-R" ;;
		-Wl,-R*)		R="-Wl,-R" ;;
		-Wl,-rpath,*)		R="-Wl,-rpath," ;;
		-Wl,-rpath-link,*)	R="-Wl,-rpath-link," ;;
		-Wl,--rpath,*)		R="-Wl,--rpath," ;;
		esac
		dir="${arg#$R}"
		case $osf1runpath in
		"")	osf1runpath="$dir" ;;
		*)	osf1runpath="$osf1runpath:$dir" ;;
		esac
		$debug_log $wrapperlog "    (cmd-sink-osf1-cc) drop: $dir [adding to osf1runpath]"
		;;
	-Wl,-h*)
		arg="-Wl,-soname"${arg#"-Wl,-h"}
		$debug_log $wrapperlog "    (cmd-sink-osf1-cc) pop: $arg"
		. $buildcmd
		;;
	*)
		. $buildcmd
		;;
	esac
done

if $test -n "$osf1runpath"; then
	arg="-Wl,-rpath,$osf1runpath"
	$debug_log $wrapperlog "    (cmd-sink-osf1-cc) pop: $arg [aggregate]"
	. $buildcmd
fi