omtex
aien-dev/omtex
Brought by drakestapleton
| 1 | #!/bin/sh |
| 2 | # build.sh PAPER.om [OUTDIR] -- Omega paper -> generator -> .tex -> (listing check) -> PDF. |
| 3 | # Env: OMC (pinned omc, sha256 checked), OMTEX_NO_PDF=1 to stop after the .tex, |
| 4 | # OMTEX_NICE (default "nice -n 19 ionice -c3") prefixed to every heavy step, |
| 5 | # SOURCE_DATE_EPOCH (default: last commit time of the paper, else 0) for a reproducible PDF. |
| 6 | set -eu |
| 7 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 8 | . "$here/tools/pin.sh" |
| 9 | paper=$1 |
| 10 | out=${2:-build/$(basename "$(dirname "$paper")")} |
| 11 | nice=${OMTEX_NICE-nice -n 19 ionice -c3} |
| 12 | omtex_check_omc |
| 13 | mkdir -p "$out/listings" |
| 14 | name=$(basename "$paper" .om) |
| 15 | cat "$here/lib/omtex.om" "$paper" > "$out/$name.unit.om" |
| 16 | if ! $nice "$OMC" < "$out/$name.unit.om" > "$out/$name.gen" 2> "$out/$name.omc.err"; then |
| 17 | echo "build: omc refused $paper:" >&2; cat "$out/$name.omc.err" >&2; exit 1 |
| 18 | fi |
| 19 | chmod +x "$out/$name.gen" |
| 20 | "$out/$name.gen" > "$out/$name.tex" |
| 21 | "$out/$name.gen" check "$OMC" "$out/listings" > "$out/$name.listings.txt" |
| 22 | cat "$out/$name.listings.txt" |
| 23 | echo "tex sha256 $(sha256sum < "$out/$name.tex" | cut -d' ' -f1) $out/$name.tex" |
| 24 | [ "${OMTEX_NO_PDF:-0}" = 1 ] && exit 0 |
| 25 | src=$(cd "$(dirname "$paper")" && pwd) |
| 26 | if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then |
| 27 | SOURCE_DATE_EPOCH=$(git -C "$src" log -1 --format=%ct -- "$(basename "$paper")" 2>/dev/null || true) |
| 28 | fi |
| 29 | SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-0} |
| 30 | FORCE_SOURCE_DATE=1 |
| 31 | export SOURCE_DATE_EPOCH FORCE_SOURCE_DATE |
| 32 | cd "$out" |
| 33 | run() { TEXINPUTS="$src:" $nice pdflatex -interaction=nonstopmode -halt-on-error -no-shell-escape "$name.tex" > "$name.pdflatex.log" 2>&1 || { tail -30 "$name.pdflatex.log" >&2; exit 1; }; } |
| 34 | run |
| 35 | if grep -q '\\bibdata' "$name.aux"; then BIBINPUTS="$src:" $nice bibtex "$name" > "$name.bibtex.log" 2>&1 || { cat "$name.bibtex.log" >&2; exit 1; }; run; fi |
| 36 | run |
| 37 | unres='Rerun to get\|Reference .* undefined\|Citation .* undefined\|There were undefined references' |
| 38 | if grep -q "$unres" "$name.pdflatex.log"; then echo "build: unresolved references in $name" >&2; grep "$unres" "$name.pdflatex.log" >&2; exit 1; fi |
| 39 | echo "pdf $out/$name.pdf $(pdfinfo "$name.pdf" 2>/dev/null | awk '/^Pages/{print $2}') pages" |