Unix Programming - [make] how to separate src from obj tree?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2004 > [make] how to separate src from obj tree?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author [make] how to separate src from obj tree?
Markus Dehmann

2004-07-04, 5:52 pm

How can I separate the src/ from the obj/ tree, using make? It looks
chaotic when my src folder is full of .o files.

The tricky thing is I have src files with the same name, just in
different subdirectories:
src/main.cpp
src/bmw/car.cpp
src/mercedes/car.cpp

Now, (GNU) make should place the obj files into obj, preserving the
directory structure:
obj/main.o
obj/bmw/car.o
obj/mercedes/car.o

This should be the most natural thing in the world for make to do. But
it seems it's tricky...?

Markus

Here is my stupid Makefile that just puts the o files next to the src
files:

SRC=src
OBJ=obj
FILES=main bmw/car mercedes/car
OFILES=$(FILES:%=$(SRC)/%.o)
TARGET=cars

all: $(TARGET)

$(TARGET): $(OFILES)
g++ $(OFILES) -o $@

%.o: %.cpp
g++ -I$(SRC) -c -o $@ $<
Pascal Bourguignon

2004-07-05, 2:49 am


markus.cl@gmx.de (Markus Dehmann) writes:
> How can I separate the src/ from the obj/ tree, using make? It looks
> chaotic when my src folder is full of .o files.
> [...]
> %.o: %.cpp
> g++ -I$(SRC) -c -o $@ $<


Either use VPATH (but then you have to put the Makefile or a symlink
in the object directories), or specify the absolute paths:

$(OBJDIR)$(REL).o : $(SRCDIR)$(REL).c
g++ -I$(SRC) -c -o $@ $<


You could get good ideas from:

http://www.canb.auug.org.au/~miller...-cons-harm.html

--
__Pascal Bourguignon__ http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
Ian Zimmerman

2004-07-05, 2:49 am


Pascal> You could get good ideas from:
Pascal> http://www.canb.auug.org.au/~miller...-cons-harm.html

This is also very worthy of reading:

http://make.paulandlesley.org/

--
"It's not true or not." A reality show producer (real quote)
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com