Newer
Older
templates / latex / labs / Makefile
Mark on 22 May 2015 1 KB Minor tweaks.
  1. # Makefile for latex documents.
  2.  
  3. # Author: Mark George <mgeorge@infoscience.otago.ac.nz>
  4.  
  5. # driver file (tries to automatically find the driver file)
  6. SOURCE=$(basename $(or $(wildcard lab*.tex), $(wildcard test*.tex), $(wildcard outline.tex), $(wildcard project*.tex),$(wildcard *exercises.tex),$(wildcard *report.tex),$(wildcard phase*.tex),$(wildcard lec*.tex)))
  7. # if the driver file isn't one of the above then just set the value of the SOURCE variable to the name WITHOUT the extension
  8.  
  9.  
  10. # preamble file
  11. PREAMBLE=preamble
  12.  
  13. # files that will be deleted when we clean
  14. RUBBISH=*.aux *.out *.dvi *.log *.ps *~ *.*~ auto *.toc *.fdb_latexmk *.fls
  15.  
  16. # latex command
  17. LATEX=pdflatex
  18.  
  19. .PHONY: clean
  20.  
  21. default: texify clean-rubbish
  22.  
  23. pdf: default
  24.  
  25. 2up: pdf
  26. # spit out a 2up driver
  27. echo "\documentclass{article}\usepackage{pdfpages}\usepackage[a4paper,landscape, pdftex,vmargin=0in,hmargin=0.0in]{geometry}\begin{document}\includepdf[nup=2x1,frame,pages=-,delta=0mm 0mm]{%" >| 2up.tex
  28. echo ${SOURCE}.pdf% >> 2up.tex
  29. echo "}\end{document}" >> 2up.tex
  30.  
  31. # texify it
  32. ${LATEX} 2up.tex
  33.  
  34. # clean up
  35. rm 2up.tex
  36. mv 2up.pdf ${SOURCE}_2up.pdf
  37.  
  38. # get rid of any additional generated rubbish
  39. rm -rf $(RUBBISH)
  40.  
  41. # texify target
  42. texify: ${SOURCE}.pdf
  43.  
  44. # compile as many times as needed (at least twice to get PDF bookmarks right) to sort out references and labels
  45. ${SOURCE}.pdf: ${SOURCE}.tex ${PREAMBLE}.tex
  46. $(LATEX) ${SOURCE}.tex
  47. $(LATEX) ${SOURCE}.tex
  48.  
  49. # once more if there are still undefined references
  50. if [ -n "$(shell grep 'There were undefined references' ${SOURCE}.log)" ]; then $(LATEX) ${SOURCE}.tex ; fi
  51.  
  52. # once more if there are labels that have changed
  53. if [ -n "$(shell grep 'Label(s) may have changed' ${SOURCE}.log)" ]; then $(LATEX) ${SOURCE}.tex ; fi
  54.  
  55. # delete unwanted generated files
  56. clean-rubbish:
  57. rm -rf $(RUBBISH)
  58.  
  59. # delete ALL generated files
  60. clean: clean-rubbish
  61. rm -rf ${SOURCE}.pdf ${SOURCE}_2up.pdf
  62.