Makerules 6.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
## -*- mode: Makefile -*-
##
## This is a sufficient `Makefile', but not a great one.
##
## "Normal" PDF is generated via `pdflatex'.  This is the route you take if you
## make `<doc>.pdf'.
##

###############################################################################

## These variables can be set by Makefiles that include this file. At a
## minimum, DOCUMENTS or SUBDIRS should be set, all of the others are optional

# The root documents, minus their `.tex' file name extensions.  Each of these
# is a (phony) Make target.
#
#DOCUMENTS	:= prop

# Sub-directories that should be recursed into 
#SUBDIRS        := adm

# "Extra" figures, not made from `.fig' or `.svg' files.  These must have file
# name extensions because we don't want to infer them.
#
#EXTRAFIGEPS	:=
#
#EXTRAFIGPDF	:=
#
#EXTRAFIGWWW	:=

# The first root file listed in `DOCUMENTS' is the default target. Override
# the DOC variable if you want to to be something else
DOC		?= $(firstword $(DOCUMENTS))

###############################################################################

TEXINPUTS	?= .:./figs:./texstuff::
BUILDDIR	?= ./.build

#
# Needed to use bibtex properly in the builddir
#
CURDIR		= $(shell pwd)
BIBINPUTS	?= $(CURDIR):$(CURDIR)/bib::

export TEXINPUTS
export BIBINPUTS

LATEX		?= latex
Robert Ricci's avatar
Robert Ricci committed
50
PDFLATEX	?= xelatex
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
BIBTEX		?= bibtex

PS2PDF		?= ps2pdf14
FIG2DEV		?= fig2dev
INKSCAPE 	?= inkscape
EPSTOPDF	?= epstopdf

PDFLATEXFLAGS	?= --interaction=nonstopmode --halt-on-error \
                   --file-line-error --output-directory=$(BUILDDIR)

# See below for some long-winded comments about these options.
#
PS2PDFFLAGS	?= -sPAPERSIZE=letter -dPDFSETTINGS=/printer \
		   -dUseCIEColor \
		   -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100
PS2PDFFLAGS_EPS	?= -dEPSCrop -dPDFSETTINGS=/printer \
		   -dUseCIEColor \
		   -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100

TEX4HT		?= tex4ht
T4HT		?= t4ht

