#!/bin/bash echo 'ninja_dyndep_version = 1' src="$1" dst="$2" tgt="${dst%%.*}.pdf" temp="$(mktemp -p .)" trap 'rm -rf ${temp} ${temp}.*' EXIT INT cp "$src" "$temp.tex" xelatex -recorder "$temp.tex" >/dev/null deps="$(awk -v ORS=' ' -v "temp=$temp" -v "repl=${src%%.*}" '/INPUT \./ {gsub(temp,repl,$2); print $2}' < "$temp.fls")" outs="$(awk -v ORS=' ' -v "temp=${temp#*/}" -v "repl=${dst%%.*}" '/OUTPUT / {gsub(temp,repl,$2); print $2}' < "$temp.fls")" echo -n "build $tgt" [ -z "$outs" ] || echo -n " | $outs" echo -n " : dyndep" [ -z "$deps" ] || echo -n " | $deps" echo