#!/bin/bash
# build.sh
# GPLv3+
set -x

# A function to jump to application's root, default .../forksand-it-manual
cd $(echo $PWD | sed -e "s/\(.*\/forksand-it-manual\)\/.*/\1/") && echo "current path: $PWD"
rootPath=$PWD

cd source || exit
# Generate Source-gen.tex, for auto source code inclusion
rm -f forksand-it-manual.pdf ../forksand-it-manual.pdf
time ./resources/make-sources-list.sh

# A function to jump to application's root, default .../forksand-it-manual
cd $(echo $PWD | sed -e "s/\(.*\/forksand-it-manual\)\/.*/\1/") && echo "current path: $PWD"
cd source/ || exit

# Build main LaTeX file
# Run BibTeX
#bibtex                                                                  \
#        forksand-it-manual
# Build PDF
xelatex                                                                 \
         -halt-on-error                                                  \
         -shell-escape                                                   \
         -interaction=nonstopmode                                        \
        forksand-it-manual.tex

makeglossaries-lite "forksand-it-manual"

for i in $(ls *.pdf); do mv -f $i ../$i ; done # in windows every file must be processed explicitly

exit 0

# Use latexmk for final build, takes 5x+ longer to run...
latexmk									\
	-xelatex							\
        -halt-on-error                                                  \
        -shell-escape                                                   \
        -interaction=nonstopmode                                        \
        forksand-it-manual.tex

# Faster, may not be enough runs:
xelatex                                                                 \
         -halt-on-error                                                  \
         -shell-escape                                                   \
         -interaction=nonstopmode                                        \
        forksand-it-manual.tex
