help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #include in a C file


From: Sam Ravnborg
Subject: Re: #include in a C file
Date: Sun, 5 Dec 2010 10:57:46 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Dec 05, 2010 at 11:48:03AM +0330, ali hagigat wrote:
> This makes each ‘.d’ file depend on all the source and header files
> that the corresponding
> ‘.o’ file depends on. make then knows it must regenerate the
> prerequisites whenever any of
> the source or header files changes.
> -------------------------------------------------------------------------------------------------------------------------
> What is inside each .d file?

Quote from the manual:
=============================================
Here is the pattern rule to generate a file of prerequisites (i.e., a makefile) 
called name.d from a C source file called name.c:

     %.d: %.c
             @set -e; rm -f $@; \
              $(CC) -M $(CPPFLAGS) $< > address@hidden; \
              sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < address@hidden > $@; \
              rm -f address@hidden
See Pattern Rules, for information on defining pattern rules. The ‘-e’ flag to 
the shell causes it to exit immediately if the $(CC) command (or any other 
command) fails (exits with a nonzero status). With the GNU C compiler, you may 
wish to use the ‘-MM’ flag instead of ‘-M’. This omits prerequisites on system 
header files. See Options Controlling the Preprocessor, for details.

The purpose of the sed command is to translate (for example):

     main.o : main.c defs.h
into:

     main.o main.d : main.c defs.h
This makes each ‘.d’ file depend on all the source and header files that the 
corresponding ‘.o’ file depends on. make then knows it must regenerate the 
prerequisites whenever any of the source or header files changes.
=============================================

And you asked "What is inside each .d file?".

If you read the above it is IMO obvious that the content of the .d file in this 
example is the output
of the sed command.
The manual say: "into: main.o main.d : main.c defs.h".

> When a source or header file changes, what prerequisites will be generated?
I can not follow your question. Please provide some more context.
Knowing you have read the manual I assume this is not the simple question it 
looks like.

        Sam



reply via email to

[Prev in Thread] Current Thread [Next in Thread]