delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/04/18:02:04

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Another makefile question
Date: 4 Mar 1997 02:06:31 GMT
Organization: Oxford University
Lines: 62
Message-ID: <5fg037$ehc@news.ox.ac.uk>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970303131626 DOT 9009H-100000 AT is> <331B8C81 DOT 5933 AT cs DOT com>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

John M. Aldrich (fighteer AT cs DOT com) wrote:
: Eli Zaretskii wrote:

: > But if it doesn't find them, it doesn't care!  Question: what will
: > happen if some .d file has somehow, by omission or commission, been
: > deleted?  Answer: nothing; Make couldn't care less.

: There is perhaps the only real problem.  That's why I always include a
: list of "primary" dependencies in my makefiles, listing any of my own
: header files that my projects depend on.

: >         1) It doesn't cause Make to be aware of the *necessity* of the
: > .d files.  (They are generated as a side effect of using -MD, but Make
: > doesn't know that.)

: But they aren't necessary, except in the rare case you mentioned above
: when somebody both deletes the .d files _and_ changes one or more of the
: dependent headers without changing the source itself.  It seems to be to
: be quite a lot of trouble to go to for a very minor result.  :)

Why not make targets for the .d files? I tried this briefly and it seemed
to work...

As Eli pointed out about a week ago, I suck at makefile programming, but
I haven't yet R'd the FM properly so you'll have to bear with my style.
Here is my proposition (which appears to work as required):

--- makefile ---
all : depend main.exe

depend : *.c *.cc *.h
	gcc -E -MD -o NUL *.c *.cc

main.exe : file1.o file2.o
	gcc -o main.exe file1.o file2.o

DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif
----------------

As I said, my makefile programming is poor, but you can replace the
main.exe rule with whatever it should be. This will first create .d
files for all .c and .cc files whenever any of the .c, .cc or .h files
changes. Then it proceeds as JMA's suggestion earlier.

This worked in every circumstance I could think of, including changing 
any of the .c, .cc or .h files and/or deleting one or all of the .d
files, etc. The only case in which it won't replace a missing .d file
is if there weren't any changes to the source, in which case it isn't
necessary. Recreating the .d files with every source change doesn't 
really hurt, because it's such a fast operation anyway, compared to the
actually compilation and linking.

If I have made any mistakes here, I'd like to hear them; if not, I'll
adopt this style for all my future makefiles, and learn the proper
syntax :)

-- 
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019