You can combine the shell's facilities with Make's to get a fairly succinct definition.
define compile
@dir="${1}"; outdir="${2}"; outdir=$${outdir:-"$dir"}; \
$(COMPILER) -output-directory "$${outdir}" "$${dir:-.}/*.tex
The double-dollar is an escape which passes a single dollar sign to the shell. The construct ${variable:-value}
returns the value of $variable
unless it is unset or empty, in which case it returns value
. Because ${1}
and ${2}
are replaced by static strings before the shell evaluates this expression, we have to take the roundabout route of assigning them to variables before examining them.
This also demonstrates how to combine two "one-liners" into a single shell invocation. The semicolon is a statement terminator (basically equivalent to a newline) and the sequence of a backslash and a newline causes the next line to be merged with the current line into a single "logical line".
This is complex enough that I would recommend you omit the leading @
but I left it in just to show where it belongs. If you want silent operation, once you have it properly debugged, run with make -s
.