interplane.Get Omega
Read in your language

omtex

aien-dev/omtex

Brought by drakestapleton

branch main Branches Tags History

omtex / tools / build.sh

39 lines · 2118 bytes Raw Blame History
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.
6set -eu
7here=$(cd "$(dirname "$0")/.." && pwd)
8. "$here/tools/pin.sh"
9paper=$1
10out=${2:-build/$(basename "$(dirname "$paper")")}
11nice=${OMTEX_NICE-nice -n 19 ionice -c3}
12omtex_check_omc
13mkdir -p "$out/listings"
14name=$(basename "$paper" .om)
15cat "$here/lib/omtex.om" "$paper" > "$out/$name.unit.om"
16if ! $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
18fi
19chmod +x "$out/$name.gen"
20"$out/$name.gen" > "$out/$name.tex"
21"$out/$name.gen" check "$OMC" "$out/listings" > "$out/$name.listings.txt"
22cat "$out/$name.listings.txt"
23echo "tex sha256 $(sha256sum < "$out/$name.tex" | cut -d' ' -f1) $out/$name.tex"
24[ "${OMTEX_NO_PDF:-0}" = 1 ] && exit 0
25src=$(cd "$(dirname "$paper")" && pwd)
26if [ -z "${SOURCE_DATE_EPOCH:-}" ]; then
27 SOURCE_DATE_EPOCH=$(git -C "$src" log -1 --format=%ct -- "$(basename "$paper")" 2>/dev/null || true)
28fi
29SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-0}
30FORCE_SOURCE_DATE=1
31export SOURCE_DATE_EPOCH FORCE_SOURCE_DATE
32cd "$out"
33run() { 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; }; }
34run
35if 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
36run
37unres='Rerun to get\|Reference .* undefined\|Citation .* undefined\|There were undefined references'
38if grep -q "$unres" "$name.pdflatex.log"; then echo "build: unresolved references in $name" >&2; grep "$unres" "$name.pdflatex.log" >&2; exit 1; fi
39echo "pdf $out/$name.pdf $(pdfinfo "$name.pdf" 2>/dev/null | awk '/^Pages/{print $2}') pages"