Module Name:    othersrc
Committed By:   agc
Date:           Wed Mar 19 04:08:04 UTC 2014

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

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

Changes from previous version:

+ be a bit smarter in the awk command in the rmdups functionality
+ add --list-all command
+ support for PKG_CONFIG_PATH
+ optimise queries just a tad


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
    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.3 othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh:1.4
--- othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh:1.3	Tue Mar 18 00:42:45 2014
+++ othersrc/external/bsd/bsd-pkg-config/dist/bsd-pkg-config.sh	Wed Mar 19 04:08:04 2014
@@ -1,8 +1,8 @@
 #! /bin/sh
 
-# $NetBSD: bsd-pkg-config.sh,v 1.3 2014/03/18 00:42:45 agc Exp $
+# $NetBSD: bsd-pkg-config.sh,v 1.4 2014/03/19 04:08:04 agc Exp $
 
-# Copyright (c) 2012 Alistair Crooks <a...@netbsd.org>
+# Copyright (c) 2012,2013,2014 Alistair Crooks <a...@netbsd.org>
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -26,11 +26,11 @@
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-version=20140317
+version=20140318
 
 # find the base of the .pc file
 findbase() {
-	for b in ${pkgbase} ${srcbase} ${xbase}; do
+	for b in ${pathdirs}; do
 		if [ -f ${b}/$1.pc ]; then
 			echo ${b}
 			return 0
@@ -39,18 +39,17 @@ findbase() {
 	exit 1
 }
 
-# invoked as showvalues "type" package
+# invoked as showvalues "type" base package
 showvalues() {
-	b=$(findbase $2)
-	if [ -f ${b}/$2.pc ]; then
+	if [ -f $2/$3.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}" }' ${b}/$2.pc)"
+			END { print "all:\n\t@echo -n ${t}" }' $2/$3.pc)"
 		echo "${mf}" | make -f -
 		return 0
 	else
-#		echo "Package \"${pkg}\" not installed" >&2
+#		echo "Package \"$3\" not installed" >&2
 		exit 1
 	fi
 }
@@ -77,13 +76,13 @@ expandpkgname() {
 	local inname="$1"
 	case "${inname}" in
 	*\>*|*\<*)
-		constraint=$(echo "${inname}" | sed -e 's| ||g')
-		name=${inname%% *}
-		have="${name}-$(showvalues "Version:" ${inname})"
+		constraint=${inname}
+		name=${inname%%>*}; name=${name%%<*}
+		have="${name}-$(showvalues "Version:" $(findbase ${name}) ${name})"
 		have=$(echo "${have}" | sed -e 's| ||g')
 		got=$(pkg_admin pmatch "${constraint}" "${have}")
 		if [ $? -ne 0 ]; then
-			echo "Constraint ${constraint} not matched by ${have}" >&2
+			echo "Constraint ${constraint} not matched by ${have} for ${inname}" >&2
 			exit 1
 		fi
 		echo ${name}
@@ -94,62 +93,99 @@ expandpkgname() {
 
 # get the requires lines (recursively)
 showreqs() {
-	out=$(showvalues "Requires:" $1)
+	out=$(showvalues "Requires:" $(findbase $1) $1 | sed -e 's| >|>|g' -e 's| <|<|g' -e 's|= |=|g')
 	for word in ${out}; do
 		out="${out} $(showreqs ${word})"
 	done
-	echo "${out}"
+	case "${out}" in
+	"")	;;
+	*)	echo "${out}"
+	esac
 }
 
-# show the values for $1 (recursively) for pkg $2
-recursevalues() {
-	out="$(showvalues $1 $2)"
-	requires=$(showreqs $2)
+# get the requires recursively
+recursereqs() {
+	out=""
+	requires="$(showreqs $1)"
 	for req in ${requires}; do
-		out="${out} $(recursevalues $1 ${req})"
+		case "${req}" in
+		*\>*|*\<*)	r=$(expandpkgname "${req}") ;;
+		*)		r=${req} ;;
+		esac
+		test -z "${r}" && continue
+		out="${out} ${r}"
+	done
+	case "${out}" in
+	"")	;;
+	*)	echo "${out}" ;;
+	esac
+}
+
+# get the libraries, $1 == pc, $2 == search
+findvalues() {
+	for lib in $1; do
+		out="${out} $(showvalues $2 $(findbase ${lib}) ${lib})"
 	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]) }')
