archive.pdf: intro.pdf requirements.pdf design-doc.pdf \
    binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \
    binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \
    readme.pdf resources.pdf reflection.pdf listings.pdf images.pdf review.pdf todo.pdf
	pdfjam --no-tidy --outfile archive.pdf -- intro.pdf requirements.pdf design-doc.pdf \
	    binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \
	    binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \
	    readme.pdf resources.pdf reflection.pdf listings.pdf images.pdf review.pdf todo.pdf

todo.pdf: todo.tex
	pdflatex todo.tex

images.pdf: images.tex images/app_main.jpg images/app_editor_1.jpg images/app_editor_2.jpg images/app_graph.jpg images/app_details.jpg \
    images/gateway.jpg images/collar.jpg
	pdflatex images.tex

listings.pdf: listings.tex \
    external/app/app/src/main/java/com/danilafe/fencelessgrazing/requests/LoginRequest.kt \
    external/app/app/src/main/java/com/danilafe/fencelessgrazing/ui/activities/CollarDetailActivity.kt \
    external/app/app/src/main/java/com/danilafe/fencelessgrazing/ui/components/GrazingPolygon.kt \
    external/server/fgs/jwt.py \
    external/server/fgs/views.py \
    external/server/fgs/model.py \
    external/gateway/main.py \
    external/collar/collar.cpp
	pdflatex listings.tex

resources.pdf: resources.tex
	pdflatex resources.tex

reflection.pdf: reflection.tex
	pdflatex reflection.tex

# Generate LaTeX files from READMEs
# Matt's READMEs don't use the convention for headers; we need to update them so that every
# "section" is a subsection and so on. We also insert our own overarching section title.
readme-app.tex: external/app/README.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o readme-app.tex external/app/README.md

readme-cdl.tex: external/cdl/README.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o readme-cdl.tex external/cdl/README.md

readme-server.tex: external/server/README.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o readme-server.tex external/server/README.md

readme-collar.tex: external/collar/README.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o readme-collar.tex external/collar/README.md
	sed -i -e 's/section/subsection/g' readme-collar.tex
	sed -i.old '1s;^;\\section{Collar Firmware};' readme-collar.tex

readme-gateway.tex: external/gateway/README.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o readme-gateway.tex external/gateway/README.md
	sed -i -e 's/section/subsection/g' readme-gateway.tex
	sed -i.old '1s;^;\\section{Gateway Software};' readme-gateway.tex

readme.pdf: readme-app.tex readme-server.tex readme-collar.tex readme-gateway.tex readme-cdl.tex readme.tex
	pdflatex readme.tex

# Generate LaTeX files from code REVIEW files.
review-app.tex: external/app/REVIEW.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o review-app.tex external/app/REVIEW.md
	sed -i -e 's/Code Review Changes/Code Review Changes for Android Application/g' review-app.tex

review-server.tex: external/server/REVIEW.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o review-server.tex external/server/REVIEW.md
	sed -i -e 's/Code Review Changes/Code Review Changes for API Server/g' review-server.tex

review-collar.tex: external/collar/REVIEW.md
	pandoc -f markdown-auto_identifiers -t latex --no-highlight -o review-collar.tex external/collar/REVIEW.md
	sed -i -e 's/Code Review Changes/Code Review Changes for Collar Firmware/g' review-collar.tex

review.pdf: review-app.tex review-server.tex review-collar.tex review.tex
	pdflatex review.tex

intro.pdf: intro.tex
	pdflatex intro.tex

blog-daniel.pdf: external/blog-daniel/blog.tex
	cd external/blog-daniel && pdflatex -output-directory=../.. blog.tex && pdflatex -output-directory=../.. blog.tex
	mv blog.pdf blog-daniel.pdf

techreview-daniel.pdf: external/techreview-daniel/techreview.latex
	cd external/techreview-daniel && pdflatex -output-directory=../.. techreview.latex && pdflatex -output-directory=../.. techreview.latex
	mv techreview.pdf techreview-daniel.pdf

design-doc.pdf: external/design/dd.tex
	cd external/design && pdflatex -output-directory=../.. dd.tex && pdflatex -output-directory=../.. dd.tex
	mv dd.pdf design-doc.pdf

requirements.pdf: external/requirements/requirements.latex
	cd external/requirements && pdflatex -output-directory=../.. requirements.latex && pdflatex -output-directory=../.. requirements.latex

clean:
	rm -rf *.pdf *.out *.aux *.log *.toc readme-*.tex *.old review-*.tex

.PHONY: clean
