URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=16286>
Summary: VPATH and directory cache Project: make Submitted by: None Submitted on: Donnerstag 06.04.2006 um 18:15 UTC Severity: 3 - Normal Item Group: Bug Status: None Privacy: Public Assigned to: None Open/Closed: Open Component Version: 3.79.1 Operating System: Any Fixed Release: None _______________________________________________________ Details: Normally, all prerequisites are searched in ./ and in all directories found in VPATH. If found, the $^ variable holds the prerequisites with the actual path where they are found. Fine. Unfortunately this utterly fails if the prerequisite was the target of a previously executed rule. Following the manual, make assumes that a rule creates its target. But what if the target is created in a different directory than then ./ ? make adds the file to its directory cache - without noticing that it was created somewhere else. As soon as the former target appears as prerequisite, make does no longer search in VPATH but simply assumes that the file is in the current directory. And of course the rule fails to build its target then. When running make a second time, it skips building the object files (of course), finds them through vpath and works as expected. ************************************************** VPATH = $(INCSRC):obj:bin SRCS = foo1.c foo2.c foo3.c foo4.c foo5.c foo6.c OBJS = $(SRCS:.c=.o) LIBS = $(ADDLIBS) TARG = $foo.elf all: $(OBJS) $(TARG) avr-objcopy -O binary -I ihex $(PROJ).hex $(PROJ).bin %o : %c @$(CC) -c $(CPFLAGS) $(INCFIRST) -I$(INCDIR) $(INCLAST) $< -o obj/$@ %elf: $(OBJS) @$(CC) $^ $(LDFLAGS) $(LIBS) -o bin/$@ ************************************************************ make compiles all c files properly, the object files placed in the obj subfolder. but then the linking of the object files fails. While all compiled .o files are in obj/*.o , make constructs a $^ variable which contains some prerequisites with and some without the obj/ prefix. A debug output reveals that whils considering targets and rules for the prerequisites in the %elf rule, make has pruned some files form the search (apparently because of their -wrong- appearance in the directory cache) while others are searched for and found by the VPATH mechanism. Which ones are found and which are simply (and wrongly) assumed depends on the number of source files and seems to be influenced by cosmic x-rays too. The only fix to this problem was to change the rule like this: %elf: $(OBJS) @$(CC) $(addprefix obj/,$(notdir $^)) $(LDFLAGS) $(LIBS) -o bin/$@ which renders the vpath mechanism almost useless, only working properly for files that aren't made by make itself. _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=16286> _______________________________________________ Nachricht geschickt von/durch Savannah http://savannah.gnu.org/ _______________________________________________ Bug-make mailing list Bug-make@gnu.org http://lists.gnu.org/mailman/listinfo/bug-make