helpAutoconf - Support: sr #110657, Autoconf configure script...

 
 

sr #110657: Autoconf configure script considers absence of usable grep a fatal error, although it only uses egrep thereafter

Submitter:  Alain Knaff <alainknaff>
Submitted:  Sun 15 May 2022 06:11:13 PM UTC
 
Category:  None Priority:  1 - Later
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Operating System:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Thu 09 Jun 2022 12:59:50 AM UTC, comment #12: 

comment #11:

> As attached, it works.


OK, I installed a patch along those lines into savannah master. Closing the bug report.

Paul Eggert <eggert>
Project Administrator
Wed 08 Jun 2022 09:54:51 PM UTC, comment #11: 

comment #10:

> This patch works great, thanks :-)
>


Sorry, I misspoke. The patch actually fails to set the variable EGREP_TRADITIONAL (it only sets ac_cv_path_EGREP_TRADITIONAL), so all egrep checks later fail, just as if the search expression was not found.

As attached, it works.

(file #53286)

Alain Knaff <alainknaff>
Wed 08 Jun 2022 08:56:22 PM UTC, comment #10: 

comment #9:

> comment #8:

[...]

> > egrep '(-z)' </etc/profile
>
> That won't work if the pattern contains back-references, since it'll mess up the numbering.


Indeed, forgot about that.

> However, we can prepend '.?' to the pattern; this should work. How about the attached patch instead?
>
> (file #53284)


This patch works great, thanks :-)

Alain Knaff <alainknaff>
Wed 08 Jun 2022 05:45:08 PM UTC, comment #9: 

comment #8:

> there is another way than -e to escape that dash: simply put a pair of parenthesis around the search string:
>
> egrep '(-z)' </etc/profile


That won't work if the pattern contains back-references, since it'll mess up the numbering. However, we can prepend '.?' to the pattern; this should work. How about the attached patch instead?

(file #53284)

Paul Eggert <eggert>
Project Administrator
Mon 06 Jun 2022 09:48:15 PM UTC, comment #8: 

comment #6:

> How about the attached patch instead?


Unfortunately, this patch doesn't work ... due to another peculiarity of UnixPC's egrep which had escaped earlier: for some weird reason, if -e is used, egrep doesn't support grepping in stdin, but only in files given on command line.

i.e. egrep -e root </etc/passwd doesn't work.

However, egrep -e root /etc/passwd does work, and so does egrep root </etc/passwd

There seems no easy fix for it, because the use case (grepping in cpp's output) does indeed involve grepping from stdin. Catching cpp's output into a file would be needlessly cumbersome, so we might need to ponder whether -e is indeed needed for AC_EGREP_CPP. I think we do agree that multiple -e options are not needed for AC_EGREP_CPP. So the only reason why -e is needed is to search for strings that start with a dash. But there is another way than -e to escape that dash: simply put a pair of parenthesis around the search string:

egrep '(-z)' </etc/profile

Alain Knaff <alainknaff>
Sun 05 Jun 2022 09:38:47 PM UTC, comment #7: 

comment #6:

> How about the attached patch instead?

Oops, that patch had a stray -E so I removed it. Revised patch attached.

(file #53277)

Paul Eggert <eggert>
Project Administrator
Sun 05 Jun 2022 09:32:51 PM UTC, comment #6: 

comment #5:

> the only reason why AC_PROG_EGREP is brought in (in my case) is due to the macro AC_EGREP_CPP, which does not ever use the -e option

AC_EGREP_CPP should use -e though, since it should work even if the pattern begins with '-'.

How about the attached patch instead? It fixes that bug with '-', it defines a new macro _AC_PROG_EGREP_TRADITIONAL which I hopes works as well on the AT&T UnixPC as it does on today's platforms, and it avoids messing with AC_PROG_EGREP due to the usual worries about breaking old stuff. This macro name begins with underscore so it's private (I don't want users relying on it).

> So this should also work on platforms were egrep doesn't support -e either.

We don't know of any such platforms so it should be OK to not worry about that.

(file #53276)

Paul Eggert <eggert>
Project Administrator
Sat 04 Jun 2022 06:02:58 PM UTC, comment #5: 

comment #4:

> For the record, despite this having been marked "won't do", I would consider and review a patch (against current development trunk) that would make configure scripgs set $EGREP and $GREP to `egrep` on systems where `egrep -e` works but `grep -E -e` doesn't work.  It's just that neither Paul nor I have the time, nor the necessary test environment, to develop such a patch.


Hi,

Thanks for "opening the way" for a patch :-)

Attached is a patch which addresses the issue (the patch is against 2.71, as available in Debian testing).

It removes the dependency of AC_PROG_EGREP on AC_PROG_GREP , and does the "acceptable" check itself instead. If no acceptable grep is found (for use with -E), it falls back on searching for an acceptable egrep.

Moreover, I noticed that the only reason why AC_PROG_EGREP is brought in (in my case) is due to the macro AC_EGREP_CPP, which does not ever use the -e option (to supply multiple pattern, or pattern that start with a dash).

So the patch has an additional fix, by defining an AC_PROG_EGREP_SIMPLE which relaxes the requirements. It now only needs to conform to extended regexp syntax, and work with long lines, but doesn't need to support -e.

So this should also work on platforms were egrep doesn't support -e either.

Then, in my example, AC_EGREP_CPP is only needed by AC_EGREP_HEADER, itself only needed by AC_TYPE_UID_T.
And AC_TYPE_UID_T has a FIXME comment at the top saying "Rewrite using AC_CHECK_TYPE" :-)

(file #53274)

Alain Knaff <alainknaff>
Tue 17 May 2022 10:12:47 PM UTC, comment #4: 

For the record, despite this having been marked "won't do", I would consider and review a patch (against current development trunk) that would make configure scripgs set $EGREP and $GREP to `egrep` on systems where `egrep -e` works but `grep -E -e` doesn't work.  It's just that neither Paul nor I have the time, nor the necessary test environment, to develop such a patch.

Zack Weinberg <zackw>
Project Administrator
Tue 17 May 2022 09:59:31 PM UTC, comment #3: 

OK, I think I see what's happening now; you have an egrep that's good enough, but you also want to test for header files and Autoconf's header-file tests insist on robust 'grep' because they prefer to use 'grep -E', as egrep was removed from POSIX a long time ago.

For this sort of thing, I suggest either (a) installing and using a better 'grep' like GNU grep, or (b) running something like './configure ac_cv_path_GREP=/usr/bin/grep ac_cv_path_egrep=/usr/bin/egrep' in the hopes that your system grep and egrep are good enough for 'configure'. (a) should be much better in the long run.

I doubt whether we should modify Autoconf to work around this problem, as it should occur only on nonstandard platforms that are no longer supported even by their own suppliers.

Paul Eggert <eggert>
Project Administrator
Tue 17 May 2022 10:10:15 AM UTC, comment #2: 

>> For example, grep does not support -e , but egrep does.
> AC_PROG_GREP looks for a grep that does support -e, so a configure script that uses that should have a $GREP that works, assuming you have one somewhere in your $PATH. (If not, you'll need to get one.)


Unfortunately, my configure script does not use AC_PROG_GREP directly.

Instead, this is brought in via AC_REQUIRE by AC_PROG_EGREP, which itself is required by AC_EGREP_CPP which is required by lots of tests for header files etc.

However, as said in my initial report, grep is actually not used further down in the script (AC_PROG_CPP only needs egrep, not grep). And strangely enough, egrep does support the -e flag on UnixPC.

>> This lack of support of -e makes the configure script fail, although there is a usable egrep.
> Autoconf's 'configure' script doesn't use 'grep -e' anywhere that I can see.


And that is exactly my point. Absence of a feature which is not being used anywhere shouldn't be a fatal error.

> Are you debugging some other 'configure' script that uses 'grep -e'?


No, I've only been debugging the mtools configure script (generated by autoconf) as well as another configure script generated by autoconf from a mostly empty configure.in

> If so,it should use AC_PROG_GREP


I'm not really sure how adding an explicit AC_PROG_GREP would solve the problem brough by the implicit usage (due to AC_REQUIRE, see above)

> and "$GREP -e" and you should have a grep in your $PATH that works.


Unfortunately, this museum piece :-) doesn't have a grep where -e works, but it does haven an egrep that supports -e. The issue I have is that the configure script doesn't actually need a grep that supports -e (apart from this test itself), and only needs egrep with -e. Neither does my own compilation need grep -e.

(I just hope you didn't get confused by the existence of an -E (capital E) option that makes grep behave like egrep (i.e. uses extended regexp syntax). The -e that I am talking about here is lower case -e that makes allows to use regular expressions that start with a dash (-), or to use multiple regular expressions)

Alain Knaff <alainknaff>
Mon 16 May 2022 05:48:00 AM UTC, comment #1: 

> For example, grep does not support -e , but egrep does.

AC_PROG_GREP looks for a grep that does support -e, so a configure script that uses that should have a $GREP that works, assuming you have one somewhere in your $PATH. (If not, you'll need to get one.)

> This lack of support of -e makes the configure script fail, although there is a usable egrep.

Autoconf's 'configure' script doesn't use 'grep -e' anywhere that I can see. Are you debugging some other 'configure' script that uses 'grep -e'? If so,it should use AC_PROG_GREP and "$GREP -e" and you should have a grep in your $PATH that works.

Paul Eggert <eggert>
Project Administrator
Sun 15 May 2022 06:11:13 PM UTC, original submission:  

Configure scripts generated by autoconf first test for a "usable" grep (i.e. one which understands the -e option, and supports multiple -e options), and then after that looks for an egrep candidate.

By default it tries to use grep -E for egrep, or if that doesn't work, it tries actual egrep.

During the rest of the script (most scripts in any case, not sure about some exotic tests), $EGREP is only ever used, not $GREP.

This works fine on most platforms, where grep an egrep are the same binary anyways, and change regular expression syntax depending on how they are called.

Not so on AT&T UnixPC, where they are largely independent of each other. Grep seems to be generally the older binary, and generally supports less command line options than egrep.
For example, grep does not support -e , but egrep does.

This lack of support of -e makes the configure script fail, although there is a usable egrep.

Fix: make lack of "usable" grep on non-fatal error (and only try to use egrep directly in that case, rather than grep -E)

Alain Knaff <alainknaff>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #53284:  0001-Fix-bug-AC_EGREP_CPP-with-leading-in-pattern.patch added by eggert (3KiB - text/x-patch - Version 3 of the proposed patch for this problem)
file #53277:  0001-Fix-bug-AC_EGREP_CPP-with-leading-in-pattern.patch added by eggert (3KiB - text/x-patch - AC_EGREP_CPP fix v2)
file #53274:  autoconf-grep.diff added by alainknaff (3KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by zackw (Posted a comment)
  • -email is unavailable- added by eggert (Posted a comment)
  • -email is unavailable- added by alainknaff (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-09 eggert StatusWont Do Done
        Open/ClosedOpen Closed
    2022-06-08 alainknaff Attached File- Added autoconf-egrep-traditional.diff, #53286
    2022-06-08 eggert Attached File- Added 0001-Fix-bug-AC_EGREP_CPP-with-leading-in-pattern.patch, #53284
    2022-06-05 eggert Attached File- Added 0001-Fix-bug-AC_EGREP_CPP-with-leading-in-pattern.patch, #53277
    2022-06-05 eggert Attached File#53276 Removed
    2022-06-05 eggert Attached File- Added 0001-Fix-bug-AC_EGREP_CPP-with-leading-in-pattern.patch, #53276
    2022-06-04 alainknaff Attached File- Added autoconf-grep.diff, #53274
    2022-05-17 eggert Priority3 - Low 1 - Later
    2022-05-17 eggert StatusNeed Info Wont Do
    2022-05-16 eggert Priority5 - Normal 3 - Low
        StatusNone Need Info

    Back to the top


    Powered by Savane 3.9