[vox-tech] Make question: headers depending on other headers

Jeff Newmiller vox-tech@lists.lugod.org
Wed, 31 Mar 2004 15:22:11 -0800 (PST)


On Wed, 31 Mar 2004, Bill Kendrick wrote:

> 
> I have some source files that depend on some other sources' headers.
> 
> In turn, some of THOSE headers depend on other headers (e.g., a header
> defining a structure might depend on another header that defines some other
> structures).
> 
> Is it useful to list these 'dependencies' within the Makefile?

That is what a makefile is all about.

> For example, consider foo.c:
> 
>   /* foo.c
>      I do foo things */
> 
>   #include "foo.h"  /* My header */
>   #include "bar.h"  /* bar.c's header, so I can get to its function(s) and/or
>                        typedefs... */
> 
>   ...
> 
> 
> In Makefile, I'd do:
> 
>   foo.o:  foo.c foo.h bar.h
>           ...compile foo.c into foo.o...
> 
> 
> However, say in "bar.h", I have:
> 
> 
>   /* bar.h
>      I do things with alcohol (get it? "bar?" hahaha...) */
> 
>   #include "bar.h"  /* My header */
>   #include "zzz.h"  /* Contains some #define's for compile-time options */
> 
>   ...
> 
> 
> Should I make "bar.h" depend on "zzz.h"?  Or "foo.o" depend on it?  Or...?

You have bar.h including bar.h... not a good idea.  I am not really sure
where your question was leading... assuming we omit the recursion...

* the foo.c dependency should include foo.h, bar.h, and zzz.h

* any bar.c dependency should include bar.h and zzz.h

> I just want to make sure that in case I touch something somewhere, that
> everybody who needs to get update GETS updated.

In general, for a given .c.o dependency, you need to include all of the
quoted includes that it depends on... directly OR indirectly. This is
generally not done for <> includes (library headers).

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------