summaryrefslogtreecommitdiff
path: root/mk/buildlink3/buffer
blob: 52a91a79732d6a1b47ee5e0d56277c57e0b51205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# $NetBSD: buffer,v 1.3 2004/01/07 17:40:36 jlam Exp $
#
# Fill the buffer if it's empty, and shift the arguments.  The next
# argument checked by the cache and logic files is taken from the
# first non-empty buffer.  We avoid using "eval" so that we can skip
# having to specially quote the argument using "sed".
#
case ${buf1}${buf2}${buf3}${buf4}${buf5} in
"")
	arg="$1"; shift
	#
	# Marshall any group of consecutive arguments into a single
	# $arg to be checked in the cache and logic files.
	#
	. $marshall
	#
	# Fill the buffers from $arg.
	#
	case $arg in
	-Wl,-R*:*|-Wl,-rpath,*:*|-Wl,-rpath-link,*:*|\
	-Wl,--rpath,*:*|-Wl,--rpath-link,*:*)
		#
		# Change "-Wl,-R/path1:/path2:/path3" into
		# "-Wl,-R/path1 -Wl,-R/path2 -Wl,-R/path3" so that
		# they can be checked correctly in the cache and logic
		# files.
		#
		case $arg in
		-Wl,-R*)		R="-Wl,-R" ;;
		-Wl,-rpath,*)		R="-Wl,-rpath," ;;
		-Wl,-rpath-link,*)	R="-Wl,-rpath-link," ;;
		-Wl,--rpath,*)		R="-Wl,--rpath," ;;
		-Wl,--rpath-link,*)	R="-Wl,--rpath-link," ;;
		esac
		arg=`$echo "X$arg" | $Xsed -e "s|^"$R"||g"`
		allargs="$@"
		save_IFS="${IFS}"; IFS=":"
		dirlist=
		set -- $arg
		while $test $# -gt 0; do
			case "$dirlist" in
			"$1"|"$1 "*) ;;
			*" $1 "*|*" $1") ;;
			*)	dirlist="$dirlist $1"
				if   $test -z "$buf1"; then buf1="$R$1"
				elif $test -z "$buf2"; then buf2="$R$1"
				elif $test -z "$buf3"; then buf3="$R$1"
				elif $test -z "$buf4"; then buf4="$R$1"
				elif $test -z "$buf5"; then buf5="$R$1"
				else exit 2
				fi
				;;
			esac
			shift
		done
		IFS="${save_IFS}"
		if $test -n "$allargs"; then
			set -- $allargs
		fi
		;;
	*)
		if   $test -z "$buf1"; then buf1="$arg"
		elif $test -z "$buf2"; then buf2="$arg"
		elif $test -z "$buf3"; then buf3="$arg"
		elif $test -z "$buf4"; then buf4="$arg"
		elif $test -z "$buf5"; then buf5="$arg"
		else exit 2
		fi
		;;
	esac
	;;
esac
#
# Re-fetch $arg from the first non-empty buffer.
#
if   $test -n "$buf1"; then arg="$buf1"; buf1=
elif $test -n "$buf2"; then arg="$buf2"; buf2=
elif $test -n "$buf3"; then arg="$buf3"; buf3=
elif $test -n "$buf4"; then arg="$buf4"; buf4=
elif $test -n "$buf5"; then arg="$buf5"; buf5=
fi