Lacking Natural Simplicity

Random musings on books, code, and tabletop games.

Need to specify a file in a GNUmakefile that starts with ~?

Like on macOS Catalina where you can't have directories outside your home directory any more, so need to refer to the directory you manually installed some software to? You can't just include the raw ~/where/ever in that PATH in the GNUmakefile because the ~ prefix won't be translated into the user's home directory. That substitution is done by the shell when a command is executed, but the shells expect that tilde to have been expanded in the command that sets the path. It doesn't do “Tilde Expansion” on each part of the PATH when it goes looking things up in the path. So, you have to get that expansion done manually if you set it in a GNUmakefile.

Anyway, This ugly hack works:

export PATH := $(shell eval dir='~/sw/versions/heirloom-doctools/git/ucb';\
                 echo $$dir):$(PATH)
export TROFFFONTS := $(shell eval dir='~/Library/Fonts';\
        echo $$dir):/Library/Fonts

        @echo PATH=${PATH}
        @echo -n '"type troff" returns '
        @type troff

Put this in a file somewhere and invoke GNU make on it and it prints:

PATH=/Users/tkb/sw/versions/heirloom-doctools/git/ucb:/Users/tkb/local/rndbin:/Users/tkb/.cargo/bin:/Users/tkb/.nimble/bin:/usr/local/opt/libxslt/bin:/usr/local/opt/libxml2/bin:/Users/tkb/sw/versions/mew/git/bin:/Users/tkb/sw/versions/groff-git/bin:/Users/tkb/sw/versions/chibi-scheme/git/bin:/usr/local/opt/tcl-tk/bin:/usr/local/opt/expat/bin:/Users/tkb/.opam/default/bin:/usr/local/opt/texinfo/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/findutils/libexec/gnubin:/usr/local/opt/curl/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/tkb/.local/bin:/Users/tkb/context-osx-64/tex/texmf-osx-64/bin:/Applications/ v7.5/bin:/Users/tkb/go/bin:/Applications/


"type troff" returns troff is /Users/tkb/sw/versions/heirloom-doctools/git/ucb/troff

(Yes, my path may be a little excessive.)

Unfortunately I haven't figured out how to do this with the BSD makes.

Last edited: 2020-08-03 16:03:19 EDT

Print Friendly and PDF


Comments powered by Disqus