bugmake - Bugs: bug #21670, implicit rule ignored for...

 
 

bug #21670: implicit rule ignored for prerequisite that is produced by .DEFAULT

Submitter:  Guenter Egerer <egerer>
Submitted:  Thu 29 Nov 2007 12:52:15 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Duplicate Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  3.81 Operating System:  POSIX-Based
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 10 Jun 2009 02:33:42 AM UTC, comment #2: 

I believe this is a duplicate of bug #17752

Paul D. Smith <psmith>
Group administrator
Thu 29 Nov 2007 04:04:54 PM UTC, comment #1: 

Looks like a regression in 3.81, as the makefile works as desired with 3.80.  It seems the interpretation of step 5.c of the algorithm in section 10.8, "Implicit Rule Search Algorithm" of the info pages changed:

       c. Test whether all the prerequisites exist or ought
          to exist. (If a file name is mentioned in the
          makefile as a target or as an explicit
          prerequisite, then we say it ought to exist.)

          If all prerequisites exist or ought to exist, or
          there are no prerequisites, then this rule applies.

make.c is mentioned in the makefile as an explicit prerequisite (for prog), so make should conclude that "it ought to exist" and therefore the suffix rule for .c.o should apply and block consideration of .DEFAULT for hello.o.

Note that 3.81 behaves as desired if this is added to the makefile:
 make.o: make.c

It's like 3.81 interprets the phrase "explicit prerequisite" to mean "explicit prerequisite of the current target" in step 5.c.


That said, the .DEFAULT rule in the example seems like the wrong tool for the job here.  The right way to tell GNU make that the backup/ directory may contain a copy of a missing prerequisite would be this:

%:: backup/%
        ln -s $< $@

Note that with that instead of the .DEFAULT rule, GNU make operates correctly, even after removing the 'make.c' dependency for the 'prog' target.  (The rule for 'prog' doesn't use 'make.c', only 'make.o', so it has no real reason to depend on 'make.c'.)

Anonymous
Thu 29 Nov 2007 12:52:15 PM UTC, original submission:  

I've found a problem with GNU make 3.81 (built for i686-pc-linux-gnu).

The following makefile can be used to recreate the problem:

# -------------------------------------
CC = cc

.SUFFIXES:
.SUFFIXES: .c .o
.c.o:
$(CC) -c $<

.DEFAULT:
@if [ -f backup/$< ]; then \
  ln -s backup/$< . ;\
  echo "ln -s backup/$< .";\
else  \
  echo "'$<' does not exist.";\
  false;\
fi

prog: hello.c hello.o
$(CC) -o $@ hello.o
# -------------------------------------

The directory that contains this makefile should also
contain a subdirectory named "backup". That subdirectory
should contain a simple C source file named "hello.c".

Running "make" should create the file "hello.o" from the
file "hello.c" that is produced (in the current directory)
by the commands specified for the special built-in target
".DEFAULT".

Creation of the file "hello.c" works fine, but "make"
fails to produce "hello.o".

Here are the commands to reproduce the problem:

$ ls
backup  makefile
$ ls backup
hello.c
$ cat backup/hello.c
#include <stdio.h>

int main(void)
{
  printf("hello, world\n");
  return 0;
}
$ make -r
ln -s backup/hello.c .
'hello.o' does not exist.
make: * [hello.o] Error 1
$ ls
backup  hello.c  makefile
$

After this I've run "make" in the debug mode:

$ rm hello.c
$ make -rd | nl -ba
     1  GNU Make 3.81
     2  Copyright (C) 2006  Free Software Foundation, Inc.
     3  This is free software; see the source for copying conditions.
     4  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
     5  PARTICULAR PURPOSE.
     6
     7  This program built for i686-pc-linux-gnu
     8  Reading makefiles...
     9  Reading makefile `makefile'...
    10  Updating makefiles....
    11   Considering target file `makefile'.
    12    Looking for an implicit rule for `makefile'.
    13    No implicit rule found for `makefile'.
    14    Using default commands for `makefile'.
    15    Finished prerequisites of target file `makefile'.
    16   No need to remake target `makefile'.
    17  Updating goal targets....
    18  Considering target file `prog'.
    19   File `prog' does not exist.
    20    Considering target file `hello.c'.
    21     File `hello.c' does not exist.
    22     Looking for an implicit rule for `hello.c'.
    23     No implicit rule found for `hello.c'.
    24     Using default commands for `hello.c'.
    25     Finished prerequisites of target file `hello.c'.
    26    Must remake target `hello.c'.
    27  Putting child 0x080774d8 (hello.c) PID 10332 on the chain.
    28  Live child 0x080774d8 (hello.c) PID 10332
    29  ln -s backup/hello.c .
    30  Reaping winning child 0x080774d8 PID 10332
    31  Removing child 0x080774d8 PID 10332 from chain.
    32    Successfully remade target file `hello.c'.
    33    Considering target file `hello.o'.
    34     File `hello.o' does not exist.
    35     Looking for an implicit rule for `hello.o'.
    36     Trying pattern rule with stem `hello'.
    37     Trying implicit prerequisite `hello.c'.
    38     Trying pattern rule with stem `hello'.
    39     Trying implicit prerequisite `hello.c'.
    40     Looking for a rule with intermediate file `hello.c'.
    41      Avoiding implicit rule recursion.
    42     No implicit rule found for `hello.o'.
    43     Using default commands for `hello.o'.
    44     Finished prerequisites of target file `hello.o'.
    45    Must remake target `hello.o'.
    46  Putting child 0x080777f0 (hello.o) PID 10335 on the chain.
    47  Live child 0x080777f0 (hello.o) PID 10335
    48  'hello.o' does not exist.
    49  Reaping losing child 0x080777f0 PID 10335
make: * [hello.o] Error 1
    50  Removing child 0x080777f0 PID 10335 from chain.

When "make" looks for an implicit rule for "hello.o" (line 35-41)
it should recognize that the target `hello.o' could be build
from the implicit prerequisite `hello.c' by applying the command
specified for the double-suffix rule ".c.o:" (line 6 of makefile).

In my opinion, it is a bug that GNU make 3.81 finds no implicit
rule for "hello.o" (line 42).

Guenter Egerer <egerer>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #14507:  makefile added by egerer (332B - application/octet-stream)
file #14508:  hello.c added by egerer (79B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by egerer (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-06-10 psmith StatusNone Duplicate
        Open/ClosedOpen Closed
    2007-11-29 egerer Attached File- Added makefile, #14507
        Attached File- Added hello.c, #14508

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code