public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/2] toolchain-funcs.eclass: rework _tc-getPROG to accept a colon-separated list of default programs
@ 2017-06-01 18:03 Mike Gilbert
  2017-06-01 18:03 ` [gentoo-dev] [PATCH 2/2] toolchain-funcs.eclass: use gcc-{ar,nm,ranlib} when available Mike Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Gilbert @ 2017-06-01 18:03 UTC (permalink / raw
  To: gentoo-dev; +Cc: toolchain

---
 eclass/toolchain-funcs.eclass | 39 +++++++++++++++++++++++++++++++--------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index a0c359a950b2..b402a9ff2780 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -17,12 +17,13 @@ _TOOLCHAIN_FUNCS_ECLASS=1
 
 inherit multilib
 
-# tc-getPROG <VAR [search vars]> <default> [tuple]
+# tc-getPROG <VAR [search vars]> [prog:...]<default> [tuple]
 _tc-getPROG() {
-	local tuple=$1
-	local v var vars=$2
-	local prog=( $3 )
+	local IFS
 
+	IFS=' 	
+'
+	local v var vars=$2
 	var=${vars%% *}
 	for v in ${vars} ; do
 		if [[ -n ${!v} ]] ; then
@@ -32,10 +33,32 @@ _tc-getPROG() {
 		fi
 	done
 
-	local search=
-	[[ -n $4 ]] && search=$(type -p $4-${prog[0]})
-	[[ -z ${search} && -n ${!tuple} ]] && search=$(type -p ${!tuple}-${prog[0]})
-	[[ -n ${search} ]] && prog[0]=${search##*/}
+	local tuple=$4
+	[[ -z ${tuple} ]] && tuple=${!1}
+
+	IFS=:
+	local proglist=( $3 )
+
+	IFS=' 	
+'
+	local p prog search=
+	for p in "${proglist[@]}"; do
+		# Look for tuple-prog first
+		prog=( ${p} )
+		search=$(type -p "${tuple}-${prog[0]}")
+		if [[ -n ${search} ]]; then
+			prog[0]="${tuple}-${prog[0]}"
+			break
+		fi
+	done
+	if [[ -z ${search} ]]; then
+		# Then try prog with no prefix
+		for p in "${proglist[@]}"; do
+			prog=( ${p} )
+			search=$(type -p "${prog[0]}")
+			[[ -n ${search} ]] && break
+		done
+	fi
 
 	export ${var}="${prog[*]}"
 	echo "${!var}"
-- 
2.13.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-01 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-01 18:03 [gentoo-dev] [PATCH 1/2] toolchain-funcs.eclass: rework _tc-getPROG to accept a colon-separated list of default programs Mike Gilbert
2017-06-01 18:03 ` [gentoo-dev] [PATCH 2/2] toolchain-funcs.eclass: use gcc-{ar,nm,ranlib} when available Mike Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox