[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Makefile - how to filter out x.c files that do not have correspondin
From: |
hzmonte |
Subject: |
Re: Makefile - how to filter out x.c files that do not have corresponding x.h in a rule that has %.h as prerequisite |
Date: |
13 Jan 2006 14:44:04 -0800 |
User-agent: |
G2/0.2 |
For the record:
mkl> I think it would be really nice
mkl> that 'make' one day would be enhanced to accomodate optional
mkl> prerequisites. As you can see, my situation is not a rare one
in
mkl> real life. Thanks.
Paul D. Smith replies:
Without stating an opinion one way or the other on the concept of an
optional prerequisite, the case made in your email is not, to me,
compelling.
Having a rule like this:
%.o: %.c %.h
is just not appropriate, unless you have some rule in your development
process that forces every .c to have a .h (and I would think that
process would be broken). That's not what a pattern rule is for... you
should only put files that MUST exist, or the thing won't work at all,
as prerequisite patterns.
Also, it's almost unheard of that a .c file includes nothing other than
a single .h file, so you'll have to define all the other .h files as
prerequisites anyway... what makes that particular .h file so special
that it deserves a pattern?
You should define the pattern rule with just the bare minimum MANDATORY
prerequisites, then use extra prerequisite definitions to add the
optional ones to the appropriate target.
%.o : %.c
...
foo.o: foo.h
bar.o: bar.h
But more likely, as above, you'll have to implement some kind of
automatically generated list of header files, in which case that will
all be done for you.
====================================================
Just for curiosity, does one put the system header files, e.g.
stdlib.h, as prerequisites, in real life, as in
foo.o: foo.h stdlib.h
? I guess not because there would be too many. But strictly speaking,
we should just in case the system gets changed, shouldn't we?