[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dependency issue
From: |
Josh Bialkowski |
Subject: |
Re: dependency issue |
Date: |
Wed, 25 Aug 2010 12:32:35 -0400 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 |
I use the following rules to generate dependency automatically
%.P : %.cpp
$(QUIET_MM)rm -f $@; \
$(CPP) -M $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) $< > address@hidden; \
The rule from the make manual:
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > address@hidden; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < address@hidden > $@; \
rm -f address@hidden
I find that rule to be overly complicated and confusing. Rather, I
follow the advice in http://mad-scientist.net/make/autodep.html to
handle auto dependency. In particular, why should you have a separate
rule for the dependency file? I use the following style rule:
%.o: %.c
gcc -Wp,-M,-MF$*.d,-MT$@ -c -o $@ $<
-Wp says to pass the following options on to the preprocessor
-M says to generate dependency
-MF says to ouput the dependency file to <stem>.d instead of stdout
(note, this is an example, probably you want something with CFLAGS and
so forth)
The idea is this: build the dependency file at the same time as the
object file. If the object hasn't been built yet, then there is no need
for a dependency file, because make already has to build the object
file. We only actually care about the object file's dependencies if the
object file exists. I include the dependency files with "-include"
instead of "include" so that the dependencies are only included if they
actually exist. The construction makes more sense to me, and it cuts
down on the number of processes required in a build scenario.
In any case, that page is a good read an is worth understanding if
you're doing automatic dependency generation.
Josh