l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2004 Mar 31 22:55

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Make question: headers depending on other headers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On Wed, 31 Mar 2004, Bill Kendrick wrote:

> Is it useful to list these 'dependencies' within the Makefile?

I do it, 'cuz I've seen it handled incorrectly at times.  But there are
some caveats... (see below)

> 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...?

Since bar.h depends on zzz.h, you wanna do:

   bar.h: zzz.h
      touch bar.h

But if you Ctrl-C while `make` is running `touch bar.h`, make will erase
bar.h.  Make's reasoning is that bar.h depends on zzz.h, which probably
means bar.h can be recreated from zzz.h, and since you interrupted the
creation of bar.h mid-way (although you're really just touching it) bar.h
is probably only half-created, so it'll need to be fully-recreated later
when you run `make` again - so just remove the file so it doesn't mess up
dependencies later.

This is a fine rule for most cases, but not if you're just touching a file
simply because there is a depency.  So what I do this tell `make` not to
remove bar.h if I Ctrl-C:

   .PRECIOUS: bar.h

Or if you want all header files marked "precious":

   .PRECIOUS: %.h

which is fine unless you got a *.h file that does get recreated from
another file (usually okay.)

.PRECIOUS is supported by another make implementation I've used in the
past (besides GNU Make), so I'm guessing it's a pretty standard built-in
target name.

-Mark


-- 
Mark K. Kim
AIM: markus kimius
Homepage: http://www.cbreak.org/
Xanga: http://www.xanga.com/vindaci
Friendster: http://www.friendster.com/user.jsp?id=13046
PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
PGP key available on the homepage
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.