Subject: Re: CVS commit: pkgsrc/mk
To: Alistair Crooks <agc@pkgsrc.org>
From: Johnny C. Lam <jlam@NetBSD.org>
List: pkgsrc-changes
Date: 05/13/2005 12:23:51
Alistair Crooks wrote:
> On Thu, May 12, 2005 at 09:56:11PM +0000, Johnny C. Lam wrote:
>>
>>Log Message:
>>Adding "${GREP} ." into pipeline that I inadvertently left out when
>>moving the EVAL_PREFIX code from bsd.pkg.mk to find-prefix.mk.
> 
> My pkgsrccon slide may have given the wrong impression - I assume the
> grep stage is in there to catch the occurrence when awk tries to print
> a second argument which doesn't exist.  What I was trying to convey
> was that it might be better to do that in awk itself:  i.e.
> 
> [13:24:10] agc@sys3 ...pkgsrc/graphics/tiff 49 > pkg_info -qp libtool-base | awk '{ if (NF > 1) { print $2; exit }}'
> /usr/pkg
> [13:24:35] agc@sys3 ...pkgsrc/graphics/tiff 50 > echo "@cwd" | awk '{ if (NF > 1) { print $2; exit }}'
> [13:24:56] agc@sys3 ...pkgsrc/graphics/tiff 51 >
> 
> If I've picked up the problem set wrongly, please say.

I discovered the grep is there to return non-zero if pkg_info doesn't 
output anything because awk will always return zero regardless of 
whether it prints anything or not.  If the grep returns non-zero, then 
echoing the default prefix will happen.  It's easy to do it all from 
within awk, but I was too lazy to do that last night ;)  I guess 
something like the following will achieve the same effect:

	awk '{ print $2; exit 0; } END { exit 1; }'

I'll do some tests and tighten up that bit of code after I finish up 
with the new tools framework.

	Cheers,

	-- Johnny Lam <jlam@NetBSD.org>