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

 
 

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

sr #104353: Variables that must be defined

Submitted by:  None
Submitted on:  Thu 23 Jun 2005 07:23:38 PM UTC  
 
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: None
Privacy: PublicAssigned to: None
Originator Email: -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>
Project 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)
endif
endef

else

define exit_ifundef
$1
endef

endif

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:

%.a:
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.

Anonymous

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

No Changes Have Been Made to This Item

Back to the top


Powered by Savane 3.1-cleanup