pathtexbsdmake

Turn a list of words in a path string in BSD Make


I am preparing a Makefile for a TeX document and I want to customize the TEXINPUTS environment variable, as follows:

The Makefile says

TEXINPUTS= figures
TEXINPUTS+= chapter1
TEXINPUTS+= chatper2

galley.pdf: ${SRCS}
    env TEXINPUTS="${TEXINPUTSPATH}" ${TEX} galley.tex

Where TEXINPUTSPATH should be figures:chapter1:chapter2:.

How can I compute TEXINPUTSPATH from TEXINPUTS with BSD Make?


Solution

  • The naive approach TEXINPUTSPATH=${TEXINPUTS:S/ /:} will not work, because the substitution commanded by S is done on each word of TEXINPUTS. Luckily, we can use Q to quote each space and turn TEXINPUTS into a single word:

    TEXINPUTSPATH=${TEXINPUTS:Q:S/\ /:/g}