help-make
[Top][All Lists]
Advanced

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

Automatic Dependency Generation


From: Ajay Jain
Subject: Automatic Dependency Generation
Date: Tue, 5 Apr 2011 21:50:11 +0530

Hello Experts & Experts,

I need to verify the method of automatic dependency generation.

My directory structure is nested:

TOP_DIR/
|-- Makefile
`-- src
   `-- Makefile

I do make at TOP_DIR, and my .o files are generated with .c files in
SRC subdirectory.

What I have done is as follows:

%.d : %.c
    @$(SET) -e; \
$(RM) $@; \
$(CC) -M $(CFLAGS) $< > address@hidden; \
$(SED) 's,\($(notdir $*)\)\.o:,$*.o $@: ,g' < address@hidden > $@; \
$(RM) address@hidden

Is my rule correct?

I need to do this, but as per the gnu documentation on web, I see that
the following is done:

%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > address@hidden; \
sed s,\($*\)\.o[ :]*,\1.o $@ : ,g < address@hidden > $@; \
rm -f address@hidden

I feel that the second is fundamentally wrong because:

1) It does not use notdir, and hence assumes that all my object files
are in the current directory.
2) looks for a pattern [ :]*, which is also not correct. It should
just be a plain ':'.

Any comments? OR Am I wrong?

Finally, this generates a dependency file in SRC sub directory. The
file is not hidden. If I have to make it hidden, what change will I
have to make in the rule? I tried writing the rule, but I was not
successful.

Regards,
Ajay



reply via email to

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