help-make
[Top][All Lists]
Advanced

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

Re: How to generate a warning if the macro called is not defined?


From: Paul Smith
Subject: Re: How to generate a warning if the macro called is not defined?
Date: Thu, 02 Sep 2010 20:02:33 -0400

On Wed, 2010-09-01 at 15:08 -0500, Peng Yu wrote:
> Hi,
> 
> I call a macro that is not defined. It would not generate any error or
> warnings. I looked at the manual section 8.6 "The `call' Function". I
> don't see how to enable warnings or errors for such undefined macro.
> Could you let me know if it is possible to enable the warnings or
> errors for this case?
> 
> $(eval $(call nothing, 1))

Using the undefined variable warning is the only built-in way to do it,
although of course this warns about all undefined variables so it might
be too much.

You can roll your own but unfortunately it requires you to create your
own macros, one for each number of arguments in your call.  For example,
this works:

        FOO = all: ; @echo $1
        
        call1 = $(if $(filter undefined,$(origin $1)),\
                     $(error Undefined variable $1),\
                     $(call $1,$2))
        
        $(eval $(call call1,$X,bar))

Now if you run "make X=FOO" it works but if you run "make X=FO" it will
give an error:

        Makefile:7: *** Undefined variable FO.  Stop.

The problem is that you have to define another value for a call that
takes 2 arguments, etc.:

        call2 = $(if $(filter undefined,$(origin $1)),\
                     $(error Undefined variable $1),\
                     $(call $1,$2,$3))

Etc. I'm not coming up with a way to generalize this, offhand.

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