Re: Make file with objects in one directory

Henrik Carlqvist <[email protected]>
Newsgroups gmane.comp.gnu.utils
Organization SunSITE.dk - Supporting Open source
Message-ID <[email protected]>
"Kiran" <[email protected]> wrote:
> I have the following, but it compiles into the source itself.

> %.o:%.c
>    $(CC) -c $< -o $@

The above pattern and way to call your compiler will place the object file
in the same directory as the source file. The rule uses "%" as a pattern
and the string replaces % in the target will also replace % in the
prerequisite. Example, if you need to create two files, foo.o and
bar/foobar.o The above will expand to two rules:

foo.o: foo.c
	$(CC) -c $< -o $@

bar/foobar.o: bar/foobar.c
	$(CC) -c $< -o $@

At http://www.gnu.org/software/make/manual/make.html you have probably
already read that $< expands to the name of the first prerequisite and
that $@ expands to the target. So the rule above finally expands to
something like:

bar/foobar.o: bar/foobar.c
	$(CC) -c bar/foobar.c -o bar/foobar.o

What you want to do is to use a rule like this:

path/obj_files/%.o: path/src_files/%.c
	$(CC) -c $< -o $@

regards Henrik
-- 
The address in the header is only to prevent spam. My real address is:
hc8(at)uthyres.com Examples of addresses which go to spammers:
[email protected] root@localhost
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.