Reputation: 513
Makefile:
XDG_CONFIG_HOME?=$HOME/.config
I want convert the line to Plan9 mkfile syntax.
I tried
XDG_CONFIG_HOME=`{if(~ $XDG_CONFIG_HOME '') echo $HOME/.config; if not echo $XDG_CONFIG_HOME}
and it worked but it's ugly. Any alternative?
Upvotes: 0
Views: 176
Reputation: 85
mk(1) doesn’t provide such a built-in way of defining variables only if they aren’t non-empty environment variables. Actually, neither any make(1) from Bell Labs nor POSIX make(1) provide such a way to do that, the ?=
syntax is just a GNU extension.
What you usually would do is in your mkfile
just set the variable normally:
XDG_CONFIG_HOME = $home/.config
and overwrite the variable in the mk(1) command:
; mk 'XDG_CONFIG_HOME='^$home^'/cfg'
Upvotes: 1
Reputation: 1490
In shell, ":-" is used to set a variable to a default value in case the variable has no value:
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
Upvotes: 0