[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to deal if source code and object file are in different director
From: |
Philip Guenther |
Subject: |
Re: how to deal if source code and object file are in different directory? |
Date: |
Wed, 30 Aug 2006 13:13:30 -0600 |
On 8/30/06, Lin George <address@hidden> wrote:
Suppose I define two macros,
OBJ_DIR = debug/foo.o debug/goo.o
SRC_DIR = src/foo.c src/goo.c
how should I write a rule to compile foo.c and goo.c
into foo.o and goo.o and put them into debug
sub-directory?
Well, here's a pattern rule to compile _any_ .c file under 'src' into
a .o under 'debug'
debug/%.o: src/%.c
$(COMPILE.c) -o $@ $<
If you wanted that to _only_ apply to the files listed in OBJ_DIR, you
would change that to a static pattern rule (check the GNU make info
pages for details):
$(OBJ_DIR): debug/%.o: src/%.c
$(COMPILE.c) -o $@ $<
BTW, it's kinda odd to name a variable containing filenames with the
suffix "_DIR". In practically every makefile I've ever seen or
written, a variable named SRC_DIR would contain just the directory of
the source files. The list of source files would be named SRCS or
similar.
Philip Guenther