Subject: Re: bug#57028: 29.0.50; Build error with configure when brew installed 12.1 libgccjit on macos

From: Mark Barton <[email-masked]>
Date: Sun, 7 Aug 2022 09:55:10 -0700

> On Aug 7, 2022, at 1:49 AM, Eli Zaretskii <[email-masked]> wrote:
> 
>> From: Mark Barton <[email-masked]>
>> Date: Sun, 7 Aug 2022 00:15:09 -0700
>> Cc: [email-masked]
>> 
>> On Aug 6, 2022, at 11:29 PM, Eli Zaretskii <[email-masked]> wrote:
>> 
>> I hope some macOS expert could chime in and clarify the issues enough
>> for us to make the decisions.
>> 
>> 57015 has a more precise solution than mine in 57028 since it uses readlink to follow the symbolic link to
>> always get the path to the actual library. 
> 
> But we then established that 'readlink' cannot be relied upon to exist
> on any random system.  So AFAIU, that solution cannot be used.

I forgot about grep having the -m parameter to restrict the number of matches. 

Here you see it returns the single directory that would be assigned to the env variable.
(python_training) bartm002@C02FM1E2MD6T ~ % dirname $(brew ls -v libgccjit | grep -m 1 -E 'libgccjit\.(so|dylib)$')
/usr/local/Cellar/libgccjit/12.1.0/lib/gcc/current

Here I show the problem with multiple hits, the dirname result to be assigned is two lines.
(python_training) bartm002@C02FM1E2MD6T ~ % dirname $(brew ls -v libgccjit | grep -m 2 -E 'libgccjit\.(so|dylib)$')
/usr/local/Cellar/libgccjit/12.1.0/lib/gcc/current
/usr/local/Cellar/libgccjit/12.1.0/lib/gcc/12

Either dirname result is good to use, just not both. Adding the "-m 1" to the existing grep would not introduce more dependencies.