[Top][All Lists]

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

Re: some questions about GNU make

From: Paul Smith
Subject: Re: some questions about GNU make
Date: Sun, 15 Aug 2010 10:21:27 -0400

On Sun, 2010-08-15 at 16:32 +0430, ali hagigat wrote:
> To this end, after reading in all makefiles, make will consider each as
> a goal target and attempt to update it. If a makefile has a rule which
> says how to update it (found either in that very makefile or in another
> one) or if an implicit rule applies to it (see Chapter 10 [Using
> Implicit Rules], page 101), it will be updated if necessary.
> After all makefiles have
> -------------------------------------------------------------------------

> It says: " make will consider each as a goal target.."
> Will consider what? Each makefile?

Yes.  If you read each part of a sentence without the context of it's
previous parts or sentences, it's hard to understand.  The sentence
says, "after reading in all makefiles, make will consider each as a goal
target".  The "each" here clearly refers to the previous subject; that
is, the makefiles that make read in.

> as far as I know a makefile tries to update a default goal file by
> running its commands. Where is the commands and rules for these
> makefiles?

The documentation tells you: "if a makefile has a rule which says how to
update it" (again, "it" here refers to the previous subject: "a
makefile") ... "found either in that very makefile" ... so one way it
could be found is if you wrote yourself in your makefile; for example:

        include ; @echo 'all: ; @echo hi from' > $@

now you have a makefile that includes a makefile "" and also has a
rule that says how to create a target "".

> What does "updating a makefile" mean? How it is related to RCS and
> SCCS files?

"Updating" a target is well-defined in the manual; it means running a
recipe that causes the target to be brought up-to-date with respect to
its prerequisites.

The documentation above continues: "or if an implicit rule applies to
it".  One type of implicit rule would be the built-in pattern rules for
RCS or SCCS files... basically, these implicit rules allow make to check
out a copy of a file from either of those source code control systems,
which is why they're mentioned.  If you don't know anything about RCS or
SCCS and are not using them, then you can ignore these comments since
they are not relevant to you.

But there may be other implicit rules that apply; maybe your makefile
looked like this:

        include : ; @echo 'all: ; @echo hi from $@' > $@

Now you have your own implicit rule.

> "If a makefile has a rule which says how to update it (found either in
> that very makefile)..."
> Can a makefile update itself by its own rule?

Yes.  That's exactly what this is saying.  Make reads in all the
makefiles.  Then it considers every makefile it read in as a target and
sees whether those makefiles can be updated using make's normal target
updating procedures.

If one or more makefile is updated, then make will re-exec itself so
that these new versions of the makefile will be read in, and the whole
thing starts over again.

Once no makefiles are updated during this first step, then make proceeds
to run the "normal" rules defined in the makefile.

> Can you write a simple makefile to do it?

Yes, see above with "".  Also see the GNU make section "Generating
Prerequisites Automatically" which provides a practical example of how
this feature might be used in real life... although that method for
generating prerequisites automatically is no longer considered the best
method; it has a number of issues.

But it still shows an example of this feature in use.

 Paul D. Smith <address@hidden>          Find some GNU make tips at:            
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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