help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with Implicit Rules


From: Jeff Butler
Subject: Problem with Implicit Rules
Date: Wed, 27 Sep 2000 13:58:02 -0400

Hi,
  I have a problem where make fails and I don't 
think it's something that I'm doing wrong.
This email contains a description of the problem 
and a tar of the example is attached.  
The sample output was generated using the latest  
version of make 3.79.1 (also tried 3.77) on the
Redhat Linux 6.0/x86 platform.


  I'm trying to get make to build an object file 
with the following implicit rule:

%.o: $(SRCDIR)/%.c
        $(CC) -c -o $@ $(CFLAGS) $<

We have a couple of requirements:
  1) We do not want to use VPATH.
  2) We would like to keep objects in a separate 
        directory from sources.

  Make seems to be incorrectly substituting 
variables in the $(SRCDIR)/%.c.

(* the gmks.tar.gz contains the following files and
directories *)
(* you can just untar the attached tar file if that's
perferable *)

In order to replicate the problem do the following:

1. Create to following directory structure:

<topdir>/src
<topdir>/src/foodir
<topdir>/obj
<topdir>/obj/foodir

2. Create <topdir>/src/foodir/foo.c:

<foo.c contents>

main() {
        printf("hello world\n");
}

3. Create <topdir>/obj/Makefile

<Makefile contents>
SRCDIR=../src

all: foodir/foo.o

%.o $(SRCDIR)/%.c
        $(CC) -c -o $@ $(CFLAGS) $<

If you've recreated the above directory structure and 
cd to <topdir>/obj and run make the following error will
result:

<make output>
% make
make: *** No rule to make target `foodir/foo.o', needed by
`all'.  Stop.

</make output>

If you run 'make -r -d' the following diagnostic information
results:

<make output>
$ make -r -d
GNU Make version 3.79.1, by Richard Stallman and Roland
McGrath.
Built for i686-pc-linux-gnu
Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
99, 2000
        Free Software Foundation, Inc.
This is free software; see the source for copying
conditions.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A
PARTICULAR PURPOSE.

Report bugs to <address@hidden>.

Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
 Considering target file `Makefile'.
  Looking for an implicit rule for `Makefile'.
  No implicit rule found for `Makefile'.
  Finished prerequisites of target file `Makefile'.
 No need to remake target `Makefile'.
Updating goal targets....
Considering target file `all'.
 File `all' does not exist.
 Looking for an implicit rule for `all'.
 No implicit rule found for `all'.
  Considering target file `foodir/foo.o'.
   File `foodir/foo.o' does not exist.
   Looking for an implicit rule for `foodir/foo.o'.
   Trying pattern rule with stem `foo'.
   Trying implicit prerequisite `foodir/../src/foo.c'.
   Trying pattern rule with stem `foo'.
   Trying implicit prerequisite `foodir/../src/foo.c'.
   Looking for a rule with intermediate file
`foodir/../src/foo.c'.
    Avoiding implicit rule recursion.
   No implicit rule found for `foodir/foo.o'.
   Finished prerequisites of target file `foodir/foo.o'.
  Must remake target `foodir/foo.o'.
make: *** No rule to make target `foodir/foo.o', needed by
`all'.  Stop.

</make output>

The line that seems to indicate there's a bug in make is:

Looking for a rule with intermediate file
`foodir/../src/foo.c'.

The implicit rule that is defined in the makefile is

%.o: $(SRCDIR)/%.c

SRCDIR = ../src, so I would think that 
$(SRCDIR)/%.c should be equivalent to ../src/foodir/foo.c
not foodir/../src/foo.c.

Any ideas?
Am I doing something wrong?
Is there a workaround other than using VPATH?
Is this an authentic bug in gmake?

thanks,
-jeff

Attachment: gmks.tar.gz
Description: GNU Zip compressed data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]