help-make
[Top][All Lists]
Advanced

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

Re: Replacement for .if !target(${foo})


From: Paul D. Smith
Subject: Re: Replacement for .if !target(${foo})
Date: Mon, 7 Oct 2002 15:23:52 -0400

%% Larry Owen <address@hidden> writes:

  lo> First off, I'm not on list, so please include me in on the reply.
  lo> Does anyone have a clever way to recreate the following bsd make
  lo> code with gnu make:

There is no way to do _exactly_ the same thing, because there's no
provision for the kind of introspection provided by the target()
function in BSD make, in GNU make (there was going to be this ability in
3.80 but there was a complication so I disabled it for that release and
deferred it until the next one).

  lo> .for stage in pre post
  lo> .for name in download unpack patch configure \
  lo>              build install link package web

  lo> .if !target(${stage}-${name})
  lo> ${stage}-${name}:
  lo>   @${DO_NOTHING}
  lo> .endif

  lo> .endfor
  lo> .endfor

There are various ways to do things like this.  But, your situation here
is somewhat unique.  If I read the above correctly then what you want to
do is twofold:

 1) Make sure that if someone says "make post-install" for example, make
    does not fail with a "no rule to make target" error.

 2) Allow an individual makefile to include actual rules for some of
    these targets.

If that's what you want, then all you need to do is this:

  STAGES = pre post
  NAMES = download unpack patch configure build install link package web

  ALL_TARGETS = $(foreach stage,$(STAGES),$(addprefix $(stage)-,$(NAMES)))

  .PHONY: $(ALL_TARGETS)

By declaring these targets .PHONY you create them as valid targets, but
do not define any commands for them so make will not complain if they
have commands for them defined elsewhere.

The _only_ difference between the above and what you have is that if
someone does not redefine the target, "make post-unpack" (for example)
will print "nothing to be done for 'post-unpack'", rather than printing
nothing.

-- 
-------------------------------------------------------------------------------
 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]