help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Implicit Rules with Different Source and Object Directory Question


From: redcomet
Subject: Implicit Rules with Different Source and Object Directory Question
Date: Wed, 25 Nov 2009 13:07:06 -0800 (PST)

My problem is a bit different from the other posts on this topic so I decided
to make a new post, sorry if I am misunderstanding someone else's thread.

Basically I am writing some make files for a few big projects and I am
trying to use the same format and design for each project.  I am using some
basic implicit rules to make compiling and linking easy but I run into
trouble based on my directory structure.

I trying to keep the build .o files separate from the .c's, so gcc does not
inflate my source directory with .c and .o files.

Anyway here is my generic implicit rule to compile .c files

OBJECTS := $(SOURCES:%.c=$(BUILD_DIR)/Release/%.o)
$(BUILD_DIR)/Release/%.o: %.c
        mkdir -p $(BUILD_DIR)/Release
        $(CC) $(INCLUDE) $(CFLAGS) $(DEFINES) -o $@ -c $<

$(SOURCES) is my list of .c files in the src directory, and I want that
source list to map to a corresponding $(BUILD_DIR)/Release/ object.

so if my source list is
SOURCES = \
main.c \
printline.c \
dosomething.c

I want my objects list to be
OBJECTS = \
build\main.o
build\printline.o
build\dosomething.o

the next make rule is what does the compiling.  

In general this works wonderfully but I have a problem when projects have
folders in the src dir.

for example if my sources are now
SOURCES = \
main.c
linux\printline.c
linux\dosomething.c

I still want my object list to be
OBJECTS = \
build\main.o \
build\printline.o \
build\dosomething.o

NOT
OBJECTS = \
build\main.o \
build\linux\printline.o \
build\linux\dosomething.o

which is the default behavior for my rule here.

I do not want that to happen because gcc for some reason has no option to
auto create directories and I end up having to mkdir all the source sub
directories which is very very bad.

How can I change my implicit rule to not care about the directory and only
stub-ify the real filename?

Right now I do something like
OBJECTS := $(SOURCES:linux/%.c=$(BUILD_DIR)/Release/%.o)
to match just the filename.  I also have to add $(SOURCE_DIR)/linux to the
VPATH for it to work

There is not a lot of documentation on implicit rules so I am hoping someone
knows.
I know I could hack it in using $(@F) but I do not want to make 
http://make.paulandlesley.org/rules.html Paul  angry :P

Thank you very much
-- 
View this message in context: 
http://old.nabble.com/Implicit-Rules-with-Different-Source-and-Object-Directory-Question-tp26520309p26520309.html
Sent from the Gnu - Make - Help mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]