I want to set a variable if it is empty. I tried in this way:
....
TEST := $(something)
...
TEST ?= $(something else)
The first $(somethi
Any elegant solution to set the variable if empty?
GNU make is hardly known for elegant solutions. Unless you find trapdoors and minefields to be elegant. I know only of the two ways to accomplish what you want:
The standard ifeq
/endif
solution:
ifeq ($(TEST),)
TEST := $(something else)
endif
Use the $(if)
function:
TEST := $(if $(TEST),$(TEST),$(something else))
One can try to package that construct into a function too, but that is inadvisable. The function would have the hidden pitfall of occasionally breaking the $(something else)
if it contains the ,
(for which there are only wayward workarounds). (The built-in functions like $(if)
are immune to the ,
bug.)
Elegance test is up to you.