mainmake - Support: sr #104353, Variables that must be defined


You are not allowed to post comments on this tracker with your current authentication level.

sr #104353: Variables that must be defined

Submitter:  None
Submitted:  Thu 23 Jun 2005 07:23:38 PM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None

Sun 12 Mar 2006 01:57:08 PM UTC, comment #3: 

It seems a global behaviour is preferable. I think a make option which warns and possibly exists on undefined or empty variables is a better choice.
It lets you descover issues you didn't think about in the first place and may give a strict coding convention for users.
And you don't have the drag of treating parameters selectivly (also keeps the code cleaner).

Alon Blayer-Gat <alonbg>
Wed 08 Feb 2006 05:41:46 PM UTC, comment #2: 

I think you could make it slightly tidier, but the definition here seems to me to be the right way to go... but you need to decide whether you want to fail if a variable is empty, or only if it's not defined at all.  The previous example shows how to check if it's defined at all; this one assumes an empty variable is still an error:

exists = $(if $($1),$($1),$(error $1 has no value))

foo: @echo $(call exists,FOO)

It would be nicer if there were some syntactic sugar for calls to make this shorter.  Also, one disadvantage of this is that the variable is evaluated twice, which is a drag... the other option (checking for undefined) is more efficient in that respect.

Paul D. Smith <psmith>
Group administrator
Tue 02 Aug 2005 12:42:11 AM UTC, comment #1: 

You may as well write:

ifeq ($(DEBUG),on)

define exit_ifundef
 ifeq ($(origin $1),undefined)
  $(error $1 is not defined)


define exit_ifundef


Alon Blayer-Gat <alonbg>
Thu 23 Jun 2005 07:23:38 PM UTC, original submission:  

GNU Make currently has very little inherent support for debugging makefiles.  One simple change could help a lot:  adding a new type of variable reference that requires that the variable be defined.  If the variable were not defined, make would stop with an informative error message.  For example, if the syntax of a required reference were $(!varname), then one could write:

    ar rs $@ $(!^)

This would mean that it would be required that $^ be non-empty so that this rule would not create an empty archive file.

I've come across dozens of situations where I would use this feature if it existed.  On many occasions I've spent half an hour figuring out why a makefile doesn't work, when this feature would have told me instantly what the problem was.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


No changes have been made to this item

Back to the top

Powered by Savane 3.13-9c15.
Corresponding source code