add handcrafted make script
authorMart Lubbers <mart@martlubbers.net>
Tue, 4 Jul 2017 07:14:18 +0000 (09:14 +0200)
committerMart Lubbers <mart@martlubbers.net>
Tue, 4 Jul 2017 07:14:18 +0000 (09:14 +0200)
build.sh [new file with mode: 0644]
presentation.pre [moved from presentation/presentation.pre with 100% similarity]
presentation.tex [moved from presentation/presentation.tex with 100% similarity]
presentation/Makefile [deleted file]

diff --git a/build.sh b/build.sh
new file mode 100644 (file)
index 0000000..369eb3d
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,91 @@
+#!/bin/bash
+set -e
+LATEXFLAGS="-file-line-error -halt-on-error"
+
+docs=( thesis presentation )
+
+log(){
+       echo $1 >&2
+}
+
+deps(){
+       [[ "$1" != *.tex && "$1" != *.pre ]] && fn="$1.tex" || fn="$1"
+       echo "$fn"
+       grep -Po '(?<=\\input{).*(?=})|(?<=\\include{).*(?=})' $fn |\
+               while read l; do deps "$l"; done
+}
+
+recompile(){
+       for dep in $(deps "$1"); do
+               [ "$dep" -nt "$2" ] && return 0
+       done
+       return 1
+}
+
+preamble(){
+       pdflatex $LATEXFLAGS -ini -jobname="$2" "&pdflatex $1\dump"
+}
+
+compile(){
+       pdflatex $LATEXFLAGS $1
+       grep -q '^\\bibdata{' $1.aux && bibtex $1
+       grep -q '\@istfilename' $1.aux && makeglossaries $1
+       [ -f $1.idx ] && makeindex $1
+       tmpf=$(mktemp)
+       trap RETURN rm -v $tmpf
+       pdflatex $LATEXFLAGS $1 | tee $tmpf
+       grep -Fiq "Rerun" $tmpf && $LATEX $LATEXFLAGS $1
+       rm -vf $tmpf
+}
+
+pipeline(){
+       log "Processing $1"
+       if [ ! -f $1.tex ]; then
+               log "Skipping $1, no tex available"
+       else
+               # Check for preamble
+               [ -f preamble.tex ] && pre=preamble.tex
+               [ -f $1.pre ] && pre=$1.pre
+
+               if [ ! -z $pre ]; then
+                       log "preamble found"
+                       recompile $pre $1.fmt\
+                               && preamble $pre $1\
+                               || log "preamble up to date"
+               fi
+       
+               # Compile document
+               recompile "$1.tex" "$1.pdf"\
+                       && compile $1\
+                       || log "document up to date"
+       fi
+}
+
+clean(){
+       while [ $# -ne 0 ]; do 
+               log "Clean $1"
+               rm -fv $1.{acn,acr,alg,aux,bbl,blg,idl,idx,ilg,ind,fmt,glg,glo,gls,\
+ist,loa,lof,log,lol,lot,nav,out,pdf,snm,tdo,toc}
+               shift
+       done
+}
+
+if [ $# -eq 0 ]; then
+       for doc in "${docs[@]}"; do
+               pipeline $doc
+               log ""
+       done
+else
+       while [ $# -ne 0 ]; do
+               if [ $1 = "clean" ]; then
+                       if [ $# -eq 2 ];
+                       then clean $d
+                       else clean "${docs[@]}"
+                       fi
+               else
+                       pipeline $1
+               fi
+               shift
+       done
+fi
+
diff --git a/presentation/Makefile b/presentation/Makefile
deleted file mode 100644 (file)
index 8aeb1d6..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-DOCS:=presentation
-GREP?=grep
-LATEX?=pdflatex
-BIBTEX?=bibtex
-BIBTEXFLAGS:=
-MAKEGL?=makeglossaries
-MAKEGLFLAGS?=
-MAKEIDX?=makeindex
-MAKEIDXFLAGS?=
-DOT?=dot
-DOTFLAGS?=-Tpng
-LATEXFLAGS:=-file-line-error -halt-on-error
-
-FIGURES:=$(patsubst fig/%.dot,img/%.png,$(wildcard fig/*.dot))
-LISTINGS:=$(wildcard listings/*)
-TEXS:=$(wildcard *.bib)
-BIBS:=$(wildcard *.tex)
-
-.PHONY: all clean
-.SECONDARY: $(DOCS:%=%.fmt) $(FIGURES)
-
-all: $(DOCS:%=%.pdf)
-
-%.fmt: %.pre
-       $(LATEX) $(LATEXFLAGS) -ini -jobname="$(basename $<)" "&$(LATEX) $<\dump"
-
-%.pdf: %.mlog
-       if grep -Fiq "Rerun" $<; then $(LATEX) $(LATEXFLAGS) $(basename $<); fi
-
-%.mlog: %.tex %.fmt $(BIBS) $(TEXS) $(FIGURES) $(LISTINGS)
-       $(LATEX) $(LATEXFLAGS) $<
-       if $(GREP) -q '^\\bibdata{' $(basename $<).aux; then $(BIBTEX) $(BIBTEXFLAGS) $(basename $<); fi
-       if $(GREP) -q '\@istfilename' $(basename $<).aux; then $(MAKEGL) $(MAKEGLFLAGS) $(basename $<); fi
-       if [ -f $(basename $<).idx ]; then $(MAKEIDX) $(MAKEIDXFLAGS) $(basename $<); fi
-       $(LATEX) $(LATEXFLAGS) $< | tee $@
-
-img/%.png: fig/%.dot
-       $(DOT) $(DOTFLAGS) $< > $@
-
-clean: $(DOCS:%=clean-%)
-       $(RM) $(FIGURES)
-
-clean-%:
-       $(RM) $(addprefix $(@:clean-%=%).,acn acr alg aux bbl blg idl idx ilg ind\
-       fmt glg glo gls ist loa lof log lol lot mlog nav out pdf snm tdo toc)