help-make
[Top][All Lists]
Advanced

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

RE: Why are circular rules not supported


From: Paul D. Smith
Subject: RE: Why are circular rules not supported
Date: Tue, 22 Nov 2005 12:52:40 -0500

%% "Olivier Cailloux" <address@hidden> writes:

  oc> (Now I also wonder why it's not allowed to have only one explicit
  oc> rule to build any given target, but that's OT, let's stuck on the
  oc> main question.)

The POSIX standard for make requires it to be an error.

Of course, it could be supported as an extension, I suppose.

  oc> In your example, make has indeed to issue an error. Now let me
  oc> take an example like my first one, but with pattern rules instead.

  oc> %.pdf: %.ps
  oc>   (some rules...)

  oc> %.ps: %.pdf
  oc>   (some rules...)

  oc> %.ps: %.dvi
  oc>   (some rules...)

OK, this makes more sense now.

  oc> Here the second two rules are allowed AFAIU.

They are, but please be clear on what it means to have multiple patterns
with the same target pattern: in this case make will start with the
first pattern rule and walk through to the end.  For each pattern which
matches the file we want to build, it expand the prerequisite patterns
and then, just as with any other rule, it will try to verify whether
those can be built or not using standard make algorithms.

The only difference comes when make decides that the prerequisite
doesn't exist and make doesn't know how to build it: in that case,
instead of printing an error and failing make will proceed through the
rest of the defined patterns looking for another one that will match.
Only if all defined patterns fail to match will make fail.

  oc> make simply has to refuse building "chained rules" containing
  oc> something recursive. But it should not automatically reject a
  oc> makefile when it contains potentially recursive rules.

You are suggesting changing the above algorithm so that detection of a
recursion would cause that pattern to not match, but would allow
subsequent patterns to continue, is that correct?

  oc> Simply because there is no other way (except if I'm missing
  oc> something) to tell in a single makefile how to produce a pdf from
  oc> a ps (where a ps is available or can be derived from other means
  oc> than going through a pdf) AND how to produce a ps from a pdf
  oc> (where a pdf is available or can be derived from other means than
  oc> going through a ps).

Well, you could do something like this:

    ifneq (,$(filter %.pdf,$(MAKECMDGOALS)))
       %.pdf : %.ps
            ...
    else
       %.ps : %.pdf
            ...
    endif

And you could make it even fancier by using $(wildcard ...) to test
whether files of certain types existed.  Not very nice, but it's
something.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "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]