help-make
[Top][All Lists]
Advanced

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

Re: unwanted implicit rule


From: Nicholas Leippe
Subject: Re: unwanted implicit rule
Date: Thu, 5 Jul 2001 00:04:04 -0700

On Wednesday 04 July 2001 16:10, Paul D. Smith wrote:
...
> Here is the example I used:
>
>   $ cat Makefile
>   %.moc.cpp: %.h ; cp $< $@
>
>   %.ui.h: %.ui ; cp $< $@
>
>   %.ui.cpp: %.ui.h ; cp $< $@
>
>   all: foo.ui.o foo.ui.moc.o
>
>   $ touch foo.ui
>
>   $ make
>   make: Circular foo.ui <- foo.ui.o dependency dropped.
>   cp foo.ui foo.ui.h
>   cp foo.ui.h foo.ui.cpp
>   g++    -c -o foo.ui.o foo.ui.cpp
>   cp foo.ui.h foo.ui.moc.cpp
>   g++    -c -o foo.ui.moc.o foo.ui.moc.cpp
>   rm foo.ui.cpp foo.ui.h foo.ui.moc.cpp
>
> As best as I can tell, this is what you want to do and works correctly.
> This was GNU make 3.79.1.

same here--3.79.1

>
> I added the "%: %.o" rule, then I got a different circular dependency
> message, building foo.ui from foo.ui.cpp.  So I added a "%: %.cpp" as
> well, then I got no circular dependency messages.

Your example worked just fine. (no suprise :)

And, I've even managed to get it to work finally!

I narrowed the problem down to some subtle issues with the dependency
generation.  (*.d files)

My dir layout for all of this is: (using qt's tutorial 10 code, plus my own 
simple.ui)

t10.cpp
src/cannon.h
src/cannon.cpp
src/lcdrange.h
src/lcdrange.cpp
src/simple.ui

So, to build it the following must be generated:

t10.d
t10.o
t10
src/cannon.o
src/cannon.d
src/cannon.moc.cpp
src/cannon.moc.d
src/cannon.moc.o
src/lcdrange.o
src/lcdrange.moc.cpp
src/lcdrange.moc.o
src/simple.ui.h
src/simple.ui.cpp
src/simple.ui.d
src/simple.ui.o
src/simple.ui.moc.cpp
src/simple.ui.moc.d
src/simple.ui.moc.o

where the ruleset is:

%.d : %.cpp
%.moc.cpp : %.h
%.ui.h : %.ui
%.ui.cpp : %.ui.h

What appears to have been part of the problem is that when t10.d is
created by scanning t10.cpp (which has #include "simple.ui.h") simple.ui.h
does not yet exist since it is an intermediate file.  Thus gcc can't see it
and simply puts "simple.ui.h' as the prerequisite in t10.d
When make tries to make t10.o it looks for simple.ui.h.  But, since
simple.ui is not in the current dir it assumes it to be an intermediate file and
attempts to create an implicit rule chain via the default rule %: %.o resulting
in a circular dependency:

simple.ui.h <- simple.ui <- simple.ui.o <- simple.ui.cpp <- simple.ui.h

So, part of the solution required getting the 'simple.ui.h' in t10.d replaced
by the correct 'src/simple.ui.h'.

One way around this, was to merely change t10.cpp to #include "src/simple.ui.h".
This causes gcc to put src/simple.ui.h in the t10.d file, but has the constraint
that the full relative path to every ui.h file must always be specified in every
#include directive in the entire project--and maintained as such if moved
around.

So, I ended up having to do this:

$(DEPENDS): $(QTUIHDRS)

where DEPENDS is the list of all the .d files, and QTUIHDRS is all the .ui.h
files (in this case just the one src/simple.ui.h), forcing the .ui.h files to be
created before the .d files are generated.

This, and cancelling out the implicit %: %.o rule made it finally behave the
way I wanted.

So, thanks to all that gave me the hints that helped me get this far! :)


Nick

-- 
Nobody will ever need more than 640 kB RAM.
                 -- Bill Gates, 1983
Windows 98 requires 16 MB RAM.
                 -- Bill Gates, 1999
Nobody will ever need Windows 98.
                 -- logical conclusion



reply via email to

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