Subject: auto creation od .depend files
To: None <>
From: David Laight <>
List: tech-toolchain
Date: 01/26/2004 22:55:13
I've got this more or less working...

The basic idea is that whenever you compile anything, you also regenerate
the relevant .d file.  This is usually done by passing -MD to gcc and
basically costs nothing.

The problem then is that you need to post-process the .d files into .depend.
(The post-processed .depend contains a .OPTIONAL for all the include files,
so that missing files don't break the build.)

This needs to be done if and of the .d files have been created during the
current build (not if they are out of date at the start of the build).

This is done by detecting whether ${CPPFLAGS) has been expanded by setting:

and having:
.depend: .PHONY
	${SKIP_AUTODEP} rm -f .depend

realall: ${PROG} ${SCRIPTS} .WAIT .depend

Things are actually slightly more complicated...

You need 'SKIP_AUTODEP!= [ ! -f .depend ] || echo \\#' to get .depend
created if it is absent, but nothing is built.

And to use
instead of CPPFLAGS when passing things into nested makes.

I've also had to ensure there is a dummy target (ie one with no rules)
to pin the '.WAIT .depend' onto.  Maybe I could use .USEBEFORE instead???

The other changes are minor and relate to converting 'make dependall'
into 'make all', but leaving 'make depend' as is.

Most of the other changes are minor and repetetive.  Mainly adding the
dependency on .depend to the correct lines.

Everything is dependant on a MKAUTODEP variable which I've defaulted to no.

I'm tempted to commit the changes so that others can try them, the full
set of diff output woldn't really be meaningful!


David Laight: