0

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?

Yuki Ito
  • 403
  • 4
  • 11

2 Answers2

1

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'
Humm
  • 75
  • 4
0

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}
samthegolden
  • 1,366
  • 1
  • 10
  • 26
  • maybe this is useful for you: https://stackoverflow.com/questions/16035247/get-a-default-value-when-variable-is-unset-in-make – samthegolden Mar 29 '19 at 11:14