The following makefile builds my classwork for my various college classes and builds pdfs to hold the notes I took during class. I would like feedback on my directory structure and any optimizations that can be thought of to help improve it. I've been using and updating it for the past 18 months. I know that I should probably document it a bit better
The directory structure of the classes is as follows
ROOT
|- (class short code)
| |- various subdirs for classwork
|- .. repeated for each of the classes I'm taking this semester
|- old
| |- s1 (classes from semester 1)
| |- s2 (classes from semester 2)
|- mybib.bib (biblatex file for sources)
The makefile is then as follows
# Makefile for college essays
#
PANDOC := pandoc
#LATEX_FLAGS := -interaction=batchmode
SEARCHDIR := $(shell find ./* -prune -type d \( ! -name "old*" \) -print)
LATEXFILES := $(shell find ${SEARCHDIR} -name '*.tex')
MARKDOWN := \
$(shell find ${SEARCHDIR} \( -name '*.md' -and ! -path '*node_modules*' \))
DOT_GRAPHS := $(shell find ${SEARCHDIR} -name '*.dot')
SLIDESHOWS := $(shell find ${SEARCHDIR} -name '*.slideshow')
# Pandoc Stuff
TEMPLATE := college.latex
BIBFILE := mybib.bib
PDFS := $(MARKDOWN:.md=.pdf) $(LATEXFILES:.tex=.pdf)
#DOCX := $(MARKDOWN:.md=.docx)
GRAPHOUT := $(DOT_GRAPHS:.dot=.eps)
SLDESHWOUT := $(SLIDESHOWS:.slideshow=.ss.pdf)
NULLREDIR:= #> /dev/null
# Begin Primary Target
all: $(PDFS) $(GRAPHOUT) $(SLDESHWOUT)
# target to just build the latex documents
latex-out: $(LATEXFILES:.tex=.pdf)
# Clean up targets
clean: mdclean texclean dotclean
mdclean:
rm -f $(PDFS)
texclean:
rm -f *.aux
rm -f *.bbl
rm -f *.bbl
rm -f *.log
rm -f *.blg
rm -f *.xml
rm -f *.out
rm -f *.bcf
dotclean:
rm -f $(GRAPHOUT)
rm -f $(DOT_GRAPHS:.dot=-eps-converted-to.pdf)
#######################################
# Build Rules for Various File Types
#######################################
%.pdf: %.md college.latex apa.csl
$(info $@ from $<)
@${PANDOC} --bibliography ${BIBFILE} --filter pandoc-citeproc \
$< -o $@ --template ${TEMPLATE}
%.pdf: %.tex mybib.bib
-$(info $@ from $<)
-pdflatex ${LATEX_FLAGS} $< $(NULLREDIR)
-if [ -e $(notdir $(basename $<)).bcf ] ; then \
biber $(notdir $(basename $<)).bcf $(NULLREDIR) ; \
else \
bibtex $(notdir $(basename $<)).aux $(NULLREDIR) ; \
fi
-pdflatex ${LATEX_FLAGS} $< $(NULLREDIR)
-pdflatex ${LATEX_FLAGS} $< $(NULLREDIR)
-mv $(notdir $@) $@ $(NULLREDIR)
-rm -f $(basename $<).aux
%.ss.pdf: %.slideshow
pandoc --bibliography ${BIBFILE} -f markdown \
-t beamer $< -o $@
%.eps: %.dot
dot -Teps $< -o $@
%.png: %.dot
dot -Tpng $< -o $@
include depend.makefile