+	echo "$1" | awk -v RS="$2" '!cnt[$0]++ { s = s " " $0 } END { printf("%s", s) }'
+}
+
+# list one pkgconfig file's details
+listpc() {
+	a=${1##*/}
+	awk -v pc=${a%%.pc} '
+BEGIN { s = pc "\t\t\t" }
+$1 == "Name:" { sub($1, ""); s = s $0 " - " }
+$1 == "Description:" { sub($1, ""); s = s $0 }
+END { print s }' $1
+}
+
+getpkgconfig() {
+	reqs="$(recursereqs $1)"
+	reqs="$(rmdups "${reqs}" " ")"
+	vals="$(findvalues "$1 ${reqs}" $2)"
+	echo "$(rmdups "${vals}" " ")"
 }
 
 prefix=/usr/pkg
 actions=""
 while [ $# -gt 0 ]; do
 	case "$1" in
-	--cflags|--exists|--libs*|--modversion|--static|--variable=*|--version)
+	--cflags|--exists|--libs*|--list-all|--modversion|--static|--variable=*|--version)
 		actions="${actions} $1" ;;
 	--prefix=*)
 		prefix=${1#--prefix=} ;;
 	--prefix)
 		prefix=$2; shift ;;
+-v) set -x ;; # XXX
 	*)	break ;;
 	esac
 	shift
 done
 
-pkgbase=${prefix}/lib/pkgconfig
-srcbase=/usr/lib/pkgconfig
-xbase=/usr/X11R7/lib/pkgconfig
+PKG_CONFIG_PATH=${PKG_CONFIG_PATH:="${prefix}/lib/pkgconfig:${prefix}/data/pkgconfig"}
+d="$(echo "${prefix}/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11R7/lib/pkgconfig:${PKG_CONFIG_PATH}")"
+pathdirs=$(rmdups "${d}" ":")
 
 for action in ${actions}; do
 	pkgname=$(expandpkgname "$1") || exit 1
 	case "${action}" in
 	--cflags)
-		rmdups "$(recursevalues 'Cflags:' ${pkgname})"
+		getpkgconfig ${pkgname} 'Cflags:'
 		;;
 	--exists)
 		b=$(findbase ${pkgname})
 		exit $(test -f ${b}/${pkgname}.pc)
 		;;
 	--libs)
-		rmdups "$(recursevalues 'Libs:' ${pkgname})"
+		getpkgconfig ${pkgname} 'Libs:'
 		;;
 	--libs-only-*)
-		libs=$(rmdups "$(recursevalues 'Libs:' ${pkgname})")
+		libs=$(getpkgconfig ${pkgname} 'Libs:')
 		for l in ${libs}; do
 			case "${action}" in
 			--libs-only-L)
@@ -159,7 +195,8 @@ for action in ${actions}; do
 				;;
 			--libs-only-other)
 				case "${l}" in
-				-W*|-R*)	echo -n "${l} " ;;
+				-L*|-l*)	;;
+				*)		echo -n "${l} " ;;
 				esac
 				;;
 			--libs-only-l)
@@ -169,13 +206,25 @@ for action in ${actions}; do
 				;;
 			esac
 		done
+		echo ""
+		;;
+	--list-all)
+		for d in ${pathdirs}; do
+			if [ ! -d ${d} ]; then
+				continue
+			fi
+			for pc in ${d}/*.pc; do
+				listpc ${pc}
+			done
+		done
 		;;
 	--modversion)
-		showvalues "Version:" ${pkgname}
+		showvalues "Version:" $(findbase ${pkgname}) ${pkgname}
 		;;
 	--static)
-		showvalues "Libs:" ${pkgname}
-		showvalues "Libs.private:" ${pkgname}
+		showvalues "Libs:" $(findbase ${pkgname}) ${pkgname}
+		showvalues "Libs.private:" $(findbase ${pkgname}) ${pkgname}
+		echo ""
 		;;
 	--variable=*)
 		showvar ${action#*=} ${pkgname}
@@ -187,5 +236,4 @@ for action in ${actions}; do
 		;;
 	esac
 done
-echo ""
 exit 0

Reply via email to