1

Since an undefined variable can lead to an unexpected behavior if it is simply replaced with empty text (consider target directories), is there a way to have make check if a variable is undefined and stop with an error in that case?

The condition can be detected with conditionals but then how to stop execution?

ifeq ($(strip $(notdefinedforsure_man)),)
out = Undefined variable detected
endif

I'm looking for something like requiredef var1, var2

or a simple return with error statement to be used in the conditional above

Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
a1an
  • 3,526
  • 5
  • 37
  • 57

1 Answers1

6

Use the origin builtin function:

ifeq (undefined,$(origin VARIABLE))
  $(error VARIABLE is not defined)
endif

See the documentation for details.

Idelic
  • 14,976
  • 5
  • 35
  • 40
  • 1
    Or `$(if $(filter undefined,$(origin VARIABLE)),$(error blurk!))` if you need it inside a macro. – bobbogo Mar 06 '13 at 16:15