Hi all,

I'm having a problem with automatic dependency generation from source-files 
that depend on  auto-generated header files. Here's a (vastly) simplified 
example.

-- BEGIN Makefile

%.cpp %.h : %.idl
        $(IDL.comp) $<

%.o : %.cpp
        tools/cxx-deps $(dir $*) $(CPPFLAGS) $< > $*.d
        $(COMPILE.cpp) $(OUTPUT_OPTION) $<

SRC := main.cpp A.cpp   # NOTE: A.cpp is auto-generated by the IDL tool
OBJS := $(SRC:.cpp=.o)
DEPS := $(SRC:.cpp=.d)

prog : $(OBJS)
        # Linker...

-include $(DEPS)

-- END Makefile

(the cxx-deps script will generate .d files in accordance to what Paul S. 
mentions on his  website.)
Assume that main.cpp #include's A.h

Now this may or may not work.

If make tries to build A.o first, it will deduce that it must run the IDL tool 
first, and  everything is fine (the entire source tree exists)

If make tries to build main.o first (and at the same time main.d) it will fail, 
because A.h  does not exist yet.

Some simple workarounds are available:

* The developer can add some dependencies manually (main.cpp : A.h in this 
case) but that will  quickly get out of hand in a large project. Also, some 
developer working on module FOO  shouldn't need to know what parts of module 
BAR are auto-generated right?

* I could make some phony targets and make sure that all auto-generation steps 
are performed  first. This doesn't help much though when the auto-generated 
files are in another module. I  would have to litter the makefiles with 
"high-level" dependecies between modules. I suspect  that this will quickly 
deteriorate to a scheme that will be equivalent to remaking all other  modules 
prior to making the current module.

So my dilemma is this:
I need to have automatic dependency generation, but generating the dependencies 
is  hard/impossible(?) when the dependencies themself havent been generated yet.

Any practical workarounds (that would work for a larger project as well)?

NOTE: I realize that this isn't a bug or a problem with make per se, its just a 
problem with  how i'm trying to use it. After all, im trying to get the 
compiler to tell me what include files i'm depending on, even though it cannot 
find them.
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to