# TEXBITS	should exclude the root files, but it does not.
74
TEXBITS		?= $(wildcard *.tex)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
BIBBITS		?= $(wildcard *.bib) $(wildcard bib/*.bib)

FIGBITS		?= $(wildcard figs/*.fig)
SVGBITS 	?= $(wildcard figs/*.svg)
# If you want to avoid requiring inkscape, comment out the line above and 
# uncomment this one
#SVGBITS 	?=
FIGEPS		?= $(FIGBITS:.fig=.eps) $(SVGBITS:.svg=.eps) $(EXTRAFIGEPS)
FIGPDF		?= $(FIGBITS:.fig=.pdf) $(SVGBITS:.svg=.pdf) $(EXTRAFIGPDF)
FIGWWW		?= $(FIGBITS:.fig=.png) $(SVGBITS:.svg=.png) $(EXTRAFIGWWW)

DEPS		?= $(wildcard *.cls) $(wildcard *.sty) $(wildcard *.cfg) \
		   $(TEXBITS) $(BIBBITS) \
		   $(MAKEFILE_LIST)

###############################################################################

# Some commends about `PS2PDFFLAGS'.
#
# -Pdownload35 --- Embed the standard PostScript fonts.  The USENIX author
# instructions (and many other conference instructions) ask that *all* fonts be
# embedded in PDF documents.  Note that you *must* use this option in order for
# `ps2pdf14' to produce working PDF.  Note that the the name of the embedded
# `Times' font is called `Nimbus'.  (See the `ps2pk.map' file.)
#
# -u ps2pk.map --- I think this is not required, but it doesn't hurt.  I think
# `dvips' consults it anyway.  I could be wrong; maybe it is required in some
# cases.
#
# -d... --- For the `ps2pdf' options the deal with font embedding, I believe
# that all of these are the standard values for modern versions of Ghostscript
# (7.05+).
#
# Note that you can use the `pdffonts' tool to check that all the fonts are
# embedded.
#
# Some random but handy URLs for these things:
#   <http://www.crhc.uiuc.edu/~mjmille2/howtos/latex-howtos/>
#   <http://www.cs.wisc.edu/~ghost/doc/gnu/7.05/Ps2pdf.htm>

###############################################################################

.DELETE_ON_ERROR:

.PHONY: all clean realclean
all::
clean::
realclean::

###############################################################################

all:: $(DOC)

define def-doc-rule
  .PHONY: $1
  $1: $1.pdf
endef
$(foreach d,$(DOCUMENTS),$(eval $(call def-doc-rule,$d)))

.PHONY: pdf
pdf: $(DOC).pdf

####

$(addsuffix .pdf,$(DOCUMENTS)): $(DEPS) $(FIGPDF)

# Why be subtle?
# Use a special job name to keep our output docs separate from those along the
# "normal" route to PDF.
%.pdf: %.tex | $(BUILDDIR)
	$(PDFLATEX) -draftmode $(PDFLATEXFLAGS) $(basename $<)
146
#	- cd $(BUILDDIR) && $(BIBTEX) $(basename $@)
147 148
#	$(PDFLATEX) -draftmode $(PDFLATEXFLAGS) $(basename $<)
#	$(PDFLATEX) $(PDFLATEXFLAGS) $(basename $<)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
	mv $(BUILDDIR)/$@ $@
	
%.bbl: %.aux
	$(BIBTEX) $(basename $@)

$(BUILDDIR):
	mkdir -p $(BUILDDIR)

####

%.eps: %.svg
	$(INKSCAPE) \
	$< \
	--export-eps=$@

%.eps: %.jpg
	$(INKSCAPE) \
	$< \
	--export-eps=$@ \
	--export-text-to-path

%.eps: %.fig
	$(FIG2DEV) -L eps $< $@

%.pdf: %.fig
	$(FIG2DEV) -L pdf $< $@

# "-m 1.5 -S 4": magnify and smooth
%.png: %.fig
	$(FIG2DEV) -L png -m 1.5 -S 4 $< $@

# This method produces small PDFs that have tight bounding boxes.
$(SVGBITS:.svg=.pdf): %.pdf: %.eps
	$(PS2PDF) $(PS2PDFFLAGS_EPS) $< $@

###############################################################################

## Simple rules for making sub-directories

# To cause make to get run for target bar in subdirectory foo, create a
# dependency on foo/bar.MAKE
%.MAKE: 
	@$(MAKE) -w -C $(dir $@) $(basename $(notdir $@))

# In conjection with the rule above, you can depend on bar-subdirs to
# build target bar in all subdirectories
%-subdirs: $(addsuffix /%.MAKE,$(SUBDIRS)) ;

# ... and do this for some common rules
all:: all-subdirs
clean:: clean-subdirs
realclean:: realclean-subdirs

###############################################################################

## Some generally useful magic bits

# Given a list of directory/target, make dependency strings for the .MAKE rule
# above, suitable for going and building those targets
define recursivedeps
    $(foreach bit,$(1), $(dir $(bit))/$(basename $(notdir $(bit))).MAKE)
endef

###############################################################################

clean::
	$(RM) -r $(BUILDDIR)
	$(RM) *.backup *~

realclean:: clean
	$(RM) $(foreach doc, $(DOCUMENTS), $(doc).{pdf,ps,eps})
	$(RM) $(FIGBITS:.fig=.eps) $(SVGBITS:.svg=.eps)
	$(RM) $(FIGBITS:.fig=.pdf) $(SVGBITS:.svg=.pdf)
	$(RM) $(FIGBITS:.fig=.png) $(SVGBITS:.svg=.png)

###############################################################################

## End of file.