bugmake - Bugs: bug #13877, Error parsing define/endef when...

 
 

bug #13877: Error parsing define/endef when both are indented using tabs

Submitted by:  None
Submitted on:  Thu 21 Jul 2005 04:46:45 PM UTC  
 
Severity: 3 - NormalItem Group: Bug
Status: Not A BugPrivacy: Public
Assigned to: NoneOpen/Closed: Closed
Component Version: 3.80Operating System: Any
Fixed Release: NoneTriage Status: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 03 Aug 2005 08:45:02 PM UTC, comment #5:

We've reached an agreement that this is not a bug. See the email thread starting at http://www.mail-archive.com/bug-make%40gnu.org/msg03566.html

Paul D. Smith <psmith>
Project Administrator
Tue 02 Aug 2005 01:57:50 PM UTC, comment #4:

Paul,

I'd love to use 3.81, but it has regressed even farther (Savannah #13881).

As a point of reference, we've got about 6 million lines of code with about 3000 makefiles. Everything works fine in 3.76 -- except that the -jN stuff is crippled. Thus, to get full support for -jN, we want to move forward to 3.8x. Regressions appear on numerous fronts from 3.76 functional levels:

1. :: dependencies are processed differently (Savannah #13976)
2. endef can no longer be preceded by tab (Savannah #13877)
3. line numbering issue (Savannah #9058)
4. :: no longer works in pattern targets (Savannah #13881)

#3 is fixed in 3.81. #1, #2, and #4 are serious regressions over previously supported functionality.

Now regarding #2 -- the '<tab>endef' issue. GNUmake supports conditional structures implemented with 'ifdef', 'ifndef', 'ifeq', 'ifneq', 'else', 'endif'. In addition it supports macro definition using 'define' and 'endef'. All of these are considered to be reserved words in GNUmake. With the notable exeception of 'endef' all of the above can be indented using tabs. I've attached a Makefile to #13877 that illustrates this. It looks like:

<tab>ifdef FOO
<tab>endif
<tab>ifndef BAR
<tab>endif
<tab>ifeq ($(FOO),)
<tab>endif
<tab>ifneq ($(BAR),)
<tab>endif
<tab>define macro
<tab><tab>@echo macro text
endef

all: ; $(macro)

All you can see, everything but 'endef' can be indented with tabs. Thus, the requirement that the 'endef' must appear at start of line makes absolutely no sense. It also makes no sense that the 'define' is allowed to be indented using a tab, but that the matching 'endef' cannot be indented similarly with a tab.

Once, you've entered the 'do_define()' function, the only purpose is to find the matching 'endef'. You are known to be in a 'define' statement and the 'define' statement could not be a part of a rule. 'do_define()' should look for the 'endef' followed by any amount/kind of whitespace.

The documentation states: "The 'define' directive is followed on the same line by the name of the variable and nothing more. ... The end of the value is marked by a line containing just containing the work 'endef'." It is unclear from the documentation whether the 'define' or 'endef' may be indented, but since 'define' may be indented, it follows that 'endef' could be indented as well.

In addition, this is a regression over previously supported functionality in version 3.76. I'm requesting that we revert to that functionality because it is correct.

I've tested this with our makefiles and it works fine.

srmadsen

Reid Madsen <srmadsen>
Mon 01 Aug 2005 10:11:47 PM UTC, comment #3:

Bug #9058 has been fixed/closed for a long time. You can try, for example, one of the 3.81 beta versions.

For this bug, the fix you suggest is too greedy. What if someone writes a shell script with "endef" as the first thing on the line? Hm. I suppose if we accept that this should be possible then this entire bug report is moot, because there would be no way to do that if we assume <TAB>endef is the end of the define.

Paul D. Smith <psmith>
Project Administrator
Mon 01 Aug 2005 09:13:36 PM UTC, comment #2:

I've uploaded a fix for two bugs.

1. #13877 -- error processing define/endef when indented with tabs
2. #9058 -- line number mixup when processing define/endif.

Here is an excerpt from the file read.c showing the fixes for both files:

static void
do_define (name, namelen, origin, ebuf)
char *name;
unsigned int namelen;
enum variable_origin origin;
struct ebuffer *ebuf;
{
struct floc defstart;
int nlevels = 1;
unsigned int length = 100;
char definition = (char ) xmalloc (length);
unsigned int idx = 0;
char *p;

/* Expand the variable name. */
char var = (char ) alloca (namelen + 1);
bcopy (name, var, namelen);
var[namelen] = '\0';
var = variable_expand (var);

defstart = ebuf->floc;

while (1)
{
unsigned int len;
char *line;

>> /* Fix for #9058 -- reversed the order of these two lines */
>> long nlines = readline (ebuf);
>> ebuf->floc.lineno += nlines;


/* If there is nothing left to eval, we're done. */
if (nlines < 0)
break;

line = ebuf->buffer;

collapse_continuations (line);

/* If the line doesn't begin with a tab, test to see if it introduces
another define, or ends one. */

/* Stop if we find an 'endef' */

>> /* Fix for #13877 -- allow whitespace at beginning of line */
>> /* if (line[0] != '\t') */

{
p = next_token (line);
len = strlen (p);

For #9058, the bug was due to the fact that the final nlines alue was lost -- it was deferred until the next loop, and lost on the inal one -- resulting in a loss of one line per define/endef.

For #13877, I just changed the logic to not check for the leading tab.

Note: These changes were made to V3.80 source to which I've merged in the EINTRLOOP changes from 3.81.

Please let me know if I've missed anything...

srmadsen

Anonymous
Thu 21 Jul 2005 05:51:17 PM UTC, comment #1:

The use of TABs to indent any line other than a command script line in make is always problematic. It's not the case that a TAB indenting a 'define' is supported, per se, any more than a TAB indenting any other line is supported. A TAB-indented line is considered part of a command script ALWAYS, regardless of the content, if it appears in a position where it could be a part of a command script. If a TAB-indented line appears before any rule is defined, or it appears after a variable definition or other non-target line, then it is assumed to be a make statement. If it appears after a target line (even separated by whitespace or comments or ifdef etc.) then it will be assumed to be part of the command script and attached to the command of that target, regardless of its contents.

I was going to close this as "not a bug" but on second thought it seems like the contents of a define/endef should never qualify as a target (during the definition). I'll look at what's going on here.

Paul D. Smith <psmith>
Project Administrator
Thu 21 Jul 2005 04:46:45 PM UTC, original submission:

In version 3.76, the tabs could be used to indent define/endef within ifeq/ifneq/ifdef/indef clauses. For example

ifneq ($(SOMEVAR),)
<tab>define MACRO
<tab><tab>all:: ; @echo "Is this a bug?"
<tab>endef
endif

However, in make version 3.80, the above results in:

makefile:2: *** missing `endef', unterminated `define'. Stop.

The workaround is to remove the leading tab(s) on the 'endef'. For example:

ifneq ($(SOMEVAR),)
<tab>define MACRO
<tab><tab>all:: ; @echo "Is this a bug?"
endef
endif

Since you support tabs to indent the 'define', you should also support tabs to indent the 'endef'.

Reid Madsen

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #3310:  Makefile added by srmadsen (152B - application/octet-stream - Sample makefile illustrating supported tab usage.)
file #3309:  read.c added by None (86KiB - text/x-csrc - Fixes for #13877 and #9058)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 5 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Wed 03 Aug 2005 08:45:02 PM UTCpsmithStatusNone=>Not A Bug
  Open/ClosedOpen=>Closed
Tue 02 Aug 2005 02:01:32 PM UTCsrmadsenAttached File-=>Added Makefile, #2775
Mon 01 Aug 2005 09:13:36 PM UTCNoneAttached File-=>Added read.c, #2774
Thu 21 Jul 2005 05:40:40 PM UTCpsmithCarbon-Copy-=>Added -unavailable-

Back to the top


Powered by Savane 3.1-cleanup1