directory access problem when compile .c into .o using GNU make
I am meeting with a problem when using GNU make to compile two .c files into related .o files.
My situation is, foo.c is under foo sub-directory and goo.c is inder goo sub-directory. I want to put both output foo.o and goo.o into debug sub-directory.
Currently, I have written the following statements in Makefile,
SRC = foo/foo.c goo/goo.c
OBJ = debug/foo.o debug/goo.o
But I am confused about how to write a rule to compile them, since the source files are in different directories and the output directory for .o files are in another directory (debug).
I think I can write two rules, one for foo/foo.c --> debug/foo.o and the other for goo/goo.c --> debug/goo.o, but I think it is not a good way if I have a lot of source files and seems stupid.
Could anyone help please?
thanks in advance,
Try an implicit rule:
$(F@) is the filename portion of the target.
$< is the first prerequisite.
BTW, here is the GNU make manual.
|All times are GMT -5. The time now is 12:34 AM.|