Module Name:    othersrc
Committed By:   agc
Date:           Tue Mar 18 00:42:45 UTC 2014

Modified Files:
        othersrc/external/bsd/bsd-pkg-config/dist: bsd-pkg-config.sh

Log Message:
Update bsd-pkg-config to version 20140317

Changes from previous version:

+ recurse into other packages found, so that the whole dependency
  tree of cflags/libs is displayed
+ also look in system and X11R7 prefixes for pkgconfig files
+ remove duplicates on output in --cflags and --libs* output, but
  preserve the order


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh
diff -u othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh:1.2 othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh:1.3
--- othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh:1.2	Sat Feb 23 18:27:03 2013
+++ othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh	Tue Mar 18 00:42:45 2014
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# $NetBSD: bsd-pkg-config.sh,v 1.2 2013/02/23 18:27:03 agc Exp $
+# $NetBSD: bsd-pkg-config.sh,v 1.3 2014/03/18 00:42:45 agc Exp $
 
 # Copyright (c) 2012 Alistair Crooks <[email protected]>
 # All rights reserved.
@@ -26,21 +26,31 @@
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-prefix=/usr/pkg
-version=20120813
+version=20140317
+
+# find the base of the .pc file
+findbase() {
+	for b in ${pkgbase} ${srcbase} ${xbase}; do
+		if [ -f ${b}/$1.pc ]; then
+			echo ${b}
+			return 0
+		fi
+	done
+	exit 1
+}
 
 # invoked as showvalues "type" package
 showvalues() {
-	local val=$1
-	local pkg=$2
-	if [ -f ${base}/${pkg}.pc ]; then
-		mf="$(awk -v s="${val}" '
+	b=$(findbase $2)
+	if [ -f ${b}/$2.pc ]; then
+		mf="$(awk -v s="$1" '
 			/[A-Za-z_0-9]+=.*/ { print }
 			$1 == s { split($0, a, ":"); print "t=\"" a[2] "\"" }
-			END { print "all:\n\t@echo -n ${t}" }' ${base}/${pkg}.pc)"
+			END { print "all:\n\t@echo -n ${t}" }' ${b}/$2.pc)"
 		echo "${mf}" | make -f -
+		return 0
 	else
-		echo "Package \"${pkg}\" not installed" >&2
+#		echo "Package \"${pkg}\" not installed" >&2
 		exit 1
 	fi
 }
@@ -49,11 +59,12 @@ showvalues() {
 showvar() {
 	local var=$1
 	local pkg=$2
-	if [ -f ${base}/${pkg}.pc ]; then
+	b=$(findbase ${pkg})
+	if [ -f ${b}/${pkg}.pc ]; then
 		mf="$(awk -v s="${var}" '
 			/[A-Za-z_0-9]+=.*/ { print }
 			/[A-Za-z_0-9]+:.*/ { next }
-			END { print "all:\n\t@echo -n ${" s "}" }' ${base}/${pkg}.pc)"
+			END { print "all:\n\t@echo -n ${" s "}" }' ${b}/${pkg}.pc)"
 		echo "${mf}" | make -f -
 	else
 		echo "Package \"${pkg}\" not installed" >&2
@@ -81,6 +92,31 @@ expandpkgname() {
 	esac
 }
 
+# get the requires lines (recursively)
+showreqs() {
+	out=$(showvalues "Requires:" $1)
+	for word in ${out}; do
+		out="${out} $(showreqs ${word})"
+	done
+	echo "${out}"
+}
+
+# show the values for $1 (recursively) for pkg $2
+recursevalues() {
+	out="$(showvalues $1 $2)"
+	requires=$(showreqs $2)
+	for req in ${requires}; do
+		out="${out} $(recursevalues $1 ${req})"
+	done
+	echo ${out}
+}
+
+# remove duplicates in the list (but without reordering)
+rmdups() {
+	echo $(echo "$1" | tr ' ' '\n' | awk '!cnt[$0]++ { m[c++] = $0 } END { for (i = 0 ; i < c ; i++) printf("%s ", m[i]) }')
+}
+
+prefix=/usr/pkg
 actions=""
 while [ $# -gt 0 ]; do
 	case "$1" in
@@ -95,26 +131,25 @@ while [ $# -gt 0 ]; do
 	shift
 done
 
-base=${prefix}/lib/pkgconfig
+pkgbase=${prefix}/lib/pkgconfig
+srcbase=/usr/lib/pkgconfig
+xbase=/usr/X11R7/lib/pkgconfig
 
 for action in ${actions}; do
 	pkgname=$(expandpkgname "$1") || exit 1
 	case "${action}" in
 	--cflags)
-		showvalues "Cflags:" ${pkgname}
+		rmdups "$(recursevalues 'Cflags:' ${pkgname})"
 		;;
 	--exists)
-		if [ -f ${base}/${pkgname}.pc ]; then
-			exit 0
-		else
-			exit 1
-		fi
+		b=$(findbase ${pkgname})
+		exit $(test -f ${b}/${pkgname}.pc)
 		;;
 	--libs)
-		showvalues "Libs:" ${pkgname}
+		rmdups "$(recursevalues 'Libs:' ${pkgname})"
 		;;
 	--libs-only-*)
-		libs=$(showvalues "Libs:" ${pkgname})
+		libs=$(rmdups "$(recursevalues 'Libs:' ${pkgname})")
 		for l in ${libs}; do
 			case "${action}" in
 			--libs-only-L)

Reply via email to