# LaTeX Makefile # -------------- # # Author : s.m.vandenoord@student.utwente.nl (Stefan van den Oord) # Date : March 18, 1999, second version of today. # # This Makefile is a generic makefile for LaTeX documents. Distribute it # as you wish, but please don't edit or remove this initial comment. # # The Makefile can be used by setting the environment variable "MAKEFILES", # e.g. export MAKEFILES=~/Latexmakefile. # It requires GNU Make and bash or better, like zsh. Simply sh is not # sufficient, I believe. The first few lines of the Makefile contains # the executables that are used, edit them to point to the executables # on your system. # # DISCLAIMER: Using this Makefile is fully at your own risk. I am not # responsible for anything! So if crucial files are removed # by the Makefile, it is your own problem. But you should # have backups anyway. :-) # Usage # ----- # The Makefile can do the following things for you: # - generate PostScript equivalents of XFig figures; # - run makeindex and BibTeX, but only if necessary; # - compile the .dvi file, running LaTeX as many times as needed; # - run XDvi with the compiled .dvi file; # - create a PostScript equivalent of the .dvi file; # - generate a HTML equivalent of the .dvi file (if Latex2HTML is # installed); # - remove all generated output. # The Makefile is in some points even RCS aware. # # In many cases, you don't even have to tell the Makefile which LaTeX # file it has to compile. The Makefile uses the following strategy: # 1. Check if the environment variable LATEXTARGET is set; if it is, # generate $LATEXTARGET.dvi. # 2. If there is only one .tex file, use that one. # 3. Check if there is a LaTeX file that has the same basename as the # directory. For example, if the directory is named "Thesis" and # there is a file "Thesis.tex", "Thesis.dvi" is generated. # Invocation # ---------- # When the MAKEFILES environment variable is set, you can use the # following commands: # - make latexhelp # Prints an overview of the available commands. # - make file.dvi # Generates the specified DVI file. # - make file.ps # Generates the DVI file and then runs dvips. # - make latex # Use the above explained strategy to find out what has to be # generated, and generate it. # - make view # Do a make latex and then run XDvi. # - make latexps # Do a make latex and then run dvips. # - make html # Do a make latex and then use LaTeX2HTML to create the HTML equivalent. # To do this, the following environment variables are used: # * HTMLDIR : the base dir in which the output is written. For example, # if HTMLDIR=~/public_html/LaTeX, and the file that is # generated is "Thesis", the output will be written in the # directory ~/public_html/LaTeX/Thesis. # * LATEX2HTML_OPTS : if you want to pass options to LaTeX2HTML, put # them in this variable. # - make latexclean # This command removes all generated output. CAUTION: the files that are # removed are thought out pretty well, but it is possible that files are # removed that you wanted to keep! Check below what files are removed if # you want to be certain! # Note that a file figure.eps is only removed if a file figure.fig exists. # (Even if the file figure.fig exists, but is checked in using RCS, the # file figure.eps will be removed.) # Tip # --- # For some projects it is useful to have a separate Makefile in the project's # directory. For example, when you use RCS, you could add functionality for # automatic checkouts of the right files (adding dependencies is sufficient; # GNU Make rocks :-). # The command "latexclean" is declared so that you can add your own # functionality in the project's Makefile; instead of one colon, declare it # with two colons if you want to do that. # For example: # latexclean:: # rm -f foo.bar # This way both the origional definition in this Makefile and your own are # used. # # If you get tired of changing the LATEXTARGET variable, you could try # something like this to always select the newest tex file with a valid # documentclass in the current directory to be processed: # # --- 8< --- # include ~/Latexmakefile # include target # # target: *.tex # echo -n "LATEXTARGET = " >$@ # basename `ls -tr \`grep -l documentclass *.tex\` | tail -n1` .tex >>$@ # cat $@ # --- >8 --- # Caution # ------- # Do not use with the -f flag. The recursive calls of Make will not inherit # this flag. Use the environment variable MAKEFILES instead. # # Be careful with the -n flag. Some calls are still made and some files are # still generated. It's basically restricted to all if-blocks that include a # recursive $(MAKE) call, so not too much harm is done. # Changelog # --------- # # Added pdf-output and glossary-support # 24.11.2004 Steffen Wolf # # Added some color # Suggesting a way to include all fonts in the pdf output # Removed the automatic creation of figures # -> use an additional rule instead: $(LATEXTARGET).aux: inputfiles # Changed the bibtex trigger to catch changes in the used bibfiles as well # 12.3.2008 Steffen Wolf # # Deleted some unnecessary calls when run with --dry-run # There are still some calls to generate .itmp and .gtmp files in this version! # The HTML target is also still not safe! # 19.3.2008 Steffen Wolf #.SILENT: # SHELL=/usr/local/bin/bash # When including this in another Makefile you should specify the target: # LATEXTARGET = LATEX = latex BIBTEX = bibtex DVIPS = dvips MAKEINDEX = makeindex #DVIVIEWER = xdvi DVIVIEWER = xdvi -expert >/dev/null 2>&1 PSVIEWER = gv PDFVIEWER = gv LATEX2HTML = latex2html GLOSSARSTYLE = glossary.ist # to include all fonts in the pdf file: #PSTOPDF = ps2pdf14 -dPDFSETTINGS=/printer PSTOPDF = ps2pdf PAPERSIZE = a4 BIBFILES = $(wildcard *.bib) TEXFILES = $(wildcard *.tex) # Add some color to your life: GREP = grep --color GREPY = GREP_COLOR='01;38;5;3' $(GREP) EM =  EMG =  EMY =  NOEM =  # Disable standard pattern rule: %.dvi: %.tex # Do not delete the following targets: .PRECIOUS: %.aux %.bbl %.eps %.ind %.glx %.ps %.dvi # These targets do not generate files: .PHONY: view ps pdf viewps viewpdf \ %.viewdvi %.viewps %.viewpdf \ clean reallyclean latexclean latexhelp \ latex %.rerun %.aux: %.tex $(TEXFILES) @$(LATEX) $* # Look for citations. Make sure grep never returns an error code. @grep "^\\\\\(citation\|bibstyle\|bibdata\)" *.aux > .btmp.new || true # If the citations are not changed, don't do anything. Otherwise replace # the .btmp file to make sure Bibtex will be run. @if ( diff .btmp.new .btmp >& /dev/null ); then \ rm .btmp.new; \ else \ mv .btmp.new .btmp; \ fi @if [ -f $*.idx ]; then cp $*.idx .itmp.new; else touch .itmp.new; fi @if ( diff .itmp.new .itmp >& /dev/null ); then \ rm .itmp.new; \ else \ mv .itmp.new .itmp; \ $(MAKE) $*.ind; \ fi @if [ ! -s .itmp ] ; then rm .itmp ; fi @if [ -f $*.glo ]; then cp $*.glo .gtmp.new; else touch .gtmp.new; fi @if ( diff .gtmp.new .gtmp >& /dev/null ); then \ rm .gtmp.new; \ else \ mv .gtmp.new .gtmp; \ $(MAKE) $*.glx; \ fi @if [ ! -s .gtmp ] ; then rm .gtmp ; fi .btmp: %.bbl: $(BIBFILES) .btmp # Only use BibTeX if \bibliography occurs in the document. In that case, # run BibTeX and recompile. .btmp is touched to prevent useless making # next time. @if ( grep "\\\\bibdata{" $*.aux > /dev/null ); then \ $(BIBTEX) $* || echo "$(EM)There were some errors doing the bib!$(NOEM)";\ touch .rerun; \ fi @if [ -s .btmp ] ; then \ touch .btmp ;\ else \ rm -f .btmp ;\ fi .itmp: %.ind: .itmp @if [ -f $*.idx ]; then \ $(MAKEINDEX) $*; \ touch .rerun; \ touch .itmp; \ fi .gtmp: %.glx: .gtmp @if [ -f $*.glo ]; then \ $(MAKEINDEX) -s $(GLOSSARSTYLE) -o $@ $*.glo; \ touch .rerun; \ touch .gtmp; \ fi %.eps:%.fig @echo Generating figure $@ ... @fig2dev -L eps $< $@ %.dvi: %.aux %.glx %.bbl # Make sure the dvi-file exists; if not: recompile. @if [ ! -f $*.dvi ]; then \ touch .rerun; \ fi @if [ -f .rerun ]; then \ $(MAKE) $*.rerun; \ else \ $(MAKE) $*.aux; \ fi # While references et al. are changed: recompile. @while ( $(GREPY) "^LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.$$" $*.log ); do \ $(LATEX) $*; \ done @if [ -f $*.ind ]; then \ touch $*.ind; \ fi @if [ -f $*.glx ]; then \ touch $*.glx; \ fi # print out the remaining warnings @$(GREP) "^LaTeX Warning: There were undefined references\." $*.log || true @$(GREP) "^LaTeX Warning: Citation \`.*' on page .* undefined.*" $*.log || true %.rerun: @rm .rerun @$(LATEX) $* # This is the default target: latex: # Below the 'true' is included to prevent unnecessarily many errors. @if [ -n "${LATEXTARGET}" ]; then \ $(MAKE) ${LATEXTARGET}.dvi; \ true; \ else \ if [ `ls *.tex | wc -l` = "1" ]; then \ $(MAKE) `basename \`ls *.tex\` .tex`.dvi; \ true; \ else \ $(MAKE) `echo $$PWD|tr '/' '\n'|tail -1`.dvi; \ true; \ fi; \ fi view: # Below the 'true' is included to prevent unnecessarily many errors. @if [ -n "${LATEXTARGET}" ]; then \ $(MAKE) ${LATEXTARGET}.viewdvi ; \ true; \ else \ if [ `ls *.tex | wc -l` = "1" ]; then \ $(MAKE) `basename \`ls *.tex\` .tex`.viewdvi; \ true; \ else \ $(MAKE) `echo $$PWD|tr '/' '\n'|tail -1`.viewdvi; \ true; \ fi; \ fi %.ps: %.dvi $(DVIPS) -t $(PAPERSIZE) -o $@ $< %.pdf: %.ps $(PSTOPDF) -sPAPERSIZE=$(PAPERSIZE) $< $@ %.viewdvi: %.dvi $(DVIVIEWER) $*.dvi %.viewps: %.ps $(PSVIEWER) $*.ps %.viewpdf: %.pdf $(PDFVIEWER) $*.ps # Not using any intelligent guesses about the LATEXTARGET, here: ps: $(MAKE) $(LATEXTARGET).ps pdf: $(MAKE) $(LATEXTARGET).pdf viewps: $(MAKE) $(LATEXTARGET).viewps viewpdf: $(MAKE) $(LATEXTARGET).viewpdf latexps: @if [ -n "${LATEXTARGET}" ]; then \ $(MAKE) ${LATEXTARGET}.ps && \ true; \ else \ if [ `ls *.tex | wc -l` = "1" ]; then \ $(MAKE) `basename \`ls *.tex\` .tex`.ps && \ true; \ else \ $(MAKE) `echo $$PWD|tr '/' '\n'|tail -1`.ps && \ true; \ fi; \ fi html: .html .html: @if [ -n "${LATEXTARGET}" ]; then \ if [ -n "${HTMLDIR}" ]; then \ $(MAKE) ${LATEXTARGET}.dvi; \ $(LATEX2HTML) $(LATEX2HTML_OPTS) -dir $(HTMLDIR)/$(LATEXTARGET) $(LATEXTARGET) && \ chmod a+rx $(HTMLDIR)/$(LATEXTARGET) && \ chmod a+r $(HTMLDIR)/$(LATEXTARGET)/* && \ touch .html; \ else \ echo Set variable HTMLDIR\!; \ fi; \ else \ echo Set variable LATEXTARGET\!; \ fi latexhelp: @echo "LaTeX Makefile Options" @echo "----------------------" @echo "" @echo "Environment variables:" @echo " LATEXTARGET Filename to make (without extension)" @echo " HTMLDIR Directory for HTML-output" @echo "" @echo "Targets:" @echo " all Make the LATEXTARGET or .dvi" @echo " .dvi Make the given dvi file" @echo " latex Make the LATEXTARGET or .dvi" @echo " view Make and view the LATEXTARGET or .dvi" @echo " html Make the LATEXTARGET or .dvi and generate HTML output" @echo " latexhelp This overview" @echo " latexclean Remove all generated files" clean latexclean:: @rm -f *.log *.aux *.blg *.ilg *.toc *.lof *.lot *.idx *.ind *.glo *.glx .html .btmp .itmp .gtmp .rerun reallyclean: @rm -f *.bbl @epsfiles=`find * -maxdepth 0 -name "*.eps"`; \ if [ -n "$$epsfiles" ]; then \ for i in *.eps; do \ if [ -f `basename $$i .eps`.fig ]; then \ rm -f $$i; \ elif ( rcs `basename $$i .eps`.fig >& /dev/null ); then \ rm -f $$i; \ fi \ done \ fi