publish: wk4.pdf Makefile graphs/* media/* scans/* rsync -r wk4.{pdf,tex,tex.in,sed} Makefile graphs media scans mac:html/teaching/1za3/wk4/ # Makefile for LaTeX files # Original Makefile from http://www.math.psu.edu/elkin/math/497a/Makefile # Copyright (c) 2005 Matti Airas # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # $Id: Makefile,v 1.7 2005/02/17 20:16:59 martin Exp martin $ LATEX = latex PDFLATEX= pdflatex BIBTEX = bibtex MAKEINDEX = makeindex XDVI = xdvi -gamma 4 ifdef PAGES DVIPS = dvips -pp $(PAGES) DVIPDF = dvipdft -s $(PAGES) else DVIPS = dvips DVIPDF = dvipdft endif L2H = latex2html #GH = gv GH = run-mailcap IGNORETEX = ^_.* DATE = date RERUN = "(There were undefined references|Rerun to get (cross-references|the bars) right)" RERUNBIB = "No file.*\.bbl|Citation.*undefined" USEBIB = '^[^%]*\\bibliography' MAKEIDX = '^[^%]*\\makeindex' MPRINT = '^[^%]*print' USETHUMBS = '^[^%]*thumbpdf' SRC := $(shell egrep -l '^[^%]*\\begin\{document\}' *.tex | egrep -v $(IGNORETEX)) SEDSRC := $(shell egrep -l '^[^%]*\\begin\{document\}' *.tex.in | egrep -v $(IGNORETEX)) SEDSRC := $(SEDSRC:%.tex.in=%.tex) SRC += $(SEDSRC) SRC := $(sort $(SRC)) #EPSPICS := $(shell perl -ne '@foo=/^[^%]*\\(includegraphics|psfig)(\[.*?\])?\{(.*?)\}/g;if (defined($$foo[2])) { if ($$foo[2] =~ /.eps$$/) { print "$$foo[2] "; } else { print "$$foo[2].eps "; }}' *.tex) TAG := $(shell darcs changes --tags='.*' 2>/dev/null | sed -n 's/^ *tagged \(.*\)$$/\1/p' | head -n1) DEP := $(shell egrep -L '^[^%]*\\begin\{document\}' *.tex | egrep -v $(IGNORETEX)) SEDDEP := $(shell egrep -L '^[^%]*\\begin\{document\}' *.tex.in | egrep -v $(IGNORETEX)) SEDDEP := $(SEDDEP:%.tex.in=%.tex) DEP += $(SEDDEP) DEP := $(sort $(DEP)) TRG = $(SRC:%.tex=%.dvi) PSF = $(SRC:%.tex=%.ps) PDF = $(SRC:%.tex=%.pdf) COPY = if test -r $(<:%.tex=%.toc); then cp $(<:%.tex=%.toc) $(<:%.tex=%.toc.bak); fi RM = rm -f OUTDATED = echo "EPS-file is out-of-date!" && false all : $(TRG) define run-latex $(COPY);$(LATEX) $< egrep -q $(MAKEIDX) $< && ($(MAKEINDEX) $(<:%.tex=%);$(COPY);$(LATEX) $<) ; true egrep -q $(USEBIB) $< && egrep -c $(RERUNBIB) $(<:%.tex=%.log) && ($(BIBTEX) $(<:%.tex=%);$(COPY);$(LATEX) $<) ; true egrep -q $(RERUN) $(<:%.tex=%.log) && ($(COPY);$(LATEX) $<) ; true egrep -q $(RERUN) $(<:%.tex=%.log) && ($(COPY);$(LATEX) $<) ; true if cmp -s $(<:%.tex=%.toc) $(<:%.tex=%.toc.bak); then true ;else $(LATEX) $< ; fi $(RM) $(<:%.tex=%.toc.bak) # Display relevant warnings egrep -i "(Reference|Citation).*undefined" $(<:%.tex=%.log) ; true endef %.tex : %.sed %.tex.in sed -f $^ > $@ # Parse the input .tex to extract dependencies BIBFILES = $(shell perl -ne '($$_)=/^[^%]*\\bibliography\{(.*?)\}/;@_=split /,/;foreach $$b (@_) {print "$$b.bib "}' $(SRC)) BIBPATHS = $(shell pwd) $(shell echo "$(BIBINPUTS)" | sed 's/:/ /g') .bibdeps: $(SRC) for bib in $(BIBFILES); do for path in $(BIBPATHS); do if [ -e "$$path/$$bib" ]; then echo "$$path/$$bib"; break; fi; done; done > .bibdeps # Handling recursive includes properly would be too difficult, so we just # depend on anything included in the current dir and *everything* in any local # include directories set by TEXINPUTS INCFILES = $(shell sed -n 's/^\\\(input\|include\){\([^}]*\)}/\2.tex/p' < $(SRC)| sed 's/\.tex\.tex/.tex/') INCFILES += $(shell sed -n 's/^\\usepackage{\([^}]*\)}/\1.sty/p' < $(SRC)) INCPATHS = $(shell echo "$(TEXINPUTS)" | sed 's/:/ /g') .incdeps: $(SRC) for inc in $(INCFILES); do if [ -e "./$$inc" ]; then echo "`pwd`/$$inc"; fi; done > .incdeps for incpath in $(INCPATHS); do if ! [ "$$incpath" = "." ]; then ls -1 "$$incpath"/*.{tex,sty} >> .incdeps 2>/dev/null; fi; done .deps: .bibdeps .incdeps cat .bibdeps .incdeps > .deps deps: .deps arXivdeps: .incdeps cat .incdeps > .arXivdeps # XXX: This clearly isn't the right way to do the DEPS thing... but I'm not sure # what is. 'make deps' must be called explicitly. DEPS = $(shell cat .deps 2>/dev/null) $(TRG) : %.dvi : %.tex $(DEP) $(EPSPICS) $(DEPS) $(DATE) >| build-date.tex if [ -n '$(TAG)' ]; then echo '\\version $(TAG)'; else echo ''; fi >| version.tex @$(run-latex) || rm %.dvi $(PSF) : %.ps : %.dvi @$(DVIPS) $< -o $@ #$(PDF) : %.pdf : %.dvi # @$(DVIPDF) -o $@ $< $(PDF) : LATEX=$(PDFLATEX) $(PDF) : %.pdf : %.tex $(DEP) $(EPSPICS) $(DEPS) $(DATE) >| build-date.tex if [ -n '$(TAG)' ]; then echo '\\version $(TAG)'; else echo ''; fi >| version.tex @$(run-latex) show : $(TRG) @for i in $(TRG) ; do $(XDVI) $$i ; done showps : $(PSF) @for i in $(PSF) ; do $(GH) $$i ; done showpdf : $(PDF) @for i in $(PDF) ; do $(GH) $$i ; done test : showpdf test-p% : echo $* ps : $(PSF) pdf : $(PDF) # TODO: This probably needs fixing html : @$(DEP) $(EPSPICS) @$(L2H) $(SRC) clean : -rm -f $(TRG) $(PSF) $(PDF) $(TRG:%.dvi=%.aux) $(TRG:%.dvi=%.bbl) $(TRG:%.dvi=%.blg) $(TRG:%.dvi=%.log) $(TRG:%.dvi=%.out) NAME := $(shell pwd | sed 's/.*\///') VERSION := "$(shell if [ -n '$(TAG)' ]; then echo '$(TAG)'; else date +%y%m%d; fi)" FULLNAME := "$(NAME)-$(VERSION)" dist : $(TRG) $(PSF) $(PDF) [ -r .deps ] || (echo "run make .deps first, and prune .deps appropriately" && false) (\ rm -rf dist-tmp ;\ mkdir dist-tmp ;\ cd dist-tmp ;\ mkdir "$(FULLNAME)" ;\ cd "$(FULLNAME)" ;\ cp ../../$(SRC) ../../Makefile ../../version.tex . ;\ for dep in `cat ../../.deps`; do cp $$dep .; done ;\ cd .. ;\ tar -zcvf "$(FULLNAME).tgz" "$(FULLNAME)" ;\ mv "$(FULLNAME).tgz" .. ;\ cd .. ;\ rm -rf dist-tmp ;\ [ -d dist ] && cp -p "$(FULLNAME).tgz" $(TRG) $(PSF) $(PDF) dist/;\ true;\ ) arXivsrc : $(TRG) $(PSF) $(PDF) [ -r .arXivdeps ] || (echo "run make .arXivdeps first, and prune .arXivdeps appropriately" && false) (\ rm -rf arXiv-tmp ;\ mkdir arXiv-tmp ;\ cd arXiv-tmp ;\ mkdir "$(FULLNAME)" ;\ cd "$(FULLNAME)" ;\ cp ../../$(SRC) . ;\ cp ../../$(TRG:%.dvi=%.bbl) . ;\ for dep in `cat ../../.arXivdeps`; do cp $$dep .; done ;\ tar -zcvf "$(FULLNAME)"-arXiv_src.tgz * ;\ mv "$(FULLNAME)"-arXiv_src.tgz ../.. ;\ cd ../.. ;\ rm -rf arXiv-tmp ;\ true;\ ) arXivsrc1 : $(TRG) $(PSF) $(PDF) [ -r .arXivdeps ] || (echo "run make .arXivdeps first, and prune .arXivdeps appropriately" && false) (\ rm -rf arXiv-tmp ;\ mkdir arXiv-tmp ;\ cd arXiv-tmp ;\ mkdir "$(FULLNAME)" ;\ cd "$(FULLNAME)" ;\ cp ../../$(SRC) . ;\ cp ../../$(TRG:%.dvi=%.bbl) . ;\ for dep in `cat ../../.arXivdeps`; do cp $$dep .; done ;\ ) arXivsrc2 : $(TRG) $(PSF) $(PDF) (\ cd arXiv-tmp/$(FULLNAME) ;\ tar -zcvf "$(FULLNAME)"-arXiv_src.tgz * ;\ mv "$(FULLNAME)"-arXiv_src.tgz ../.. ;\ cd ../.. ;\ rm -rf arXiv-tmp ;\ true;\ ) .PHONY : all show clean ps pdf showps dist ###################################################################### # Define rules for EPS source files. %.eps: %.sxd $(OUTDATED) %.eps: %.sda $(OUTDATED) %.eps: %.png $(OUTDATED) %.eps: %.sxc $(OUTDATED) %.eps: %.xcf $(OUTDATED) %.eps: %.zargo $(OUTDATED) %.eps: %.m @egrep -q $(MPRINT) $< && ($(OUTDATED))