Table of Contents
The best way to make generated into another directory is explained in Multi-Architecture Builds Using GNU make http://make.paulandlesley.org/multi-arch.html
where 3 of the following methods are discussed:
The conclusions are:
Still, if you need to go for the Explicit Path Method for its simplicity, follow Paul's Fourth Rule of Makefiles http://make.paulandlesley.org/vpath.html
If you are impatient, here is the summary.
When using the Explicit Path Method, the only reliable way to construct a makefile that will place targets into a remote directory, rather than the current directory, is by prefixing all the targets with that directory path.
We can use some of GNU make's functions to make things a little simpler to read/modify. For example, for a executable program 'foo' that is generated from 'foo.c' and 'bar.c':
PROGS = foo OBJECTS = foo.o bar.o # Shouldn't need to change anything below here... OBJDIR = ../obj VPATH = $(OBJDIR) $(OBJDIR)/%.o : %.c $(COMPILE.c) $< -o $@ OBJPROG = $(addprefix $(OBJDIR)/, $(PROGS)) all: $(OBJPROG) $(OBJPROG): $(addprefix $(OBJDIR)/, $(OBJECTS)) $(LINK.o) $^ $(LDLIBS) -o $@
This makefile will work correctly in all situations.
Paul said it doesn't need VPATH at all — VPATH is never consulted. But I doubt that if I remove the 'VPATH = ' line, thing will still work.
T
documented on: 2006.10.24