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:
-
Source Copy Method
-
Explicit Path Method
-
VPATH Method
The conclusions are:
-
VPATH is good for finding sources, not for finding targets.
-
The most convenient way for developers to use is via the VPATH Method.
-
The Explicit Path Method is much more straight forward than the VPATH Method,
but it has its own problem.
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.
using the Explicit Path Method
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
Newsgroups: comp.os.linux.misc,comp.unix.questions
Date: Thu, 27 Mar 2003 08:56:42 -0600
> What is the right way of specifying make rules for files that are
> not in current directory? For example:
> %.ps : %.dvi %.chk
Not all makes are the same, but the implementation I use on Solaris does not
allow more than ONE % on the right side. So, I believe this would be an
error or not interpretted as you indend. GNU make may be different. What
you are trying to do works for me, on Solaris 8, when there is only one % on
the right.
Chuck Dillon
make file not in current directory
> What is the right way of specifying make rules for files that are
> not in current directory?
There is none. The concept (a) does not apply, (b) is meaningless, (c)
is ill-conceived.
> %.ps : %.dvi %.chk
> $(DVIPS) -o $@ $<
> I want it to be a general purpose rule for files that are in current
> directory, and those which aren't. But it seems to me that it does
It is.
> not apply to files not in current directory, correct? How can I make
> it happen?
You probably need to change your perception.
> Further detailed info. I have another rule:
> ps : ${TEX_DEST_DIR}/$(TEX_SOURCE_BASE).ps
> and the .dvi has already been generated in ${TEX_DEST_DIR}. But when
> I issue make, I got:
> make: *** No rule to make target `../../tmp/path/test.ps', needed by `ps'. Stop.
And where are you when you do this?
In any case, the correct way to do what you want is
export VPATH:=$(TEX_SOURCE_DIR)
ps:
$(MAKE) -C $(TEX_DEST_DIR) foo.ps
I.e. makefiles are expected to be one per dir.
Probably.
Peter
make file not in current directory
> In any case, the correct way to do what you want is
>
> export VPATH:=$(TEX_SOURCE_DIR)
> ps:
> $(MAKE) -C $(TEX_DEST_DIR) foo.ps
>
> I.e. makefiles are expected to be one per dir.
This is non-portable for those (bsd-based) `make's that do not use -C. I
suspect you'd want to use (cd $(TEX_DEST_DIR); $(MAKE) ) instead.
Or something.
~Tim
Newsgroups: comp.unix.programmer
Date: Sun, 13 Apr 2003 03:30:12 GMT
I am having difficulties writing a make file that generate files in
alternative directories. The problem is mainly on how to generate
files from generated files.
Here is an example:
Seems to me that a simple
rule can't cover the above two cases. So I'm currently writing two
separated rules for it. I want to know that if this (two separated
rules) is the only solution?
Thanks for your input, even a 'yes' would help. :-)
make, into another directory
Yes. (Seriously…)
(two separated rules is the only solution)
Paul D. Smith @gnu.org Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
make, into another directory
> %.o: %.c
> gcc -c $CFLAGS $^ -o $@ ;\
> mv -f $@ obj
That does not work so well since it makes the .o file allways out of date.
These are the kinds of rules the OP will need.
obj/%.o : %.c
gcc -c $CFLAGS $^ -o $@
obj/%.o : src/%.c
gcc -c $CFLAGS $^ -o $@
src/%.c : %.l
lex $LEXFLAGS $^
mv -f lex.yy.c $@
Gianni Mariani