dotfiles / latex.Makefile

# Makefile for LaTeX file.

INDEX = index
PDF = report
BIB = bibliography
TMP = .tmp
DEL = /
VIEWER = evince
TEX_FILES := $(wildcard *.tex)
TEX_ARGS := -halt-on-error -output-directory $(TMP)

.PHONY = short report all clean show count spell smell

# Compile without bibtex, faster than the whole report
short: compilefast show

# Compile the whole thing
report: compile show

# Compile and clean up
all: compile clean show

# Show the generated pdf file
show: $(PDF).pdf
	$(VIEWER) $(PDF).pdf &

# Count number of words in report
	@echo "Counting words in report"
	@texcount -utf8 -total -inc -sum $(INDEX).tex

# Run spellchecker
	@echo "Running spell check on report"
	@$(foreach FILE, $(TEX_FILES), aspell check $(FILE);)

# TODO: Check report for smelly writing
	@echo "Checking report for smelly writing"

# Compile report with only two passes
compilefast: $(INDEX).tex
	@mkdir $(TMP) -p
	@pdflatex $(TEX_ARGS) $(INDEX)
	@pdflatex $(TEX_ARGS) $(INDEX)
	@mv $(TMP)$(DEL)$(INDEX).pdf $(PDF).pdf

# Compile report and bibliography, require three passes
compile: $(INDEX).tex $(BIB).bib
	@mkdir $(TMP) -p
	@pdflatex $(TEX_ARGS) $(INDEX)
	@cp $(BIB).bib $(TMP)$(DEL)
	-@cd $(TMP) && bibtex $(INDEX)
#	-@cd $(TMP) && makeglossaries $(INDEX)
	@pdflatex $(TEX_ARGS) $(INDEX)
	@pdflatex $(TEX_ARGS) $(INDEX)
	@mv $(TMP)$(DEL)$(INDEX).pdf $(PDF).pdf

# Remove all generated files
	@echo "Removing LaTeX build files"
	@rm -fr .tmp/
	@rm -f *.aux *.toc *.log *.lof *.bbl *.blg *.acn *.out *.lot