Search code examples
shellplan-9rc-shell

How can I define the default value for a variable in mkfile


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?


Solution

  • 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'