felix@3266: # Copyright 2004 Chris Monson (shiblon@gmail.com)
felix@3266: # Latest version available at http://www.bouncingchairs.net/oss
felix@3266: #
felix@3266: #    This file is part of ``Chris Monson's Free Software''.
felix@3266: #
felix@3266: #    ``Chris Monson's Free Software'' is free software; you can redistribute it
felix@3266: #    and/or modify it under the terms of the GNU General Public License as
felix@3266: #    published by the Free Software Foundation, Version 2.
felix@3266: #
felix@3266: #    ``Chris Monson's Free Software'' is distributed in the hope that it will
felix@3266: #    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
felix@3266: #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
felix@3266: #    Public License for more details.
felix@3266: #
felix@3266: #    You should have received a copy of the GNU General Public License along
felix@3266: #    with ``Chris Monson's Free Software''; if not, write to the Free Software
felix@3266: #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
felix@3266: #
felix@3266: #    It is also available on the web at http://www.gnu.org/copyleft/gpl.html
felix@3266: #
felix@3266: #    Note that using this makefile to build your documents does NOT place them
felix@3266: #    under the GPL unless you, the author, specifically do so.  In other words,
felix@3266: #    I, Chris Monson, the copyright holder and author of this makefile,
felix@3266: #    consider it impossible to ``link'' to this makefile in any way covered by
felix@3266: #    the GPL.
felix@3266: #
felix@3266: # TO OBTAIN INSTRUCTIONS FOR USING THIS FILE, RUN:
felix@3266: #    make help
felix@3266: #
felix@3266: fileinfo	:= LaTeX Makefile
felix@3266: author		:= Chris Monson
felix@3266: version		:= 2.2.0-rc1
felix@3266: #
felix@3266: # Note that the user-global version is imported *after* the source directory,
felix@3266: # so that you can use stuff like ?= to get proper override behavior.
felix@3266: .PHONY: Makefile GNUmakefile Makefile.ini $(HOME)/.latex-makefile/Makefile.ini
felix@3266: -include Makefile.ini
felix@3266: -include $(HOME)/.latex-makefile/Makefile.ini
felix@3266: #
felix@3266: # This can be pdflatex or latex - you can change this by adding the following line to your Makefile.ini:
felix@3266: # BUILD_STRATEGY := latex
felix@3266: BUILD_STRATEGY		?= pdflatex
felix@3266: #
felix@3266: # Sets LC_ALL=C, by default, so that the locale-aware tools, like sort, be
felix@3266: # # immune to changes to the locale in the user environment.
felix@3266: export LC_ALL		?= C
felix@3266: #
felix@3266: #
felix@3266: # If you specify sources here, all other files with the same suffix
felix@3266: # will be treated as if they were _include_ files.
felix@3266: #onlysources.tex	?= main.tex
felix@3266: #onlysources.tex.sh	?=
felix@3266: #onlysources.tex.pl	?=
felix@3266: #onlysources.tex.py	?=
felix@3266: #onlysources.rst	?=
felix@3266: #onlysources.fig	?=
felix@3266: #onlysources.gpi	?=
felix@3266: #onlysources.dot	?=
felix@3266: #onlysources.xvg	?=
felix@3266: #onlysources.svg	?=
felix@3266: #onlysources.eps.gz	?=
felix@3266: #onlysources.eps	?=
felix@3266: #
felix@3266: # If you list files here, they will be treated as _include_ files
felix@3266: #includes.tex		?= file1.tex file2.tex
felix@3266: #includes.tex.sh	?=
felix@3266: #includes.tex.pl	?=
felix@3266: #includes.tex.py	?=
felix@3266: #includes.rst		?=
felix@3266: #includes.fig		?=
felix@3266: #includes.gpi		?=
felix@3266: #includes.dot		?=
felix@3266: #includes.xvg		?=
felix@3266: #includes.svg		?=
felix@3266: #includes.eps.gz	?=
felix@3266: #includes.eps		?=
felix@3266: #
felix@3266: # If you list files or wildcards here, they will *not* be cleaned - default is
felix@3266: # to allow everything to be cleaned.
felix@3266: #neverclean		?= *.pdf
felix@3266: #
felix@3266: # Alternatively (recommended), you can add those lines to a Makefile.ini file
felix@3266: # and it will get picked up automatically without your having to edit this
felix@3266: # Makefile.
felix@3266: #
felix@3266: # KNOWN ISSUES:
felix@3266: #	* The following occurs:
felix@3266: #		file with: \usepackage{named}\bibliographystyle{named}
felix@3266: #		Compile
felix@3266: #		change to: \usepackage{apalike}\bibliographystyle{apalike}
felix@3266: #		Compile again -- BARF!
felix@3266: #
felix@3266: #		The workaround: make clean-nographics; make
felix@3266: #
felix@3266: #		Note that we may not be able to fix this.  LaTeX itself barfs
felix@3266: #		on this, not the makefile.  The very first invocation of LaTeX
felix@3266: #		(when something like this has happened) reads the existing .aux
felix@3266: #		file and discovers invalid commands like \citeauthoryear that
felix@3266: #		are only valid in the package that was just removed.  It then
felix@3266: #		tries to parse them and explodes.  It's not at all clear to me
felix@3266: #		how to fix this.  I tried removing the .aux files on the first
felix@3266: #		run of LaTeX, but that necessarily requires more subsequent
felix@3266: #		rebuilds on common edits.  There does not appear to be a
felix@3266: #		graceful solution to this issue.
felix@3266: #
felix@3266: # CHANGES:
felix@3266: # Chris Monson (2010-04-08):
felix@3266: # 	* Bumped version to 2.2.0-rc1
felix@3266: # 	* Added back in the rst_style_file stuff that got broken when switching
felix@3266: # 		rst -> tex to use the script mechanism
felix@3266: # Chris Monson (2010-03-23):
felix@3266: #	* Bumped version to 2.2.0-beta8
felix@3266: #	* Work on issue 76: bad backtick escape for some sed versions, failure
felix@3266: #		to clear out the hold buffer when outputting MISSING comment.
felix@3266: #		- Backed out 2>&1 to &> (doesn't work in sh)
felix@3266: #		- Backed out using . to source variables
felix@3266: # Chris Monson (2010-03-22):
felix@3266: # 	* Bumped version to 2.2.0-beta7
felix@3266: # 	* Issue 72: Fix latex/bibtex invocation order for annotated bib styles
felix@3266: # 	* Fixed informational output to reflect which LaTeX run we're on
felix@3266: # 	* Fixed graphic detection to include graphics that are already there in
felix@3266: # 		.d files
felix@3266: # 	* Tightened up the .d file output to only make .d depend on graphic
felix@3266: # 		*source* files.  This means that building foo.d no longer
felix@3266: # 		builds all of the graphics files on which foo.tex depends.
felix@3266: # 		Had to use .SECONDEXPANSION trickery to make it work.
felix@3266: # 	* Changed get-graphics to only accept a stem.
felix@3266: # 	* Fixed build-once logic for scripted .tex to work better
felix@3266: # 	* Made get-inputs sed script more maintainable.
felix@3266: # 	* Moved Makefile.ini import up higher.
felix@3266: # 	* Changed bare stems to not recursively invoke make
felix@3266: # 	* Updated diff output to be more silent everywhere
felix@3266: # 	* Added a MISSING comment to the .d file if stuff isn't found - forces
felix@3266: # 		removal of .1st.make file, which often forces it to try again.
felix@3266: # 	* Fixed broken graphics-target function
felix@3266: # 	* Added sleep to .d file generation when stuff is missing - if it
felix@3266: # 		builds too fast, make doesn't realize it needs to be reloaded,
felix@3266: # 		and thus never discovers some deeper dependencies (especially
felix@3266: # 		evident when graphics are included from scripted include
felix@3266: # 		files).
felix@3266: # Chris Monson (2010-03-17):
felix@3266: # 	* Bumped version to 2.2.0-beta6
felix@3266: # 	* Fixed bareword builds to actually work (requires static patterns)
felix@3266: # 	* Fixed colorization to work with new paragraph stuff
felix@3266: # Chris Monson (2010-03-17):
felix@3266: # 	* Bumped version to 2.2.0-beta5
felix@3266: # 	* Fixed graphic detection to be much more focused - splits log file
felix@3266: # 		into paragraphs before doing pattern matching.
felix@3266: # 	* Fixed make foo to work properly (recursively calls make foo.pdf)
felix@3266: # 	* Fixed gpi -> pdf generation to not waste time building .eps *after*
felix@3266: # 		the pdf already exists.
felix@3266: # 	* Changed log copies to include MAKE_RESTARTS as part of the name.
felix@3266: # 	* Fixed missing include file detection (also makes use of the paragraph
felix@3266: # 		stuff) to detect missing scripted include files.
felix@3266: # Chris Monson (2010-03-16):
felix@3266: # 	* Bumped version to 2.2.0-beta4
felix@3266: # 	* issue 70: .pdf not moved out of the way properly on first
felix@3266: # 		compilation, resulting in early error detection failure.
felix@3266: # 	* issue 74: fixed broken error on missing .aux files: the
felix@3266: # 		implementation was masking real errors.
felix@3266: # Chris Monson (2010-03-15):
felix@3266: # 	* Bumped version to 2.2.0-beta3
felix@3266: # 	* issue 71: Made the tput dependency optional
felix@3266: # 	* issue 73: Made .tex targets not pull in .d files (building them from
felix@3266: # 		scripts should not require a .d)
felix@3266: # 	* issue 74: Output a much saner error when a .aux file is not produced
felix@3266: # 		(e.g., when you are typing "make" without arguments in a
felix@3266: # 		directory with included .tex files that are not named with
felix@3266: # 		._include_.)
felix@3266: # Chris Monson (2010-03-11):
felix@3266: # 	* Bumped version to 2.2.0-beta2
felix@3266: # 	* Fixed clean-graphics to get rid of intermediate .eps files that may
felix@3266: # 		be hanging around
felix@3266: # 	* Added an automatic setting to use eps terminals in pdflatex mode for
felix@3266: # 		gnuplot if it doesn't understand pdf.
felix@3266: # 	* issue 66: Removed grayscale generation via magic suffix.  Grayscale
felix@3266: # 		generation is now only available via GRAY=1
felix@3266: # 	* issue 68: Added explicit handling of LC_ALL for locale-aware tools
felix@3266: # 		like "sort"
felix@3266: # Chris Monson (2010-03-10):
felix@3266: # 	* Bumped version to 2.2.0-beta1
felix@3266: # 	* Fixed success message to handle output message in different places
felix@3266: # 	* Added name of produced file to success message
felix@3266: # Chris Monson (2010-03-10):
felix@3266: # 	* Bumped version to 2.2.0-alpha3
felix@3266: # 	* Added meaningful error message for wrong hyperref options
felix@3266: # 	* Added meaningful error message for incorrect graphics extensions
felix@3266: # Chris Monson (2010-03-09):
felix@3266: # 	* Bumped version to 2.2.0-alpha2
felix@3266: # 	* Updated graphics handling (gnuplot and fig generate pdf natively)
felix@3266: # 	* Changed xmgrace to output monochrome natively
felix@3266: # Chris Monson (2010-03-09):
felix@3266: # 	* Bumped version to 2.2.0-alpha1 - major change!
felix@3266: # 	* Support pdflatex natively and by default (issue 6 - a long time coming)
felix@3266: # 	* Add ability to have a single $HOME/.latex-makefile/Makefile.ini for
felix@3266: # 		all invocations
felix@3266: # 	* Reworked graphic inclusion detection so that extensions need not be
felix@3266: # 		specified for either build strategy (e.g.,
felix@3266: # 		\includegraphics{test1.eps} -> \includegrahpics{test1})
felix@3266: # 	* Changed log format to include filenames and line numbers
felix@3266: # Chris Monson (2010-02-04):
felix@3266: # 	* Bumped version to 2.1.43
felix@3266: # 	* All of the following are for issue 63 (thanks to mojoh81):
felix@3266: # 	* Added documentation about fixing Makefile.ini default target
felix@3266: # 	* Added perl and python script targets
felix@3266: # 	* Fixed run logic to allow included .tex files to be scripted (the
felix@3266: # 		run-again logic now detects missing .tex files, and the MV
felix@3266: # 		command has been switched out for a command that only invokes
felix@3266: # 		MV if the files exist)
felix@3266: # 	* Changed scripted generation to only run once per make invocation
felix@3266: # 	* Added dependency on expr
felix@3266: # Chris Monson (2010-01-19):
felix@3266: # 	* Bumped version to 2.1.42
felix@3266: # 	* issue 62: Added .brf extension to cleanable files (backrefs)
felix@3266: # Chris Monson (2010-01-07):
felix@3266: # 	* Bumped version to 2.1.41
felix@3266: # 	* issue 60: bad makeindex runs now error out on subsequent tries
felix@3266: # Chris Monson (2009-12-01):
felix@3266: # 	* Bumped version to 2.1.40
felix@3266: # 	* issue 36: build all indices (for e.g., splitidx usage)
felix@3266: # 	* issue 59: clean up all generated files (including indices)
felix@3266: # Chris Monson (2009-11-23):
felix@3266: # 	* Bumped version to 2.1.39
felix@3266: # 	* issue 57: change ps2pdf invocations to just use gs directly
felix@3266: # Chris Monson (2009-11-19):
felix@3266: # 	* Bumped version to 2.1.38
felix@3266: # 	* issue 57: Added some limited support for Cygwin (spaces in filenames)
felix@3266: # Chris Monson (2009-11-15):
felix@3266: # 	* Bumped version to 2.1.37
felix@3266: # 	* Removed svninfo, since this is now managed by mercurial
felix@3266: # 	* Fixed typo in changelist
felix@3266: # 	* Issue 52: added jpg->eps conversion (thanks to brubakee)
felix@3266: # 	* Issue 54: fix missing Overfull colorization due to lack of a blank
felix@3266: # 		line preceding the first error.
felix@3266: #	* Issue 51: remove head.tmp and body.tmp in make clean invocation
felix@3266: #	* Issue 56: maintain multiple versions of log files (for debugging)
felix@3266: # Chris Monson (2009-11-14):
felix@3266: # 	* Bumped version to 2.1.36
felix@3266: # 	* Issues 53 and 49: added .brf, .mtc, and .maf to the cleanables
felix@3266: # Chris Monson (2009-11-05):
felix@3266: # 	* Bumped version to 2.1.35
felix@3266: # 	* Added nomenclature support (see issue 48)
felix@3266: # Chris Monson (2009-10-29):
felix@3266: # 	* Bumped version to 2.1.34
felix@3266: # 	* Fixed _out_ creation bug introduced in 2.1.33 (it was always created)
felix@3266: # 	* Fixed erroneous help output for $HOME in BINARY_TARGET_DIR
felix@3266: # 	* Changed contact email address - bring on the spam!
felix@3266: # Chris Monson (2009-10-21):
felix@3266: # 	* Bumped version to 2.1.33
felix@3266: # 	* Fixed issue 46, adding support for dot2tex (thanks to fdemesmay)
felix@3266: # 	* Made all_files.* settable in Makefile.ini (using ?= instead of :=)
felix@3266: # 	* Fixed issue 47, thanks to fdemesmay: add binary copy directory, copy
felix@3266: # 		dvi, pdf, and ps if it exists
felix@3266: # Chris Monson (2009-09-25):
felix@3266: # 	* Bumped version to 2.1.32
felix@3266: # 	* Fixed so that a changed lol file will cause a rebuild
felix@3266: # 	* Added .lol files to the cleanable list
felix@3266: # Chris Monson (2009-09-08):
felix@3266: # 	* Bumped version to 2.1.31
felix@3266: # 	* Closed issue 43: evince doesn't notice pdf change w/out touch
felix@3266: # Chris Monson (2009-08-28):
felix@3266: # 	* Bumped version to 2.1.30
felix@3266: # 	* Closed issue 39: Capture multi-line log warnings/errors to output
felix@3266: # Chris Monson (2009-08-26):
felix@3266: # 	* Bumped version to 2.1.29
felix@3266: # 	* Closed issue 42: add svg support using inkscape
felix@3266: # Chris Monson (2009-08-17):
felix@3266: # 	* Bumped version to 2.1.28
felix@3266: # 	* Patch from paul.biggar for issue 38: package warnings are overlooked
felix@3266: # Chris Monson (2009-08-07):
felix@3266: # 	* Bumped version to 2.1.27
felix@3266: # 	* Included patch for issue 37 - removes pdf/ps files before copying,
felix@3266: # 		allowing some broken viewers to see changes properly.
felix@3266: # Chris Monson (2009-05-15):
felix@3266: # 	* Bumped version to 2.1.26
felix@3266: # 	* Included patch for issue 9 from favonia - detects .fig changes for
felix@3266: # 		pstex files during regular compilation, so long as the pstex
felix@3266: # 		has been built at least once with make all-pstex.
felix@3266: # Chris Monson (2009-03-27):
felix@3266: # 	* Bumped version to 2.1.25
felix@3266: # 	* Cleaned up a bunch of variable setting stuff - more stuff is now
felix@3266: # 		settable from Makefile.ini
felix@3266: # 	* Cleaned up documentation for various features, especially settable
felix@3266: # 		variables.
felix@3266: # 	* issue 28: support for png -> eps conversion (it even looks good!)
felix@3266: # 	* issue 29: support for "neverclean" files in Makefile.ini
felix@3266: # 	* issue 30: make ps2pdf14 the default - fall back when not there
felix@3266: # Chris Monson (2009-03-09):
felix@3266: # 	* Bumped version to 2.1.24
felix@3266: # 	* issue 27: xmgrace support (thanks to rolandschulzhd)
felix@3266: # Chris Monson (2008-10-23):
felix@3266: # 	* Bumped version to 2.1.23
felix@3266: # 	* issue 23: fixed _check_programs to not use bash string subs
felix@3266: # Chris Monson (2008-09-02):
felix@3266: # 	* Bumped version to 2.1.22
felix@3266: # 	* Appled patch from Holger <yllohy@googlemail.com> to add include
felix@3266: # 		sources and some documentation updates.
felix@3266: # 	* Updated backup_patterns to be a bit more aggressive (also thanks to
felix@3266: # 		Holger)
felix@3266: # Chris Monson (2008-08-30):
felix@3266: # 	* Bumped version to 2.1.21
felix@3266: # 	* Added ability to specify onlysources.* variables to indicate the only
felix@3266: # 		files that should *not* be considered includes.  Thanks to Holger
felix@3266: # 		<yllohy@googlemail.com> for this patch.
felix@3266: # 	* Added an automatic include of Makefile.ini if it exists.  Allows
felix@3266: # 		settings to be made outside of this makefile.
felix@3266: # Chris Monson (2008-05-21):
felix@3266: # 	* Bumped version to 2.1.20
felix@3266: # 	* Added manual pstex compilation support (run make all-pstex first)
felix@3266: # 	* Removed all automatic pstex support.  It was totally breaking
felix@3266: # 		everything and is very hard to incorporate into the makefile
felix@3266: # 		concept because it requires LaTeX to *fail* before it can
felix@3266: # 		determine that it needs the files.
felix@3266: # Chris Monson (2008-04-17):
felix@3266: # 	* Bumped version to 2.1.19
felix@3266: # 	* Changed the pstex build hack to be on by default
felix@3266: # Chris Monson (2008-04-09):
felix@3266: # 	* Bumped version to 2.1.18
felix@3266: # 	* issue 16: fixed pstex build problems, seems nondeterministic.  Added
felix@3266: # 		gratuitious hack for testing: set PSTEX_BUILD_ALL_HACK=1.
felix@3266: # Chris Monson (2008-04-09):
felix@3266: # 	* Bumped version to 2.1.17
felix@3266: # 	* issue 20: fixed accumulation of <pid>*.make files - wildcard was
felix@3266: #		refusing to work on files that are very recently created.
felix@3266: # Chris Monson (2008-04-02):
felix@3266: # 	* Bumped version to 2.1.16
felix@3266: # 	* issue 19: Removed the use of "type" to fix broken "echo" settings
felix@3266: # Chris Monson (2008-03-27):
felix@3266: # 	* Bumped version to 2.1.15
felix@3266: # 	* issue 18: Favors binary echo over builtin, as binary understands -n
felix@3266: # 	* issue 16: Fixed handling of missing pstex_t files in the log
felix@3266: # 	* issue 9: Added .SECONDARY target for .pstex files
felix@3266: # Chris Monson (2008-03-21):
felix@3266: # 	* Bumped version to 2.1.14
felix@3266: # 	* Fixed broken aux file flattening, which caused included bibs to be
felix@3266: # 		missed.
felix@3266: # Chris Monson (2008-03-20):
felix@3266: # 	* Bumped version to 2.1.13
felix@3266: # 	* Changed error output colorization to show errors for missing files
felix@3266: # 		that are not graphics files.
felix@3266: # Chris Monson (2008-03-20):
felix@3266: # 	* Bumped version to 2.1.12
felix@3266: # 	* Fixed a regression introduced in r28 that makes bibtex fail when
felix@3266: # 		there is no index file present
felix@3266: # Chris Monson (2008-03-03):
felix@3266: # 	* Bumped version to 2.1.11
felix@3266: # 	* Fixed issue 11 (handle index files, reported by abachn)
felix@3266: # 	* Cleaned up some comments and help text
felix@3266: # Chris Monson (2008-01-24):
felix@3266: # 	* Bumped version to 2.1.10
felix@3266: #	* Fixed to work when 'sh' is a POSIX shell like 'dash'
felix@3266: # Chris Monson (2007-12-12):
felix@3266: # 	* Bumped version to 2.1.9
felix@3266: # 	* Fixed documentation and dependency graph for pstex files
felix@3266: # Chris Monson (2007-12-12):
felix@3266: # 	* Bumped version to 2.1.8
felix@3266: # 	* Added basic pstex_t support for fig files (Issue 9 by favonia)
felix@3266: # 		I still suggest that psfrag be used instead.
felix@3266: # Chris Monson (2007-10-16):
felix@3266: # 	* Bumped version to 2.1.7
felix@3266: # 	* Removed todo item: allow other comment directives for rst conversion
felix@3266: # 	* Added ability to use global rst style file _rststyle_._include_.tex
felix@3266: # 	* Added help text to that effect
felix@3266: # Chris Monson (2007-05-20):
felix@3266: # 	* Bumped version to 2.1.6
felix@3266: # 	* Changed default paper size for rst files
felix@3266: # 	* Added todo item: fix paper size for rst files
felix@3266: # 	* Added todo item: allow other comment directives for rst conversion
felix@3266: # Chris Monson (2007-04-02):
felix@3266: # 	* Bumped version to 2.1.5
felix@3266: # 	* Addressed Issue 7, incorrect .gpi.d generation in subdirectories
felix@3266: # Chris Monson (2007-03-28):
felix@3266: # 	* Bumped version to 2.1.4
felix@3266: # 	* Fixed syntax error in dot output
felix@3266: # Chris Monson (2007-03-01):
felix@3266: # 	* Bumped version to 2.1.3
felix@3266: # 	* Added reST to the included documentation
felix@3266: # 	* Fixed graphics and script generation to be settable in the
felix@3266: # 		environment.
felix@3266: # Chris Monson (2007-02-23):
felix@3266: # 	* Bumped version to 2.1.2
felix@3266: # 	* Added the ability to generate .tex files from .rst files
felix@3266: # Chris Monson (2006-10-17):
felix@3266: # 	* Bumped version to 2.1.1
felix@3266: # 	* Fixed includes from subdirectories (sed-to-sed slash escape problem)
felix@3266: # Chris Monson (2006-10-05):
felix@3266: # 	* Bumped version to 2.1.0 (pretty serious new feature added)
felix@3266: # 	* New feature: bib files can now be anywhere on the BIBINPUTS path
felix@3266: # 	* New programs: kpsewhich (with tetex) and xargs (BSD)
felix@3266: # Chris Monson (2006-09-28):
felix@3266: # 	* Bumped version to 2.0.9
felix@3266: # 	* Added ability to parse more than one bibliography
felix@3266: # Chris Monson (2006-06-01):
felix@3266: # 	* Bumped version to 2.0.8
felix@3266: # 	* Added .vrb to the list of cleaned files
felix@3266: # Chris Monson (2006-04-26):
felix@3266: # 	* Bumped version to 2.0.7
felix@3266: # 	* Fixed so that clean-nographics does not remove .gpi.d files
felix@3266: # 	* Removed jpg -> eps hack (not working properly -- just pre-convert)
felix@3266: # 	* Fixed so that postscript grayscale can be done with BSD sed
felix@3266: # Chris Monson (2006-04-25):
felix@3266: # 	* Bumped version to 2.0.6
felix@3266: # 	* Fixed so that changed toc, lot, lof, or out causes a rebuild
felix@3266: # Chris Monson (2006-04-17):
felix@3266: # 	* Bumped version to 2.0.5
felix@3266: # 	* Added jpg -> eps conversion target
felix@3266: # Chris Monson (2006-04-12):
felix@3266: # 	* Bumped version to 2.0.4
felix@3266: # 	* Fixed BSD sed invocation to not use \| as a branch delimiter
felix@3266: # 	* Added a comment section on what is and is not allowed in BSD sed
felix@3266: # 	* Made paper size handling more robust while I was at it
felix@3266: # 	* Fixed postscript RGB grayscale to use a weighted average
felix@3266: # 	* Fixed postscript HSB grayscale to convert to RGB first
felix@3266: # 	* Fixed a problem with rebuilding .bbl files
felix@3266: # Chris Monson (2006-04-11):
felix@3266: # 	* Bumped version to 2.0.3
felix@3266: # 	* Fixed some BSD sed problems: can't use \n in substitutions
felix@3266: # Chris Monson (2006-04-10):
felix@3266: # 	* Bumped version to 2.0.2
felix@3266: # 	* Once again removed ability to create .tex files from scripts
felix@3266: # 	* \includeonly works again
felix@3266: # Chris Monson (2006-04-09):
felix@3266: # 	* Bumped version to 2.0.1
felix@3266: # 	* Fixed grayscale postscript handling to be more robust
felix@3266: # 	* Added ability to generate ._gray_. files from eps and eps.gz
felix@3266: # 	* Added ability to clean ._gray_.eps files created from .eps files
felix@3266: # Chris Monson (2006-04-07):
felix@3266: # 	* Bumped version to 2.0.0
felix@3266: # 	* Removed clunky ability to create included .tex files from scripts
felix@3266: # 	* Added note in the help about included tex scripting not working
felix@3266: # 	* Fixed the .eps generation to delete %.gpihead.make when finished
felix@3266: # 	* Abandoned designs to use shell variables to create sed scripts
felix@3266: # 	* Abandoned __default__.tex.sh idea: it causes recursion with %: .
felix@3266: # 	* Removed web page to-do.  All items are now complete.
felix@3266: # 	* Added better grayscale conversion for dot figures (direct ps fixup).
felix@3266: # 	* Include files can now be scripted (at the expense of \includeonly).
felix@3266: # 	* Updated dependency graph to contain better node names.
felix@3266: # Chris Monson (2006-04-06):
felix@3266: # 	* Bumped version to 2.0b3
felix@3266: # 	* Top level includes now fail if there is no rule to build them
felix@3266: # 	* A helpful message is printed when they do fail
felix@3266: # 	* Grayscale has been changed to be ._gray_, other phonies use _ now, too
felix@3266: # 	* Grayscale handling has been completed
felix@3266: # 	* Changed _include_stems target to _includes target.
felix@3266: # 	* Fixed _includes target to be useful by itself.
felix@3266: # 	* Removed the ability to specify clean and build targets at once
felix@3266: # 	* Verified that epsfig works fine with current code
felix@3266: # 	* Fixed included scripts so that they are added to the dep files
felix@3266: # 	* Fixed so that graphics includes don't happen if they aren't for gpi
felix@3266: # 	* Fixed dot output to allow grayscale.
felix@3266: # Chris Monson (2006-04-05):
felix@3266: #	* Bumped version to 2.0b2
felix@3266: #	* Removed automatic -gray output.  It needs fixing in a bad way.
felix@3266: #	* Revamped dependency creation completely.
felix@3266: #	* Fixed conditional inclusion to actually work (test.nobuild.d, test.d).
felix@3266: #	* Fixed clean target to remove log targets
felix@3266: #	* Added the 'monochrome' word for gray gpi output
felix@3266: #	* Added a _check_gpi_files target that checks for common problems
felix@3266: #	* Changed the _version target into the version target (no _)
felix@3266: #	* Added better handling of grayscale files.  Use the .gray.pdf target.
felix@3266: #	* Fixed testing for rebuilds
felix@3266: # Chris Monson (2006-04-04):
felix@3266: #	* Bumped version to 2.0b1
felix@3266: #	* Changed colorization of output
felix@3266: #	* Made .auxbbl and .auxtex .make files secondary targets
felix@3266: #	* Shortened and simplified the final latex invocation loop
felix@3266: #	* Added version-specific output ($$i vs. $$$$i) in latex loop
felix@3266: #	* Added a build message for the first .dvi run (Building .dvi (0))
felix@3266: #	* Removed some build messages that most people don't care about.
felix@3266: #	* Simplified procedure for user-set colors -- simple text specification
felix@3266: #	* Fixed diff output to...not output.
felix@3266: #	* Fixed rerun bug -- detect not only when preceded with LaTeX Warning
felix@3266: #	* Sped up gpi plotting
felix@3266: #	* Added error handling and colorized output for gpi failure
felix@3266: #	* Documented color changing stuff.
felix@3266: #	* Now sort the flattened aux file to avoid false recompilation needs
felix@3266: #	* Added clean-nographics target
felix@3266: #	* Don't remove self.dvi file if self.aux is missing in the log
felix@3266: #	* Clarified some code.  Did some very minor adjusting.
felix@3266: # Chris Monson (2006-04-03):
felix@3266: #	* Bumped version to 2.0a7
felix@3266: #	* Added .dvi and .ps files as secondary files.
felix@3266: #	* Fixed handling of multiple run detection when includeonly is in use.
felix@3266: #	* Added code to flatten .aux files.
felix@3266: #	* Added more files as .SECONDARY prerequisites to avoid recompilation.
felix@3266: #	* Fixed the inputs generation to be much simpler and to use pipes.
felix@3266: #	* Added the dependency graph directly into the makefile.
felix@3266: #	* Changed flatten-aux to remove \@writefile \relax \newlabel, etc.
felix@3266: #	* Undid pipe changes with sed usage (BSD sed doesn't know -f-).
felix@3266: #	* Added a _check_programs target that tells you what your system has.
felix@3266: #	* Fixed an error in colorization that made unnecessary errors appear
felix@3266: #	* Added view targets.
felix@3266: #	* Updated help text.
felix@3266: #	* Augmented cookies so that .aux can trigger .bbl and .dvi rebuilds
felix@3266: #	* Added more informative error handling for dvips and ps2pdf
felix@3266: # Chris Monson (2006-04-02):
felix@3266: #	* Bumped version to 2.0a6
felix@3266: #	* Added indirection to .bbl dependencies to avoid rebuilding .bbl files
felix@3266: #	* Streamlined the diff invocation to eliminate an existence test
felix@3266: #	* Removed special shell quote escape variables
felix@3266: #	* Moved includes to a more prominent location
felix@3266: #	* Fixed .inputs.make to not contain .aux files
felix@3266: #	* Fixed embedding to use a file instead of always grepping.
felix@3266: #	* Added *.make.temp to the list of cleanable files
felix@3266: #	* Fixed Ruby.  It should now be supported properly.
felix@3266: #	* Now differentiate between all, default, and buildable files.
felix@3266: #	* Fixed to bail out on serious errors.
felix@3266: #	* Revised the handling of includable files.  Still working on it.
felix@3266: # Chris Monson (2006-03-31):
felix@3266: #	* Bumped version to 2.0a5
felix@3266: #	* Fixed a bug with LaTeX error detection (there can be spaces)
felix@3266: #	* Added .bbl support, simplifying everything and making it more correct
felix@3266: #	* Refactored some tests that muddy the code
felix@3266: #	* Did a little cleanup of some shell loops that can safely be make loops
felix@3266: #	* Added support for graphviz .dot files
felix@3266: #	* Made _all_programs output easier to read
felix@3266: #	* Added the ruby support that has long been advertised
felix@3266: #	* Font embedding was screwed up for PostScript -- now implicit
felix@3266: #	* Changed the generation of -gray.gpi files to a single command
felix@3266: #	* Changed any make-generated file that is not included from .d to .make
felix@3266: # Chris Monson (2006-03-30):
felix@3266: #	* Bumped version to 2.0a4
felix@3266: #	* Fixed a bug with very long graphics file names
felix@3266: #	* Added a todo entry for epsfig support
felix@3266: #	* Fixed a bug paper size bug: sometimes more than one entry appears
felix@3266: #	* Fixed DVI build echoing to display the number instead of process ID
felix@3266: #	* DVI files are now removed on first invocation if ANY file is missing
felix@3266: #	* Added a simple grayscale approach: if a file ends with -gray.gpi, it
felix@3266: #		is created from the corresponding .gpi file with a special
felix@3266: #		comment ##GRAY in its header, which causes coloring to be
felix@3266: #		turned off.
felix@3266: #	* Fixed a bug in the handling of .tex.sh files.  For some reason I had
felix@3266: #		neglected to define file stems for scripted output.
felix@3266: #	* Removed a trailing ; from the %.graphics dependencies
felix@3266: #	* Added dvips embedding (I think it works, anyway)
felix@3266: # Chris Monson (2006-03-29):
felix@3266: #	* Bumped version to 2.0a3
felix@3266: #	* Fixed error in make 3.79 with MAKEFILE_LIST usage
felix@3266: #	* Added the presumed filename to the _version output
felix@3266: #	* Added a vim macro for converting sed scripts to make commands
felix@3266: #	* Added gpi dependency support (plotting external files and loading gpi)
felix@3266: #	* Allow .gpi files to be ignored if called .include.gpi or .nobuild.gpi
felix@3266: #	* Fixed sed invocations where \+ was used.  BSD sed uses \{1,\}.
felix@3266: # Chris Monson (2006-03-28):
felix@3266: #	* Bumped version to 2.0a2
felix@3266: #	* Added SHELL_DEBUG and VERBOSE options
felix@3266: #	* Changed the default shell back to /bin/sh (unset, in other words)
felix@3266: #	* Moved .PHONY declarations closer to their targets
felix@3266: #	* Moved help text into its own define block to obtain better formatting
felix@3266: #	* Removed need for double-entry when adding a new program invocation
felix@3266: #	* Moved .SECONDARY declaration closer to its relevant occurrence
felix@3266: #	* Commented things more heavily
felix@3266: #	* Added help text about setting terminal and output in gnuplot
felix@3266: #	* Created more fine-grained clean targets
felix@3266: #	* Added a %.graphics target that generates all of %'s graphics
felix@3266: #	* Killed backward-compatible graphics generation (e.g., eps.gpi=gpi.eps)
felix@3266: #	* For now, we're just GPL 2, not 3.  Maybe it will change later
felix@3266: #	* Made the version and svninfo into variables
felix@3266: # Chris Monson (2006-03-27):
felix@3266: #	* Bumped version to 2.0a1
felix@3266: #	* Huge, sweeping changes -- automatic dependencies
felix@3266: 
felix@3266: # IMPORTANT!
felix@3266: #
felix@3266: # When adding to the following list, do not introduce any blank lines.  The
felix@3266: # list is extracted for documentation using sed and is terminated by a blank
felix@3266: # line.
felix@3266: #
felix@3266: # EXTERNAL PROGRAMS:
felix@3266: # = ESSENTIAL PROGRAMS =
felix@3266: # == Basic Shell Utilities ==
felix@3266: CAT		?= cat
felix@3266: CP		?= cp -f
felix@3266: DIFF		?= diff
felix@3266: ECHO		?= echo
felix@3266: EGREP		?= egrep
felix@3266: ENV		?= env
felix@3266: EXPR		?= expr
felix@3266: MV		?= mv -f
felix@3266: SED		?= sed
felix@3266: SORT		?= sort
felix@3266: TOUCH		?= touch
felix@3266: UNIQ		?= uniq
felix@3266: WHICH		?= which
felix@3266: XARGS		?= xargs
felix@3266: SLEEP		?= sleep
felix@3266: # == LaTeX (tetex-provided) ==
felix@3266: BIBTEX		?= bibtex
felix@3266: DVIPS		?= dvips
felix@3266: LATEX		?= latex
felix@3266: PDFLATEX	?= pdflatex
felix@3266: EPSTOPDF	?= epstopdf
felix@3266: MAKEINDEX	?= makeindex
felix@3266: KPSEWHICH	?= kpsewhich
felix@3266: GS		?= gs
felix@3266: # = OPTIONAL PROGRAMS =
felix@3266: # == Makefile Color Output ==
felix@3266: TPUT		?= tput
felix@3266: # == TeX Generation ==
felix@3266: PERL		?= perl
felix@3266: PYTHON		?= python
felix@3266: RST2LATEX	?= rst2latex.py
felix@3266: # == EPS Generation ==
felix@3266: CONVERT		?= convert	# ImageMagick
felix@3266: DOT		?= dot		# GraphViz
felix@3266: DOT2TEX		?= dot2tex	# dot2tex - add options (not -o) as needed
felix@3266: FIG2DEV		?= fig2dev	# XFig
felix@3266: GNUPLOT		?= gnuplot	# GNUplot
felix@3266: INKSCAPE	?= inkscape	# Inkscape (svg support)
felix@3266: XMGRACE		?= xmgrace	# XMgrace
felix@3266: PNGTOPNM	?= pngtopnm	# From NetPBM - step 1 for png -> eps
felix@3266: PPMTOPGM	?= ppmtopgm	# From NetPBM - (gray) step 2 for png -> eps
felix@3266: PNMTOPS		?= pnmtops	# From NetPBM - step 3 for png -> eps
felix@3266: GUNZIP		?= gunzip	# GZipped EPS
felix@3266: # == Beamer Enlarged Output ==
felix@3266: PSNUP		?= psnup
felix@3266: # == Viewing Stuff ==
felix@3266: VIEW_POSTSCRIPT	?= gv
felix@3266: VIEW_PDF	?= xpdf
felix@3266: VIEW_GRAPHICS	?= display
felix@3266: 
felix@3266: # Command options for embedding fonts and postscript->pdf conversion
felix@3266: PS_EMBED_OPTIONS	?= -dPDFSETTINGS=/printer -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100
felix@3266: PS_COMPATIBILITY	?= 1.4
felix@3266: 
felix@3266: # Defaults for GPI
felix@3266: DEFAULT_GPI_EPS_FONTSIZE	?= 22
felix@3266: DEFAULT_GPI_PDF_FONTSIZE	?= 12
felix@3266: 
felix@3266: # Style file for ReST
felix@3266: RST_STYLE_FILE			?= $(wildcard _rststyle_._include_.tex)
felix@3266: 
felix@3266: # This ensures that even when echo is a shell builtin, we still use the binary
felix@3266: # (the builtin doesn't always understand -n)
felix@3266: FIXED_ECHO	:= $(if $(findstring -n,$(shell $(ECHO) -n)),$(shell which echo),$(ECHO))
felix@3266: ECHO		:= $(if $(FIXED_ECHO),$(FIXED_ECHO),$(ECHO))
felix@3266: 
felix@3266: define determine-gnuplot-output-extension
felix@3266: $(if $(shell $(WHICH) $(GNUPLOT)),
felix@3266:      $(if $(findstring unknown or ambiguous, $(shell $(GNUPLOT) -e "set terminal pdf" 2>&1)),
felix@3266: 	  eps, pdf),
felix@3266:      none)
felix@3266: endef
felix@3266: 
felix@3266: GNUPLOT_OUTPUT_EXTENSION	?= $(strip $(call determine-gnuplot-output-extension))
felix@3266: 
felix@3266: # Directory into which we place "binaries" if it exists.
felix@3266: # Note that this can be changed on the commandline or in Makefile.ini:
felix@3266: #
felix@3266: # Command line:
felix@3266: #   make BINARY_TARGET_DIR=$HOME/pdfs myfile.pdf
felix@3266: #
felix@3266: # Also, you can specify a relative directory (relative to the Makefile):
felix@3266: #   make BINARY_TARGET_DIR=pdfs myfile.pdf
felix@3266: #
felix@3266: # Or, you can use Makefile.ini:
felix@3266: #
felix@3266: #   BINARY_TARGET_DIR := $(HOME)/bin_out
felix@3266: #
felix@3266: BINARY_TARGET_DIR	?= _out_
felix@3266: 
felix@3266: RESTARTS		:= $(if $(MAKE_RESTARTS),$(MAKE_RESTARTS),0)
felix@3266: # SH NOTES
felix@3266: #
felix@3266: # On some systems, /bin/sh, which is the default shell, is not linked to
felix@3266: # /bin/bash.  While bash is supposed to be sh-compatible when invoked as sh, it
felix@3266: # just isn't.  This section details some of the things you have to stay away
felix@3266: # from to remain sh-compatible.
felix@3266: #
felix@3266: #	* File pattern expansion does not work for {}
felix@3266: #	* [ "$x" = "$y" ] has to be [ x"$x" x"$y" ]
felix@3266: #	* &> for stderr redirection doesn't work, use 2>&1 instead
felix@3266: #
felix@3266: # BSD SED NOTES
felix@3266: #
felix@3266: # BSD SED is not very nice compared to GNU sed, but it is the most
felix@3266: # commonly-invoked sed on Macs (being based on BSD), so we have to cater to
felix@3266: # it or require people to install GNU sed.  It seems like the GNU
felix@3266: # requirement isn't too bad since this makefile is really a GNU makefile,
felix@3266: # but apparently GNU sed is much less common than GNU make in general, so
felix@3266: # I'm supporting it here.
felix@3266: #
felix@3266: # Sad experience has taught me the following about BSD sed:
felix@3266: #
felix@3266: # 	* \+ is not understood to mean \{1,\}
felix@3266: # 	* \| is meaningless (does not branch)
felix@3266: # 	* \n cannot be used as a substitution character
felix@3266: # 	* ? does not mean \{0,1\}, but is literal
felix@3266: # 	* a\ works, but only reliably for a single line if subsequent lines
felix@3266: # 		have forward slashes in them (as is the case in postscript)
felix@3266: #
felix@3266: # For more info (on the Mac) you can consult
felix@3266: #
felix@3266: # man -M /usr/share/man re_format
felix@3266: #
felix@3266: # And look for the word "Obsolete" near the bottom.
felix@3266: 
felix@3266: #
felix@3266: # EXTERNAL PROGRAM DOCUMENTATION SCRIPT
felix@3266: #
felix@3266: 
felix@3266: # $(call output-all-programs,[<output file>])
felix@3266: define output-all-programs
felix@3266: 	[ -f '$(this_file)' ] && \
felix@3266: 	$(SED) \
felix@3266: 		-e '/^[[:space:]]*#[[:space:]]*EXTERNAL PROGRAMS:/,/^$$/!d' \
felix@3266: 		-e '/EXTERNAL PROGRAMS/d' \
felix@3266: 		-e '/^$$/d' \
felix@3266: 		-e '/^[[:space:]]*#/i\ '\
felix@3266: 		-e 's/^[[:space:]]*#[[:space:]][^=]*//' \
felix@3266: 		$(this_file) $(if $1,> '$1',) || \
felix@3266: 	$(ECHO) "Cannot determine the name of this makefile."
felix@3266: endef
felix@3266: 
felix@3266: # If they misspell gray, it should still work.
felix@3266: GRAY	?= $(call get-default,$(GREY),)
felix@3266: 
felix@3266: #
felix@3266: # Utility Functions and Definitions
felix@3266: #
felix@3266: 
felix@3266: # While not exactly a make function, this vim macro is useful.  It takes a
felix@3266: # verbatim sed script and converts each line to something suitable in a command
felix@3266: # context.  Just paste the script's contents into the editor, yank this into a
felix@3266: # register (starting at '0') and run the macro once for each line of the
felix@3266: # original script:
felix@3266: #
felix@3266: # 0i	-e :s/\$/$$/eg
felix@3266: :s/'/'"'"'/eg
felix@3266: ^Ela'A' \:noh
felix@3266: j
felix@3266: 
felix@3266: # don't call this directly - it is here to avoid calling wildcard more than
felix@3266: # once in remove-files.
felix@3266: remove-files-helper	= $(if $1,$(RM) $1,$(sh_true))
felix@3266: 
felix@3266: # $(call remove-files,file1 file2)
felix@3266: remove-files		= $(call remove-files-helper,$(wildcard $1))
felix@3266: 
felix@3266: # Removes all cleanable files in the given list
felix@3266: # $(call clean-files,file1 file2 file3 ...)
felix@3266: # Works exactly like remove-files, but filters out files in $(neverclean)
felix@3266: clean-files		= \
felix@3266: 	$(call remove-files-helper,$(call cleanable-files,$(wildcard $1)))
felix@3266: 
felix@3266: # Outputs all generated files to STDOUT, along with some others that are
felix@3266: # created by these (e.g., .idx files end up producing .ilg and .ind files).
felix@3266: # Discovered by reading *.fls OUTPUT lines and producing corresponding .ind
felix@3266: # filenames as needed.
felix@3266: #
felix@3266: # $(call get-generated-names,<source recorder file (*.fls)>)
felix@3266: define get-generated-names
felix@3266: [ -f '$1' ] && \
felix@3266: $(SED) \
felix@3266: 	-e '/^OUTPUT /{' \
felix@3266: 	-e '  s///' \
felix@3266: 	-e '  p' \
felix@3266: 	-e '  s/\.idx/\.ind/p' \
felix@3266: 	-e '  s/\.ind/\.ilg/p' \
felix@3266: 	-e '}' \
felix@3266: 	-e 'd' \
felix@3266: 	'$1' \
felix@3266: | $(SORT) | $(UNIQ)
felix@3266: endef
felix@3266: 
felix@3266: # This removes files without checking whether they are there or not.  This
felix@3266: # sometimes has to be used when the file is created by a series of shell
felix@3266: # commands, but there ends up being a race condition: make doesn't know about
felix@3266: # the file generation as quickly as the system does, so $(wildcard ...) doesn't
felix@3266: # work right.  Blech.
felix@3266: # $(call remove-temporary-files,filenames)
felix@3266: remove-temporary-files	= $(if $1,$(RM) $1,:)
felix@3266: 
felix@3266: # Create an identifier from a file name
felix@3266: # $(call cleanse-filename,filename)
felix@3266: cleanse-filename	= $(subst .,_,$(subst /,__,$1))
felix@3266: 
felix@3266: # Escape dots
felix@3266: # $(call escape-dots,str)
felix@3266: escape-dots		= $(subst .,\\.,$1)
felix@3266: 
felix@3266: # Test that a file exists
felix@3266: # $(call test-exists,file)
felix@3266: test-exists		= [ -e '$1' ]
felix@3266: 
felix@3266: # $(call move-files,source,destination)
felix@3266: move-if-exists		= $(call test-exists,$1) && $(MV) '$1' '$2'
felix@3266: 
felix@3266: # Copy file1 to file2 only if file2 doesn't exist or they are different
felix@3266: # $(call copy-if-different,sfile,dfile)
felix@3266: copy-if-different	= $(call test-different,$1,$2) && $(CP) '$1' '$2'
felix@3266: copy-if-exists		= $(call test-exists,$1) && $(CP) '$1' '$2'
felix@3266: move-if-different	= $(call test-different,$1,$2) && $(MV) '$1' '$2'
felix@3266: replace-if-different-and-remove	= \
felix@3266: 	$(call test-different,$1,$2) \
felix@3266: 	&& $(MV) '$1' '$2' \
felix@3266: 	|| $(call remove-files,'$1')
felix@3266: 
felix@3266: # Note that $(DIFF) returns success when the files are the SAME....
felix@3266: # $(call test-different,sfile,dfile)
felix@3266: test-different		= ! $(DIFF) -q '$1' '$2' >/dev/null 2>&1
felix@3266: test-exists-and-different	= \
felix@3266: 	$(call test-exists,$2) && $(call test-different,$1,$2)
felix@3266: 
felix@3266: # Return value 1, or value 2 if value 1 is empty
felix@3266: # $(call get-default,<possibly empty arg>,<default value if empty>)
felix@3266: get-default	= $(if $1,$1,$2)
felix@3266: 
felix@3266: # Copy a file and log what's going on
felix@3266: # $(call copy-with-logging,<source>,<target>)
felix@3266: define copy-with-logging
felix@3266: if [ -d '$2/' ]; then \
felix@3266: 	if $(CP) '$1' '$2/'; then \
felix@3266: 		$(ECHO) "$(C_INFO)Copied '$1' to '$2/'$(C_RESET)"; \
felix@3266: 	else \
felix@3266: 		$(ECHO) "$(C_ERROR)Failed to copy '$1' to '$2/'$(C_RESET)"; \
felix@3266: 	fi; \
felix@3266: fi
felix@3266: endef
felix@3266: 
felix@3266: # Gives a reassuring message about the failure to find include files
felix@3266: # $(call include-message,<list of include files>)
felix@3266: define include-message
felix@3266: $(strip \
felix@3266: $(if $(filter-out $(wildcard $1),$1),\
felix@3266: 	$(shell $(ECHO) \
felix@3266: 	"$(C_INFO)NOTE: You may ignore warnings about the"\
felix@3266: 	"following files:" >&2;\
felix@3266: 	$(ECHO) >&2; \
felix@3266: 	$(foreach s,$(filter-out $(wildcard $1),$1),$(ECHO) '     $s' >&2;)\
felix@3266: 	$(ECHO) "$(C_RESET)" >&2)
felix@3266: ))
felix@3266: endef
felix@3266: # Characters that are hard to specify in certain places
felix@3266: space		:= $(empty) $(empty)
felix@3266: colon		:= \:
felix@3266: comma		:= ,
felix@3266: 
felix@3266: # Useful shell definitions
felix@3266: sh_true		:= :
felix@3266: sh_false	:= ! :
felix@3266: 
felix@3266: # Clear out the standard interfering make suffixes
felix@3266: .SUFFIXES:
felix@3266: 
felix@3266: # Turn off forceful rm (RM is usually mapped to rm -f)
felix@3266: ifdef SAFE_RM
felix@3266: RM	:= rm
felix@3266: endif
felix@3266: 
felix@3266: # Turn command echoing back on with VERBOSE=1
felix@3266: ifndef VERBOSE
felix@3266: QUIET	:= @
felix@3266: endif
felix@3266: 
felix@3266: # Turn on shell debugging with SHELL_DEBUG=1
felix@3266: # (EVERYTHING is echoed, even $(shell ...) invocations)
felix@3266: ifdef SHELL_DEBUG
felix@3266: SHELL	+= -x
felix@3266: endif
felix@3266: 
felix@3266: # Get the name of this makefile (always right in 3.80, often right in 3.79)
felix@3266: # This is only really used for documentation, so it isn't too serious.
felix@3266: ifdef MAKEFILE_LIST
felix@3266: this_file	:= $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
felix@3266: else
felix@3266: this_file	:= $(wildcard GNUmakefile makefile Makefile)
felix@3266: endif
felix@3266: 
felix@3266: # Terminal color definitions
felix@3266: 
felix@3266: REAL_TPUT 	:= $(if $(NO_COLOR),,$(shell $(WHICH) $(TPUT)))
felix@3266: 
felix@3266: # $(call get-term-code,codeinfo)
felix@3266: # e.g.,
felix@3266: # $(call get-term-code,setaf 0)
felix@3266: get-term-code = $(if $(REAL_TPUT),$(shell $(REAL_TPUT) $1),)
felix@3266: 
felix@3266: black	:= $(call get-term-code,setaf 0)
felix@3266: red	:= $(call get-term-code,setaf 1)
felix@3266: green	:= $(call get-term-code,setaf 2)
felix@3266: yellow	:= $(call get-term-code,setaf 3)
felix@3266: blue	:= $(call get-term-code,setaf 4)
felix@3266: magenta	:= $(call get-term-code,setaf 5)
felix@3266: cyan	:= $(call get-term-code,setaf 6)
felix@3266: white	:= $(call get-term-code,setaf 7)
felix@3266: bold	:= $(call get-term-code,bold)
felix@3266: uline	:= $(call get-term-code,smul)
felix@3266: reset	:= $(call get-term-code,sgr0)
felix@3266: 
felix@3266: #
felix@3266: # User-settable definitions
felix@3266: #
felix@3266: LATEX_COLOR_WARNING	?= magenta
felix@3266: LATEX_COLOR_ERROR	?= red
felix@3266: LATEX_COLOR_INFO	?= green
felix@3266: LATEX_COLOR_UNDERFULL	?= magenta
felix@3266: LATEX_COLOR_OVERFULL	?= red bold
felix@3266: LATEX_COLOR_PAGES	?= bold
felix@3266: LATEX_COLOR_BUILD	?= cyan
felix@3266: LATEX_COLOR_GRAPHIC	?= yellow
felix@3266: LATEX_COLOR_DEP		?= green
felix@3266: LATEX_COLOR_SUCCESS	?= green bold
felix@3266: LATEX_COLOR_FAILURE	?= red bold
felix@3266: 
felix@3266: # Gets the real color from a simple textual definition like those above
felix@3266: # $(call get-color,ALL_CAPS_COLOR_NAME)
felix@3266: # e.g., $(call get-color,WARNING)
felix@3266: get-color	= $(subst $(space),,$(foreach c,$(LATEX_COLOR_$1),$($c)))
felix@3266: 
felix@3266: #
felix@3266: # STANDARD COLORS
felix@3266: #
felix@3266: C_WARNING	:= $(call get-color,WARNING)
felix@3266: C_ERROR		:= $(call get-color,ERROR)
felix@3266: C_INFO		:= $(call get-color,INFO)
felix@3266: C_UNDERFULL	:= $(call get-color,UNDERFULL)
felix@3266: C_OVERFULL	:= $(call get-color,OVERFULL)
felix@3266: C_PAGES		:= $(call get-color,PAGES)
felix@3266: C_BUILD		:= $(call get-color,BUILD)
felix@3266: C_GRAPHIC	:= $(call get-color,GRAPHIC)
felix@3266: C_DEP		:= $(call get-color,DEP)
felix@3266: C_SUCCESS	:= $(call get-color,SUCCESS)
felix@3266: C_FAILURE	:= $(call get-color,FAILURE)
felix@3266: C_RESET		:= $(reset)
felix@3266: 
felix@3266: #
felix@3266: # PRE-BUILD TESTS
felix@3266: #
felix@3266: 
felix@3266: # Check that clean targets are not combined with other targets (weird things
felix@3266: # happen, and it's not easy to fix them)
felix@3266: hascleangoals	:= $(if $(sort $(filter clean clean-%,$(MAKECMDGOALS))),1)
felix@3266: hasbuildgoals	:= $(if $(sort $(filter-out clean clean-%,$(MAKECMDGOALS))),1)
felix@3266: ifneq "$(hasbuildgoals)" ""
felix@3266: ifneq "$(hascleangoals)" ""
felix@3266: $(error $(C_ERROR)Clean and build targets specified together$(C_RESET)))
felix@3266: endif
felix@3266: endif
felix@3266: 
felix@3266: #
felix@3266: # VARIABLE DECLARATIONS
felix@3266: #
felix@3266: 
felix@3266: # Names of sed scripts that morph gnuplot files -- only the first found is used
felix@3266: GNUPLOT_SED	:= global-gpi.sed gnuplot.sed
felix@3266: GNUPLOT_GLOBAL	:= global._include_.gpi gnuplot.global
felix@3266: 
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: default_graphic_extension	?= eps
felix@3266: latex_build_program		?= $(LATEX)
felix@3266: build_target_extension		?= dvi
felix@3266: hyperref_driver_pattern		?= hdvips
felix@3266: hyperref_driver_error		?= Using dvips: specify ps2pdf in the hyperref options.
felix@3266: else
felix@3266: default_graphic_extension	?= pdf
felix@3266: latex_build_program		?= $(PDFLATEX)
felix@3266: build_target_extension		?= pdf
felix@3266: hyperref_driver_pattern		?= hpdf.*
felix@3266: hyperref_driver_error		?= Using pdflatex: specify pdftex in the hyperref options (or leave it blank).
felix@3266: endif
felix@3266: 
felix@3266: # Files of interest
felix@3266: all_files.tex		?= $(wildcard *.tex)
felix@3266: all_files.tex.sh	?= $(wildcard *.tex.sh)
felix@3266: all_files.tex.pl	?= $(wildcard *.tex.pl)
felix@3266: all_files.tex.py	?= $(wildcard *.tex.py)
felix@3266: all_files.rst		?= $(wildcard *.rst)
felix@3266: all_files.fig		?= $(wildcard *.fig)
felix@3266: all_files.gpi		?= $(wildcard *.gpi)
felix@3266: all_files.dot		?= $(wildcard *.dot)
felix@3266: all_files.xvg		?= $(wildcard *.xvg)
felix@3266: all_files.svg		?= $(wildcard *.svg)
felix@3266: all_files.png		?= $(wildcard *.png)
felix@3266: all_files.jpg		?= $(wildcard *.jpg)
felix@3266: all_files.eps.gz	?= $(wildcard *.eps.gz)
felix@3266: all_files.eps		?= $(wildcard *.eps)
felix@3266: 
felix@3266: # Utility function for obtaining all files not specified in $(neverclean)
felix@3266: # $(call cleanable-files,file1 file2 file3 ...)
felix@3266: # Returns the list of files that is not in $(wildcard $(neverclean))
felix@3266: cleanable-files = $(filter-out $(wildcard $(neverclean)), $1)
felix@3266: 
felix@3266: # Utility function for getting all .$1 files that are to be ignored
felix@3266: #  * files listed in $(includes.$1)
felix@3266: #  * files not listed in $(onlysources.$1) if it is defined
felix@3266: ignore_files = \
felix@3266:   $(includes.$1) \
felix@3266:   $(if $(onlysources.$1),$(filter-out $(onlysources.$1), $(all_files.$1)))
felix@3266: 
felix@3266: # Patterns to never be allowed as source targets
felix@3266: ignore_patterns	:= %._include_
felix@3266: 
felix@3266: # Patterns allowed as source targets but not included in 'all' builds
felix@3266: nodefault_patterns := %._nobuild_ $(ignore_patterns)
felix@3266: 
felix@3266: # Utility function for getting targets suitable building
felix@3266: # $(call filter-buildable,suffix)
felix@3266: filter-buildable	= \
felix@3266: 	$(filter-out $(call ignore_files,$1) \
felix@3266: 		$(addsuffix .$1,$(ignore_patterns)),$(all_files.$1))
felix@3266: 
felix@3266: # Utility function for getting targets suitable for 'all' builds
felix@3266: # $(call filter-default,suffix)
felix@3266: filter-default		= \
felix@3266: 	$(filter-out $(call ignore_files,$1) \
felix@3266: 		$(addsuffix .$1,$(nodefault_patterns)),$(all_files.$1))
felix@3266: 
felix@3266: # Top level sources that can be built even when they are not by default
felix@3266: files.tex	:= $(call filter-buildable,tex)
felix@3266: files.tex.sh	:= $(call filter-buildable,tex.sh)
felix@3266: files.tex.pl	:= $(call filter-buildable,tex.pl)
felix@3266: files.tex.py	:= $(call filter-buildable,tex.py)
felix@3266: files.rst	:= $(call filter-buildable,rst)
felix@3266: files.gpi	:= $(call filter-buildable,gpi)
felix@3266: files.dot	:= $(call filter-buildable,dot)
felix@3266: files.fig	:= $(call filter-buildable,fig)
felix@3266: files.xvg	:= $(call filter-buildable,xvg)
felix@3266: files.svg	:= $(call filter-buildable,svg)
felix@3266: files.png	:= $(call filter-buildable,png)
felix@3266: files.jpg	:= $(call filter-buildable,jpg)
felix@3266: files.eps.gz	:= $(call filter-buildable,eps.gz)
felix@3266: 
felix@3266: # Make all pstex targets secondary.  The pstex_t target requires the pstex
felix@3266: # target, and nothing else really depends on it, so it often gets deleted.
felix@3266: # This avoids that by allowing *all* fig files to be pstex targets, which is
felix@3266: # perfectly valid and causes no problems even if they're going to become eps
felix@3266: # files in the end.
felix@3266: .SECONDARY:	$(patsubst %.fig,%.pstex,$(files.fig))
felix@3266: 
felix@3266: # Top level sources that are built by default targets
felix@3266: default_files.tex	:= $(call filter-default,tex)
felix@3266: default_files.tex.sh	:= $(call filter-default,tex.sh)
felix@3266: default_files.tex.pl	:= $(call filter-default,tex.pl)
felix@3266: default_files.tex.py	:= $(call filter-default,tex.py)
felix@3266: default_files.rst	:= $(call filter-default,rst)
felix@3266: default_files.gpi	:= $(call filter-default,gpi)
felix@3266: default_files.dot	:= $(call filter-default,dot)
felix@3266: default_files.fig	:= $(call filter-default,fig)
felix@3266: default_files.xvg	:= $(call filter-default,xvg)
felix@3266: default_files.svg	:= $(call filter-default,svg)
felix@3266: default_files.png	:= $(call filter-default,png)
felix@3266: default_files.jpg	:= $(call filter-default,jpg)
felix@3266: default_files.eps.gz	:= $(call filter-default,eps.gz)
felix@3266: 
felix@3266: # Utility function for creating larger lists of files
felix@3266: # $(call concat-files,suffixes,[prefix])
felix@3266: concat-files	= $(foreach s,$1,$($(if $2,$2_,)files.$s))
felix@3266: 
felix@3266: # Useful file groupings
felix@3266: all_files_source	:= $(call concat-files,tex,all)
felix@3266: all_files_scripts	:= $(call concat-files,tex.sh tex.pl tex.py rst,all)
felix@3266: 
felix@3266: .PHONY: $(all_files_scripts)
felix@3266: 
felix@3266: default_files_source	:= $(call concat-files,tex,default)
felix@3266: default_files_scripts	:= $(call concat-files,tex.sh tex.pl tex.py rst,default)
felix@3266: 
felix@3266: files_source	:= $(call concat-files,tex)
felix@3266: files_scripts	:= $(call concat-files,tex.sh tex.pl tex.py rst)
felix@3266: 
felix@3266: # Utility function for obtaining stems
felix@3266: # $(call get-stems,suffix,[prefix])
felix@3266: get-stems	= $(sort $($(if $2,$2_,)files.$1:%.$1=%))
felix@3266: 
felix@3266: # List of all stems (including ._include_ and ._nobuild_ file stems)
felix@3266: all_stems.tex		:= $(call get-stems,tex,all)
felix@3266: all_stems.tex.sh	:= $(call get-stems,tex.sh,all)
felix@3266: all_stems.tex.pl	:= $(call get-stems,tex.pl,all)
felix@3266: all_stems.tex.py	:= $(call get-stems,tex.py,all)
felix@3266: all_stems.rst		:= $(call get-stems,rst,all)
felix@3266: all_stems.fig		:= $(call get-stems,fig,all)
felix@3266: all_stems.gpi		:= $(call get-stems,gpi,all)
felix@3266: all_stems.dot		:= $(call get-stems,dot,all)
felix@3266: all_stems.xvg		:= $(call get-stems,xvg,all)
felix@3266: all_stems.svg		:= $(call get-stems,svg,all)
felix@3266: all_stems.png		:= $(call get-stems,png,all)
felix@3266: all_stems.jpg		:= $(call get-stems,jpg,all)
felix@3266: all_stems.eps.gz	:= $(call get-stems,eps.gz,all)
felix@3266: all_stems.eps		:= $(call get-stems,eps,all)
felix@3266: 
felix@3266: # List of all default stems (all default PDF targets):
felix@3266: default_stems.tex		:= $(call get-stems,tex,default)
felix@3266: default_stems.tex.sh		:= $(call get-stems,tex.sh,default)
felix@3266: default_stems.tex.pl		:= $(call get-stems,tex.pl,default)
felix@3266: default_stems.tex.py		:= $(call get-stems,tex.py,default)
felix@3266: default_stems.rst		:= $(call get-stems,rst,default)
felix@3266: default_stems.fig		:= $(call get-stems,fig,default)
felix@3266: default_stems.gpi		:= $(call get-stems,gpi,default)
felix@3266: default_stems.dot		:= $(call get-stems,dot,default)
felix@3266: default_stems.xvg		:= $(call get-stems,xvg,default)
felix@3266: default_stems.svg		:= $(call get-stems,svg,default)
felix@3266: default_stems.png		:= $(call get-stems,png,default)
felix@3266: default_stems.jpg		:= $(call get-stems,jpg,default)
felix@3266: default_stems.eps.gz		:= $(call get-stems,eps.gz,default)
felix@3266: 
felix@3266: # List of all stems (all possible bare PDF targets created here):
felix@3266: stems.tex		:= $(call get-stems,tex)
felix@3266: stems.tex.sh		:= $(call get-stems,tex.sh)
felix@3266: stems.tex.pl		:= $(call get-stems,tex.pl)
felix@3266: stems.tex.py		:= $(call get-stems,tex.py)
felix@3266: stems.rst		:= $(call get-stems,rst)
felix@3266: stems.fig		:= $(call get-stems,fig)
felix@3266: stems.gpi		:= $(call get-stems,gpi)
felix@3266: stems.dot		:= $(call get-stems,dot)
felix@3266: stems.xvg		:= $(call get-stems,xvg)
felix@3266: stems.svg		:= $(call get-stems,svg)
felix@3266: stems.png		:= $(call get-stems,png)
felix@3266: stems.jpg		:= $(call get-stems,jpg)
felix@3266: stems.eps.gz		:= $(call get-stems,eps.gz)
felix@3266: 
felix@3266: # Utility function for creating larger lists of stems
felix@3266: # $(call concat-stems,suffixes,[prefix])
felix@3266: concat-stems	= $(sort $(foreach s,$1,$($(if $2,$2_,)stems.$s)))
felix@3266: 
felix@3266: # The most likely to be source but not finished product go first
felix@3266: graphic_source_extensions	:= fig \
felix@3266: 				   gpi \
felix@3266: 				   xvg \
felix@3266: 				   svg \
felix@3266: 				   dot \
felix@3266: 				   eps.gz
felix@3266: 
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: graphic_source_extensions	+= png jpg
felix@3266: graphic_target_extensions	:= eps ps
felix@3266: else
felix@3266: graphic_source_extensions	+= eps
felix@3266: graphic_target_extensions	:= pdf png jpg mps tif
felix@3266: endif
felix@3266: 
felix@3266: all_stems_source	:= $(call concat-stems,tex,all)
felix@3266: all_stems_script	:= $(call concat-stems,tex.sh tex.pl tex.py rst,all)
felix@3266: all_stems_graphic	:= $(call concat-stems,$(graphic_source_extensions),all)
felix@3266: all_stems_ss		:= $(sort $(all_stems_source) $(all_stems_script))
felix@3266: all_stems_sg		:= $(sort $(all_stems_script))
felix@3266: all_stems_ssg		:= $(sort $(all_stems_ss))
felix@3266: 
felix@3266: default_stems_source	:= $(call concat-stems,tex,default)
felix@3266: default_stems_script	:= $(call concat-stems,tex.sh tex.pl tex.py rst,default)
felix@3266: default_stems_ss	:= $(sort $(default_stems_source) $(default_stems_script))
felix@3266: default_stems_sg	:= $(sort $(default_stems_script))
felix@3266: default_stems_ssg	:= $(sort $(default_stems_ss))
felix@3266: 
felix@3266: stems_source		:= $(call concat-stems,tex)
felix@3266: stems_script		:= $(call concat-stems,tex.sh tex.pl tex.py rst)
felix@3266: stems_graphic		:= $(call concat-stems,$(graphic_source_extensions))
felix@3266: stems_gg		:= $(sort $(stems_graphic))
felix@3266: stems_ss		:= $(sort $(stems_source) $(stems_script))
felix@3266: stems_sg		:= $(sort $(stems_script))
felix@3266: stems_ssg		:= $(sort $(stems_ss))
felix@3266: 
felix@3266: # Calculate names that can generate the need for an include file.  We can't
felix@3266: # really do this with patterns because it's too easy to screw up, so we create
felix@3266: # an exhaustive list.
felix@3266: allowed_source_suffixes	:= \
felix@3266: 	pdf \
felix@3266: 	ps \
felix@3266: 	dvi \
felix@3266: 	ind \
felix@3266: 	nls \
felix@3266: 	bbl \
felix@3266: 	aux \
felix@3266: 	aux.make \
felix@3266: 	d \
felix@3266: 	auxbbl.make \
felix@3266: 	_graphics \
felix@3266: 	_show
felix@3266: allowed_source_patterns		:= $(addprefix %.,$(allowed_source_suffixes))
felix@3266: 
felix@3266: allowed_graphic_suffixes	:= \
felix@3266: 	pdf \
felix@3266: 	eps \
felix@3266: 	gpihead.make \
felix@3266: 	gpi.d
felix@3266: allowed_graphic_patterns	:= $(addprefix %.,$(allowed_graphic_suffixes))
felix@3266: 
felix@3266: # All targets allowed to build documents
felix@3266: allowed_source_targets	:= \
felix@3266: 	$(foreach suff,$(allowed_source_suffixes),\
felix@3266: 	$(addsuffix .$(suff),$(stems_ssg)))
felix@3266: 
felix@3266: # All targets allowed to build graphics
felix@3266: allowed_graphic_targets	:= \
felix@3266: 	$(foreach suff,$(allowed_graphic_suffixes),\
felix@3266: 	$(addsuffix .$(suff),$(stems_gg)))
felix@3266: 
felix@3266: # All targets that build multiple documents (like 'all')
felix@3266: allowed_batch_source_targets	:= \
felix@3266: 	all \
felix@3266: 	all-pdf \
felix@3266: 	all-ps \
felix@3266: 	all-dvi \
felix@3266: 	all-bbl \
felix@3266: 	all-ind \
felix@3266: 	all-gls \
felix@3266: 	all-nls \
felix@3266: 	show
felix@3266: 
felix@3266: # All targets that build multiple graphics (independent of document)
felix@3266: allowed_batch_graphic_targets	:= \
felix@3266: 	all-graphics \
felix@3266: 	all-pstex \
felix@3266: 	all-dot2tex \
felix@3266: 	show-graphics
felix@3266: 
felix@3266: # Now we figure out which stuff is available as a make target for THIS RUN.
felix@3266: real_goals	:= $(call get-default,$(filter-out _includes,$(MAKECMDGOALS)),\
felix@3266: 			all)
felix@3266: 
felix@3266: specified_source_targets	:= $(strip \
felix@3266: 	$(filter $(allowed_source_targets) $(stems_ssg),$(real_goals)) \
felix@3266: 	)
felix@3266: 
felix@3266: specified_batch_source_targets	:= $(strip \
felix@3266: 	$(filter $(allowed_batch_source_targets),$(real_goals)) \
felix@3266: 	)
felix@3266: 
felix@3266: specified_graphic_targets	:= $(strip \
felix@3266: 	$(filter $(allowed_graphic_targets),$(real_goals)) \
felix@3266: 	)
felix@3266: 
felix@3266: specified_batch_graphic_targets	:= $(strip \
felix@3266: 	$(filter $(allowed_batch_graphic_targets),$(real_goals)) \
felix@3266: 	)
felix@3266: 
felix@3266: specified_gpi_targets	:= $(patsubst %.gpi,%.$(default_graphic_extension),\
felix@3266: 	$(filter $(patsubst %.$(default_graphic_extension),%.gpi,$(specified_graphic_targets)),\
felix@3266: 		$(all_files.gpi)) \
felix@3266: 	)
felix@3266: 
felix@3266: # Determine which .d files need including from the information gained above.
felix@3266: # This is done by first checking whether a batch target exists.  If it does,
felix@3266: # then all *default* stems are used to create possible includes (nobuild need
felix@3266: # not apply for batch status).  If no batch targets exist, then the individual
felix@3266: # targets are considered and appropriate includes are taken from them.
felix@3266: source_stems_to_include	:= \
felix@3266: 	$(sort\
felix@3266: 	$(if $(specified_batch_source_targets),\
felix@3266: 		$(default_stems_ss),\
felix@3266: 		$(foreach t,$(specified_source_targets),\
felix@3266: 		$(foreach p,$(allowed_source_patterns),\
felix@3266: 			$(patsubst $p,%,$(filter $p $(stems_ssg),$t)) \
felix@3266: 		)) \
felix@3266: 	))
felix@3266: 
felix@3266: # Determine which .gpi.d files are needed using the above information.  We
felix@3266: # first check whether a batch target is specified, then check individual
felix@3266: # graphics that may have been specified.
felix@3266: graphic_stems_to_include	:= \
felix@3266: 	$(sort\
felix@3266: 	$(if $(specified_batch_graphic_targets),\
felix@3266: 		$(default_stems.gpi),\
felix@3266: 		$(foreach t,$(specified_gpi_targets),\
felix@3266: 		$(foreach p,$(allowed_graphic_patterns),\
felix@3266: 			$(patsubst $p,%,$(filter $p,$t)) \
felix@3266: 		)) \
felix@3266: 	))
felix@3266: 
felix@3266: # All dependencies for the 'all' targets
felix@3266: all_pdf_targets		:= $(addsuffix .pdf,$(stems_ssg))
felix@3266: all_ps_targets		:= $(addsuffix .ps,$(stems_ssg))
felix@3266: all_dvi_targets		:= $(addsuffix .dvi,$(stems_ssg))
felix@3266: all_tex_targets		:= $(addsuffix .tex,$(stems_sg))
felix@3266: all_d_targets		:= $(addsuffix .d,$(stems_ssg))
felix@3266: all_graphics_targets	:= $(addsuffix .$(default_graphic_extension),$(stems_gg))
felix@3266: intermediate_graphics_targets	:= $(if $(filter pdf,$(default_graphic_extension)),$(addsuffix .eps,$(stems_gg)),)
felix@3266: all_pstex_targets	:= $(addsuffix .pstex_t,$(stems.fig))
felix@3266: all_dot2tex_targets	:= $(addsuffix .dot_t,$(stems.dot))
felix@3266: 
felix@3266: all_known_graphics	:= $(sort $(all_graphics_targets) $(wildcard *.$(default_graphic_extension)))
felix@3266: 
felix@3266: default_pdf_targets	:= $(addsuffix .pdf,$(default_stems_ss))
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: default_ps_targets	:= $(addsuffix .ps,$(default_stems_ss))
felix@3266: default_dvi_targets	:= $(addsuffix .dvi,$(default_stems_ss))
felix@3266: pre_pdf_extensions	:= dvi ps
felix@3266: endif
felix@3266: 
felix@3266: # Extensions generated by LaTeX invocation that can be removed when complete
felix@3266: rm_ext		:= \
felix@3266: 	log *.log aux $(pre_pdf_extensions) pdf blg bbl out nav snm toc lof lot lol pfg \
felix@3266: 	fls vrb idx ind ilg glg glo gls lox nls nlo nlg brf mtc maf brf
felix@3266: backup_patterns	:= *~ *.bak *.backup body.tmp head.tmp
felix@3266: 
felix@3266: graph_stem	:= _graph
felix@3266: 
felix@3266: # All LaTeX-generated files that can be safely removed
felix@3266: 
felix@3266: rm_tex := \
felix@3266: 	$(foreach e,$(rm_ext),$(addsuffix .$e,$(all_stems_source))) \
felix@3266: 	$(foreach e,$(rm_ext) tex,$(addsuffix .$e,$(all_stems_sg))) \
felix@3266: 	$(addsuffix .log,$(all_ps_targets) $(all_pdf_targets)) \
felix@3266: 	$(addsuffix .*.log,$(stems_graphic))
felix@3266: 
felix@3266: # These are the files that will affect .gpi transformation for all .gpi files.
felix@3266: #
felix@3266: # Use only the first one found.  Backward compatible values are at the end.
felix@3266: # Note that we use foreach, even though wildcard also returns a list, to ensure
felix@3266: # that the order in the uppercase variables is preserved.  Directory listings
felix@3266: # provide no such guarantee, so we avoid relying on them.
felix@3266: gpi_sed		:= $(strip \
felix@3266: 	$(firstword $(foreach f,$(GNUPLOT_SED),$(wildcard $f))))
felix@3266: gpi_global	:= $(strip \
felix@3266: 	$(firstword $(foreach f,$(GNUPLOT_GLOBAL),$(wildcard $f))))
felix@3266: 
felix@3266: #
felix@3266: # Functions used in generating output
felix@3266: #
felix@3266: 
felix@3266: # Outputs all source dependencies to stdout.  The first argument is the file to
felix@3266: # be parsed, the second is a list of files that will show up as dependencies in
felix@3266: # the new .d file created here.
felix@3266: #
felix@3266: # NOTE: BSD sed does not understand \|, so we have to do something more
felix@3266: # clunky to extract suitable extensions.
felix@3266: #
felix@3266: # Also, we do a little bit of funny rewriting up front (TARGETS=) to make sure
felix@3266: # that we can properly backslash-escape spaces in file names (e.g, on Cygwin
felix@3266: # for tex distributions that have "Program Files" in their name).
felix@3266: #
felix@3266: # $(call get-inputs,<parsed file>,<target files>)
felix@3266: define get-inputs
felix@3266: $(SED) \
felix@3266: -e '/^INPUT/!d' \
felix@3266: -e 's!^INPUT \(\./\)\{0,1\}!!' \
felix@3266: -e 's/[[:space:]]/\\ /g' \
felix@3266: -e 's/\(.*\)\.aux$$/\1.tex/' \
felix@3266: -e '/\.tex$$/b addtargets' \
felix@3266: -e '/\.cls$$/b addtargets' \
felix@3266: -e '/\.sty$$/b addtargets' \
felix@3266: -e '/\.pstex_t$$/b addtargets' \
felix@3266: -e '/\.dot_t$$/b addtargets' \
felix@3266: -e 'd' \
felix@3266: -e ':addtargets' \
felix@3266: -e 's/^/$2: /' \
felix@3266: $1 | $(SORT) | $(UNIQ)
felix@3266: endef
felix@3266: 
felix@3266: # $(call get-missing-inputs,<log file>,<target files>)
felix@3266: define get-missing-inputs
felix@3266: $(SED) \
felix@3266: -e '$$ b para' \
felix@3266: -e '/^$$/b para' \
felix@3266: -e 'H' \
felix@3266: -e 'd' \
felix@3266: -e ':para' \
felix@3266: -e 'x' \
felix@3266: -e '/^$$/d' \
felix@3266: -e 's/^\n*//' \
felix@3266: -e '/^! LaTeX Error: File /{' \
felix@3266: -e '  s/^/::DOUBLE_PARAGRAPH::/' \
felix@3266: -e '  h' \
felix@3266: -e '  d' \
felix@3266: -e '}' \
felix@3266: -e 's/^::DOUBLE_PARAGRAPH:://' \
felix@3266: -e '/Default extension: /!d' \
felix@3266: -e 's/[[:space:]]\{1,\}/ /g' \
felix@3266: -e 's/\n\{1,\}/ /g' \
felix@3266: -e 's/^.*File `//' \
felix@3266: -e 's/'"'"' not found\..*//' \
felix@3266: -e '/\.tex/!s/$$/.tex/' \
felix@3266: -e 's/[[:space:]]/\\ /g' \
felix@3266: -e 'h' \
felix@3266: -e 's/.*/# MISSING input "&" - (presence of comment affects build)/' \
felix@3266: -e 'p' \
felix@3266: -e 's/.*//' \
felix@3266: -e 'x' \
felix@3266: -e 's/^/$2: /' \
felix@3266: $1 | $(SORT) | $(UNIQ)
felix@3266: endef
felix@3266: 
felix@3266: # Get source file for specified graphics stem.
felix@3266: #
felix@3266: # $(call graphics-source,<stem>)
felix@3266: define graphics-source
felix@3266: $(strip $(firstword \
felix@3266: 	$(wildcard \
felix@3266: 		$(addprefix $1.,\
felix@3266: 			$(graphic_source_extensions))) \
felix@3266: 	$1 \
felix@3266: ))
felix@3266: endef
felix@3266: 
felix@3266: # Get the target file for the specified graphics file/stem
felix@3266: #
felix@3266: # $(call graphics-target,<stem>)
felix@3266: define graphics-target
felix@3266: $(strip $(if 	$(filter $(addprefix %.,$(graphic_target_extensions)),$1), $1,
felix@3266: 	$(firstword $(patsubst $(addprefix %.,$(graphic_source_extensions) $(graphic_target_extensions)), %, $1).$(default_graphic_extension) $1.$(default_graphic_extension))))
felix@3266: endef
felix@3266: 
felix@3266: # Outputs all of the graphical dependencies to stdout.  The first argument is
felix@3266: # the stem of the source file being built, the second is a list of suffixes
felix@3266: # that will show up as dependencies in the generated .d file.
felix@3266: #
felix@3266: # Note that we try to escape spaces in filenames where possible.  We have to do
felix@3266: # it with three backslashes so that as the name percolates through the makefile
felix@3266: # it eventually ends up with the proper escaping when the build rule is found.
felix@3266: # Ugly, but it appears to work.  Note that graphicx doesn't allow filenames
felix@3266: # with spaces, so this could in many ways be moot unless you're using something
felix@3266: # like grffile.
felix@3266: #
felix@3266: # For pdflatex, we really need the missing file to be specified without an
felix@3266: # extension, otherwise compilation barfs on the first missing file.  Truly
felix@3266: # annoying, but there you have it.
felix@3266: #
felix@3266: # It turns out that the graphics errors, although they have lines with empty
felix@3266: # space, are only made of two paragraphs.  So, we just use some sed magic to
felix@3266: # get everything into paragraphs, detect when it's a paragraph that interests
felix@3266: # us, and double it up.  Then we get the filename only if we're missing
felix@3266: # extensions (a sign that it's graphicx complaining).
felix@3266: #
felix@3266: # $(call get-graphics,<target file stem>)
felix@3266: #.log,$(addprefix $*.,d $(build_target_extension) _graphics)
felix@3266: define get-graphics
felix@3266: $(SED) \
felix@3266: -e '$$ b para' \
felix@3266: -e '/^$$/b para' \
felix@3266: -e 'H' \
felix@3266: -e 'd' \
felix@3266: -e ':para' \
felix@3266: -e 'x' \
felix@3266: -e '/^$$/d' \
felix@3266: -e 's/^\n*//' \
felix@3266: -e '/^! LaTeX Error: File `/{' \
felix@3266: -e '  s/^/::DOUBLE_PARAGRAPH::/' \
felix@3266: -e '  h' \
felix@3266: -e '  d' \
felix@3266: -e '}' \
felix@3266: -e 's/^::DOUBLE_PARAGRAPH:://' \
felix@3266: -e '/could not locate the file with any of these extensions:/{' \
felix@3266: -e '  s/\n\{1,\}/ /g' \
felix@3266: -e '  s/[[:space:]]\{1,\}/ /g' \
felix@3266: -e '  s/^.*File `//' \
felix@3266: -e '  s/'"'"' not found\..*//' \
felix@3266: -e '  h' \
felix@3266: -e '  s/.*/# MISSING stem "&" - (presence of comment affects build)/' \
felix@3266: -e '  p' \
felix@3266: -e '  g' \
felix@3266: -e '  b addtargets' \
felix@3266: -e '}' \
felix@3266: -e '/.*File: \(.*\) Graphic file (type [^)]*).*/{' \
felix@3266: -e '  s//\1/' \
felix@3266: -e '  b addtargets' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: -e ':addtargets' \
felix@3266: -e 's/[[:space:]]/\\\\\\&/g' \
felix@3266: -e 'h' \
felix@3266: -e 's/.*/-include &.gpi.d/' \
felix@3266: -e 'p' \
felix@3266: -e 'g' \
felix@3266: -e 's/.*/$(addprefix $1,.d): $$$$(call graphics-source,&)/' \
felix@3266: -e 'p' \
felix@3266: -e 's/.*//' \
felix@3266: -e 'x' \
felix@3266: -e 's/.*/$(addprefix $1.,$(build_target_extension) _graphics): $$$$(call graphics-target,&)/' \
felix@3266: -e 'p' \
felix@3266: -e 'd' \
felix@3266: $*.log
felix@3266: endef
felix@3266: 
felix@3266: # Checks for build failure due to pstex inclusion, and gives instructions.
felix@3266: #
felix@3266: # $(call die-on-pstexs,<parsed file>)
felix@3266: define die-on-pstexs
felix@3266: if $(EGREP) -q '^! LaTeX Error: File .*\.pstex.* not found' $1; then \
felix@3266: 	$(ECHO) "$(C_ERROR)Missing pstex_t file(s)$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)Please run$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)  make all-pstex$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)before proceeding.$(C_RESET)"; \
felix@3266: 	exit 1; \
felix@3266: fi
felix@3266: endef
felix@3266: 
felix@3266: # Checks for build failure due to dot2tex, and gives instructions.
felix@3266: #
felix@3266: # $(call die-on-dot2tex,<parsed file>)
felix@3266: define die-on-dot2tex
felix@3266: if $(EGREP) -q ' LaTeX Error: File .*\.dot_t.* not found' $1; then \
felix@3266: 	$(ECHO) "$(C_ERROR)Missing dot_t file(s)$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)Please run$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)  make all-dot2tex$(C_RESET)"; \
felix@3266: 	$(ECHO) "$(C_ERROR)before proceeding.$(C_RESET)"; \
felix@3266: 	exit 1; \
felix@3266: fi
felix@3266: endef
felix@3266: 
felix@3266: # Checks for the existence of a .aux file, and dies with an error message if it
felix@3266: # isn't there.  Note that we pass the file stem in, not the full filename,
felix@3266: # e.g., to check for foo.aux, we call it thus: $(call die-on-no-aux,foo)
felix@3266: #
felix@3266: # $(call die-on-no-aux,<aux stem>)
felix@3266: define die-on-no-aux
felix@3266: if [ ! -e '$1.aux' ]; then \
felix@3266: 	$(call colorize-latex-errors,$1.log); \
felix@3266: 	exit 1; \
felix@3266: fi
felix@3266: endef
felix@3266: 
felix@3266: # Outputs all index files to stdout.  Arg 1 is the source file stem, arg 2 is
felix@3266: # the list of targets for the discovered dependency.
felix@3266: #
felix@3266: # $(call get-log-index,<log file stem>,<target files>)
felix@3266: define get-log-index
felix@3266: $(SED) \
felix@3266: -e 's/^No file \(.*\.ind\)\.$$/TARGETS=\1/' \
felix@3266: -e 's/^No file \(.*\.[gn]ls\)\.$$/TARGETS=\1/' \
felix@3266: -e 's/[[:space:]]/\\&/g' \
felix@3266: -e '/^TARGETS=/{' \
felix@3266: -e '  h' \
felix@3266: -e '  s/^TARGETS=/$2: /p' \
felix@3266: -e '  g' \
felix@3266: -e '  s/^TARGETS=\(.*\)/\1: $1.tex/p' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: '$1.log' | $(SORT) | $(UNIQ)
felix@3266: endef
felix@3266: 
felix@3266: 
felix@3266: # Outputs all bibliography files to stdout.  Arg 1 is the source stem, arg 2 is
felix@3266: # a list of targets for each dependency found.
felix@3266: #
felix@3266: # The script kills all lines that do not contain bibdata.  Remaining lines have
felix@3266: # the \bibdata macro and delimiters removed to create a dependency list.  A
felix@3266: # trailing comma is added, then all adjacent commas are collapsed into a single
felix@3266: # comma.  Then commas are replaced with the string .bib[space], and the
felix@3266: # trailing space is killed off.  Finally, all filename spaces are escaped.
felix@3266: # This produces a list of space-delimited .bib filenames, which is what the
felix@3266: # make dep file expects to see.
felix@3266: #
felix@3266: # Note that we give kpsewhich a bogus argument so that a failure of sed to
felix@3266: # produce output will not cause an error.
felix@3266: #
felix@3266: # $(call get-bibs,<aux file>,<targets>)
felix@3266: define get-bibs
felix@3266: $(SED) \
felix@3266: -e '/^\\bibdata/!d' \
felix@3266: -e 's/\\bibdata{\([^}]*\)}/\1,/' \
felix@3266: -e 's/,\{2,\}/,/g' \
felix@3266: -e 's/[[:space:]]/\\&/g' \
felix@3266: -e 's/,/.bib /g' \
felix@3266: -e 's/ \{1,\}$$//' \
felix@3266: $1 | $(XARGS) $(KPSEWHICH) '#######' | \
felix@3266: $(SED) \
felix@3266: -e 's/^/$2: /' | \
felix@3266: \$(SORT) | $(UNIQ)
felix@3266: endef
felix@3266: 
felix@3266: # Makes a an aux file that only has stuff relevant to the target in it
felix@3266: # $(call make-auxtarget-file,<flattened-aux>,<new-aux>)
felix@3266: define make-auxtarget-file
felix@3266: $(SED) \
felix@3266: -e '/^\\newlabel/!d' \
felix@3266: $1 > $2
felix@3266: endef
felix@3266: 
felix@3266: # Makes an aux file that only has stuff relevant to the bbl in it
felix@3266: # $(call make-auxbbl-file,<flattened-aux>,<new-aux>)
felix@3266: define make-auxbbl-file
felix@3266: $(SED) \
felix@3266: -e '/^\\newlabel/d' \
felix@3266: $1 > $2
felix@3266: endef
felix@3266: 
felix@3266: # Makes a .gpi.d file from a .gpi file
felix@3266: # $(call make-gpi-d,<.gpi>,<.gpi.d>)
felix@3266: define make-gpi-d
felix@3266: $(ECHO) '# vim: ft=make' > $2; \
felix@3266: $(ECHO) 'ifndef INCLUDED_$(call cleanse-filename,$2)' >> $2; \
felix@3266: $(ECHO) 'INCLUDED_$(call cleanse-filename,$2) := 1' >> $2; \
felix@3266: $(call get-gpi-deps,$1,$(addprefix $(2:%.gpi.d=%).,$(GNUPLOT_OUTPUT_EXTENSION) gpi.d)) >> $2; \
felix@3266: $(ECHO) 'endif' >> $2;
felix@3266: endef
felix@3266: 
felix@3266: # Parse .gpi files for data and loaded dependencies, output to stdout
felix@3266: #
felix@3266: # The sed script here tries to be clever about obtaining valid
felix@3266: # filenames from the gpi file.  It assumes that the plot command starts its own
felix@3266: # line, which is not too difficult a constraint to satisfy.
felix@3266: #
felix@3266: # This command script also generates 'include' directives for every 'load'
felix@3266: # command in the .gpi file.  The load command must appear on a line by itself
felix@3266: # and the file it loads must have the suffix .gpi.  If you don't want it to be
felix@3266: # compiled when running make graphics, then give it a suffix of ._include_.gpi.
felix@3266: #
felix@3266: # $(call get-gpi-deps,<gpi file>,<targets>)
felix@3266: define get-gpi-deps
felix@3266: $(SED) \
felix@3266: -e '/^[[:space:]]*s\{0,1\}plot/,/[^\\]$$/{' \
felix@3266: -e ' H' \
felix@3266: -e ' /[^\\]$$/{' \
felix@3266: -e '  s/.*//' \
felix@3266: -e '  x' \
felix@3266: -e '  s/\\\{0,1\}\n//g' \
felix@3266: -e '  s/^[[:space:]]*s\{0,1\}plot[[:space:]]*\(\[[^]]*\][[:space:]]*\)*/,/' \
felix@3266: -e '  s/[[:space:]]*\(['\''"][^'\''"]*['\''"]\)\{0,1\}[^,]*/\1/g' \
felix@3266: -e '  s/,['\''"]-\{0,1\}['\''"]//g' \
felix@3266: -e '  s/[,'\''"]\{1,\}/ /g' \
felix@3266: -e '  s!.*!$2: &!' \
felix@3266: -e '  p' \
felix@3266: -e ' }' \
felix@3266: -e ' d' \
felix@3266: -e '}' \
felix@3266: -e 's/^[[:space:]]*load[[:space:]]*['\''"]\([^'\''"]*\.gpi\)['\''"].*$$/-include \1.d/p' \
felix@3266: -e 'd' \
felix@3266: $1
felix@3266: endef
felix@3266: 
felix@3266: # Colorizes real, honest-to-goodness LaTeX errors that can't be overcome with
felix@3266: # recompilation.
felix@3266: #
felix@3266: # Note that we only ignore file not found errors for things that we know how to
felix@3266: # build, like graphics files.
felix@3266: #
felix@3266: # $(call colorize-latex-errors,<log file>)
felix@3266: define colorize-latex-errors
felix@3266: $(SED) \
felix@3266: -e '$$ b para' \
felix@3266: -e '/^$$/b para' \
felix@3266: -e 'H' \
felix@3266: -e 'd' \
felix@3266: -e ':para' \
felix@3266: -e 'x' \
felix@3266: -e '/^$$/d' \
felix@3266: -e 's/^\n*//' \
felix@3266: -e '/^! LaTeX Error: File /{' \
felix@3266: -e '  s/^/::DOUBLE_PARAGRAPH::/' \
felix@3266: -e '  h' \
felix@3266: -e '  d' \
felix@3266: -e '}' \
felix@3266: -e 's/^::DOUBLE_PARAGRAPH:://' \
felix@3266: -e '/could not locate the file with any of these extensions:/d' \
felix@3266: -e '/Missing .begin.document/{' \
felix@3266: -e '  h' \
felix@3266: -e '  s/.*/Are you trying to build an include file?/' \
felix@3266: -e '  x' \
felix@3266: -e '  G' \
felix@3266: -e '}' \
felix@3266: -e '/ LaTeX Error: Cannot determine size/d' \
felix@3266: -e 's/.* LaTeX Error .*/$(C_ERROR)&$(C_RESET)/p' \
felix@3266: -e 's/Error: pdflatex (file .*/$(C_ERROR)& - try specifying it without an extension$(C_RESET)/p' \
felix@3266: -e '/.*\*hyperref using.*driver \(.*\)\*.*/{' \
felix@3266: -e '  s//\1/' \
felix@3266: -e '  /^$(hyperref_driver_pattern)$$/!{' \
felix@3266: -e '    s/.*//' \
felix@3266: -e '    p' \
felix@3266: -e '    s/.*/$(C_ERROR)--- Using incorrect driver for hyperref! ---$(C_RESET)/' \
felix@3266: -e '    p' \
felix@3266: -e '    s/.*/$(C_ERROR)$(hyperref_driver_error)$(C_RESET)/' \
felix@3266: -e '    p' \
felix@3266: -e '  }' \
felix@3266: -e '  d' \
felix@3266: -e '}' \
felix@3266: -e '/ LaTeX Error: Unknown graphics extension/{' \
felix@3266: -e '  s/^/     /' \
felix@3266: -e '  h' \
felix@3266: -e '  s/.*/--- Graphics extension error:/' \
felix@3266: -e '  G' \
felix@3266: -e '  h' \
felix@3266: -e '  s/.*/--- If you specified the extension explicitly in your .tex file, try removing it./' \
felix@3266: -e '  H' \
felix@3266: -e '  g' \
felix@3266: -e '  s/.*/$(C_ERROR)&$(C_RESET)/' \
felix@3266: -e '  p' \
felix@3266: -e '  s/.*//' \
felix@3266: -e '  h' \
felix@3266: -e '  b' \
felix@3266: -e '}' \
felix@3266: -e 's/.*\(\n\{0,\}! .*\)/$(C_ERROR)\1$(C_RESET)/p' \
felix@3266: -e 'd' \
felix@3266: $1
felix@3266: endef
felix@3266: 
felix@3266: # Colorize Makeindex errors
felix@3266: define colorize-makeindex-errors
felix@3266: $(SED) \
felix@3266: -e '/^!! /{' \
felix@3266: -e '  N' \
felix@3266: -e '  s/^.*$$/$(C_ERROR)&$(C_RESET)/' \
felix@3266: -e '  p' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: $1
felix@3266: endef
felix@3266: 
felix@3266: # Colorize epstopdf errors
felix@3266: #
felix@3266: # $(call colorize-epstopdf-errors,<log file>)
felix@3266: define colorize-epstopdf-errors
felix@3266: $(SED) \
felix@3266: -e '/^Error:/,/^Execution stack:/{' \
felix@3266: -e '  /^Execution stack:/d' \
felix@3266: -e '  s/.*/$(C_ERROR)&$(C_RESET)/' \
felix@3266: -e '  p' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: $1
felix@3266: endef
felix@3266: 
felix@3266: # Colorize GNUplot errors
felix@3266: #
felix@3266: # $(call colorize-gnuplot-errors,<log file>)
felix@3266: define colorize-gnuplot-errors
felix@3266: $(SED) \
felix@3266: -e '/, line [0-9]*:/!{' \
felix@3266: -e '  H' \
felix@3266: -e '  x' \
felix@3266: -e '  s/.*\n\(.*\n.*\)$$/\1/' \
felix@3266: -e '  x' \
felix@3266: -e '}' \
felix@3266: -e '/, line [0-9]*:/{' \
felix@3266: -e '  H' \
felix@3266: -e '  /unknown.*terminal type/{' \
felix@3266: -e '    s/.*/--- Try changing the GNUPLOT_OUTPUT_EXTENSION variable to 'eps'./' \
felix@3266: -e '	H' \
felix@3266: -e '  }' \
felix@3266: -e '  /gpihead/{' \
felix@3266: -e '    s/.*/--- This could be a Makefile bug - contact the maintainer./' \
felix@3266: -e '    H' \
felix@3266: -e '  }' \
felix@3266: -e '  g' \
felix@3266: -e '  s/.*/$(C_ERROR)&$(C_RESET)/' \
felix@3266: -e '  p' \
felix@3266: -e '}' \
felix@3266: -e '/^gnuplot>/,/^$$/{' \
felix@3266: -e '  s/^gnuplot.*/$(C_ERROR)&/' \
felix@3266: -e '  s/^$$/$(C_RESET)/' \
felix@3266: -e '  p' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: $1
felix@3266: endef
felix@3266: 
felix@3266: # Colorize GraphViz errors
felix@3266: #
felix@3266: # $(call colorize-dot-errors,<log file>)
felix@3266: define colorize-dot-errors
felix@3266: $(SED) \
felix@3266: -e '/^Error:/,/context:/s/.*/$(C_ERROR)&$(C_RESET)/p' \
felix@3266: -e 's/^Warning:.*/$(C_WARNING)&$(C_RESET)/p' \
felix@3266: -e 'd' \
felix@3266: '$1'
felix@3266: endef
felix@3266: 
felix@3266: # Get all important .aux files from the top-level .aux file and merges them all
felix@3266: # into a single file, which it outputs to stdout.
felix@3266: #
felix@3266: # $(call flatten-aux,<toplevel aux>,<output file>)
felix@3266: define flatten-aux
felix@3266: $(SED) \
felix@3266: -e '/\\@input{\(.*\)}/{' \
felix@3266: -e     's//\1/' \
felix@3266: -e     's![.:]!\\&!g' \
felix@3266: -e     'h' \
felix@3266: -e     's!.*!\\:\\\\@input{&}:{!' \
felix@3266: -e     'p' \
felix@3266: -e     'x' \
felix@3266: -e     's/\\././g' \
felix@3266: -e     's/.*/r &/p' \
felix@3266: -e     's/.*/d/p' \
felix@3266: -e     's/.*/}/p' \
felix@3266: -e     'd' \
felix@3266: -e '}' \
felix@3266: -e 'd' \
felix@3266: '$1' > "$1.$$$$.sed.make"; \
felix@3266: $(SED) -f "$1.$$$$.sed.make" '$1' > "$1.$$$$.make"; \
felix@3266: $(SED) \
felix@3266: -e '/^\\relax/d' \
felix@3266: -e '/^\\bibcite/d' \
felix@3266: -e 's/^\(\\newlabel{[^}]\{1,\}}\).*/\1/' \
felix@3266: "$1.$$$$.make" | $(SORT) > '$2'; \
felix@3266: $(call remove-temporary-files,$1.$$$$.make $1.$$$$.sed.make)
felix@3266: endef
felix@3266: 
felix@3266: # Generate pdf from postscript
felix@3266: #
felix@3266: # Note that we don't just call ps2pdf, since there are so many versions of that
felix@3266: # script on various systems.  Instead, we call the postscript interpreter
felix@3266: # directly.
felix@3266: #
felix@3266: # $(call ps2pdf,infile,outfile,[embed fonts])
felix@3266: define ps2pdf
felix@3266: 	$(GS) \
felix@3266: 		-dSAFER -dCompatibilityLevel=$(PS_COMPATIBILITY) \
felix@3266: 		$(if $3,$(PS_EMBED_OPTIONS)) \
felix@3266: 		-q -dNOPAUSE -dBATCH \
felix@3266: 		-sDEVICE=pdfwrite -sstdout=%stderr \
felix@3266: 		'-sOutputFile=$2' \
felix@3266: 		-dSAFER -dCompatibilityLevel=$(PS_COMPATIBILITY) \
felix@3266: 		$(if $3,$(PS_EMBED_OPTIONS)) \
felix@3266: 		-c .setpdfwrite \
felix@3266: 		-f '$1'
felix@3266: endef
felix@3266: 
felix@3266: # Colorize LaTeX output.
felix@3266: # This uses a neat trick from the Sed & Awk Book from O'Reilly:
felix@3266: # 1) If a line has a single ending paren, delete it to make a blank line (so
felix@3266: #	that we catch the first error, which is not always preceded by a blank
felix@3266: #	line).
felix@3266: # 2) Ensure that the last line of the file gets appended to the hold buffer,
felix@3266: # 	and blank it out to trigger end-of-paragraph logic below.
felix@3266: # 3) When encountering a blank line (LaTeX output helpfully breaks output on
felix@3266: # 	newlines)
felix@3266: # 	a) swap the hold buffer (containing the paragraph) into the pattern buffer (putting a blank line into the hold buffer),
felix@3266: # 	b) remove the newline at the beginning (don't ask),
felix@3266: # 	c) apply any colorizing substitutions necessary to ensure happiness.
felix@3266: # 	d) get the newline out of the hold buffer and append it
felix@3266: # 	e) profit! (print)
felix@3266: # 4) Anything not colorized is deleted, unless in verbose mode.
felix@3266: color_tex	:= \
felix@3266: 	$(SED) \
felix@3266: 	-e '$${' \
felix@3266: 	-e '  /^$$/!{' \
felix@3266: 	-e '    H' \
felix@3266: 	-e '    s/.*//' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '}' \
felix@3266: 	-e '/^$$/!{' \
felix@3266: 	-e '  H' \
felix@3266: 	-e '  d' \
felix@3266: 	-e '}' \
felix@3266: 	-e '/^$$/{' \
felix@3266: 	-e '  x' \
felix@3266: 	-e '  s/^\n//' \
felix@3266: 	-e '  /Output written on /{' \
felix@3266: 	-e '    s/.*Output written on \([^(]*\) (\([^)]\{1,\}\)).*/Success!  Wrote \2 to \1/' \
felix@3266: 	-e '    s/[[:digit:]]\{1,\}/$(C_PAGES)&$(C_RESET)/g' \
felix@3266: 	-e '    s/Success!/$(C_SUCCESS)&$(C_RESET)/g' \
felix@3266: 	-e '    s/to \(.*\)$$/to $(C_SUCCESS)\1$(C_RESET)/' \
felix@3266: 	-e '    b end' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  / *LaTeX Error:.*/{' \
felix@3266: 	-e '    s/.*\( *LaTeX Error:.*\)/$(C_ERROR)\1$(C_RESET)/' \
felix@3266: 	-e '    b end' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  /.*Warning:.*/{' \
felix@3266: 	-e '    s//$(C_WARNING)&$(C_RESET)/' \
felix@3266: 	-e '    b end' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  /Underfull.*/{' \
felix@3266: 	-e '    s/.*\(Underfull.*\)/$(C_UNDERFULL)\1$(C_RESET)/' \
felix@3266: 	-e '    b end' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  /Overfull.*/{' \
felix@3266: 	-e '    s/.*\(Overfull.*\)/$(C_OVERFULL)\1$(C_RESET)/' \
felix@3266: 	-e '    b end' \
felix@3266: 	-e '  }' \
felix@3266: 	$(if $(VERBOSE),,-e '  d') \
felix@3266: 	-e '  :end' \
felix@3266: 	-e '  G' \
felix@3266: 	-e '}' \
felix@3266: 
felix@3266: # Colorize BibTeX output.
felix@3266: color_bib	:= \
felix@3266: 	$(SED) \
felix@3266: 	-e 's/^Warning--.*/$(C_WARNING)&$(C_RESET)/' -e 't' \
felix@3266: 	-e '/---/,/^.[^:]/{' \
felix@3266: 	-e '  H' \
felix@3266: 	-e '  /^.[^:]/{' \
felix@3266: 	-e '    x' \
felix@3266: 	-e '    s/\n\(.*\)/$(C_ERROR)\1$(C_RESET)/' \
felix@3266: 	-e '	p' \
felix@3266: 	-e '    s/.*//' \
felix@3266: 	-e '    h' \
felix@3266: 	-e '    d' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  d' \
felix@3266: 	-e '}' \
felix@3266: 	-e '/(.*error.*)/s//$(C_ERROR)&$(C_RESET)/' \
felix@3266: 	$(if $(VERBOSE),,-e 'd')
felix@3266: 
felix@3266: 
felix@3266: # Make beamer output big enough to print on a full page.  Landscape doesn't
felix@3266: # seem to work correctly.
felix@3266: enlarge_beamer	= $(PSNUP) -l -1 -W128mm -H96mm -pletter
felix@3266: 
felix@3266: # $(call test-run-again,<source stem>)
felix@3266: test-run-again	= $(EGREP) -q '^(.*Rerun .*|No file $1\.[^.]+\.)$$' $1.log
felix@3266: 
felix@3266: # This tests whether the build target commands should be run at all, from
felix@3266: # viewing the log file.
felix@3266: # $(call test-log-for-need-to-run,<source stem>)
felix@3266: define test-log-for-need-to-run
felix@3266: $(SED) \
felix@3266: -e '/^No file $(call escape-dots,$1)\.aux\./d' \
felix@3266: $1.log \
felix@3266: | $(EGREP) -q '^(.*Rerun .*|No file $1\.[^.]+\.|No file .+\.tex\.|LaTeX Warning: File.*)$$'
felix@3266: endef
felix@3266: 
felix@3266: # LaTeX invocations
felix@3266: #
felix@3266: # $(call latex,<tex file>,[<extra LaTeX args>])
felix@3266: run-latex	= $(latex_build_program) --interaction=batchmode $(if $2,$2,) $1 > /dev/null
felix@3266: 
felix@3266: # $(call latex-color-log,<LaTeX stem>)
felix@3266: latex-color-log	= $(color_tex) $1.log
felix@3266: 
felix@3266: # $(call run-makeindex,<input>,<output>,<log>,<extra flags>)
felix@3266: define run-makeindex
felix@3266: success=1; \
felix@3266: if ! $(MAKEINDEX) -q $1 -t $3 -o $2 $4 > /dev/null || $(EGREP) -q '^!!' $3; then \
felix@3266: 	$(call colorize-makeindex-errors,$3); \
felix@3266: 	$(RM) -f '$2'; \
felix@3266: 	success=0; \
felix@3266: fi; \
felix@3266: [ "$$success" = "1" ] && $(sh_true) || $(sh_false);
felix@3266: endef
felix@3266: 
felix@3266: # This runs the given script to generate output, and it uses MAKE_RESTARTS to
felix@3266: # ensure that it never runs it more than once for a particular root make
felix@3266: # invocation.
felix@3266: #
felix@3266: # $(call run-script,<interpreter>,<input>,<output>)
felix@3266: define run-script
felix@3266: [ ! -e '$2.cookie' ] && $(ECHO) "restarts=$(RESTARTS)" > $2.cookie && $(ECHO) "level=$(MAKELEVEL)" >> $2.cookie; \
felix@3266: restarts=`$(SED) -n -e 's/^restarts=//p' $2.cookie`; \
felix@3266: level=`$(SED) -n -e 's/^level=//p' $2.cookie`; \
felix@3266: if $(EXPR) $(MAKELEVEL) '<=' $$level '&' $(RESTARTS) '<=' $$restarts >/dev/null; then \
felix@3266: 	$(call echo-build,$2,$3,$(RESTARTS)-$(MAKELEVEL)); \
felix@3266: 	$1 '$2' '$3'; \
felix@3266: 	$(ECHO) "restarts=$(RESTARTS)" > '$2.cookie'; \
felix@3266: 	$(ECHO) "level=$(MAKELEVEL)" >> '$2.cookie'; \
felix@3266: fi
felix@3266: endef
felix@3266: 
felix@3266: # BibTeX invocations
felix@3266: #
felix@3266: # $(call run-bibtex,<tex stem>)
felix@3266: run-bibtex	= $(BIBTEX) $1 | $(color_bib)
felix@3266: 
felix@3266: 
felix@3266: # $(call convert-eps-to-pdf,<eps file>,<pdf file>,[gray])
felix@3266: # Note that we don't use the --filter flag because it has trouble with bounding boxes that way.
felix@3266: define convert-eps-to-pdf
felix@3266: $(if $3,$(CAT) '$1' | $(call kill-ps-color) > '$1.cookie',$(CP) '$1' '$1.cookie'); \
felix@3266: $(EPSTOPDF) '$1.cookie' --outfile='$2' > $1.log; \
felix@3266: $(call colorize-epstopdf-errors,$1.log);
felix@3266: endef
felix@3266: 
felix@3266: # $(call convert-gpi,<gpi file>,<output file>,[gray])
felix@3266: #
felix@3266: define convert-gpi
felix@3266: $(ECHO) 'set terminal $(if $(filter %.pdf,$2),pdf enhanced,postscript enhanced eps)' \
felix@3266: $(if $(filter %.pdf,$2),fsize ,)$(call get-default,$(strip \
felix@3266: $(firstword \
felix@3266: 	$(shell \
felix@3266: 		$(SED) \
felix@3266: 			-e 's/^\#\#FONTSIZE=\([[:digit:]]\{1,\}\)/\1/p' \
felix@3266: 			-e 'd' \
felix@3266: 			$1 $(strip $(gpi_global)) \
felix@3266: 	) \
felix@3266: ) \
felix@3266: ),$(if $(filter %.pdf,$2),$(DEFAULT_GPI_PDF_FONTSIZE),$(DEFAULT_GPI_EPS_FONTSIZE))) \
felix@3266: $(strip $(if $3,monochrome,$(if \
felix@3266: $(shell $(EGREP) '^\#\#[[:space:]]*GRAY[[:space:]]*$$' $< $(gpi_global)),\
felix@3266: ,color))) > $1head.make; \
felix@3266: $(ECHO) 'set output "$2"' >> $1head.make; \
felix@3266: $(if $(gpi_global),$(CAT) $(gpi_global) >> $1head.make;,) \
felix@3266: fnames='$1head.make $1';\
felix@3266: $(if $(gpi_sed),\
felix@3266: 	$(SED) -f '$(gpi_sed)' $$fnames > $1.temp.make; \
felix@3266: 	fnames=$1.temp.make;,\
felix@3266: ) \
felix@3266: success=1; \
felix@3266: if ! $(GNUPLOT) $$fnames 2>$1.log; then \
felix@3266: 	$(call colorize-gnuplot-errors,$1.log); \
felix@3266: 	success=0; \
felix@3266: fi; \
felix@3266: $(if $(gpi_sed),$(call remove-temporary-files,$1.temp.make);,) \
felix@3266: $(call remove-temporary-files,$1head.make); \
felix@3266: [ "$$success" = "1" ] && $(sh_true) || $(sh_false);
felix@3266: endef
felix@3266: 
felix@3266: # Creation of .eps files from .png files
felix@3266: #
felix@3266: # The intermediate step of PNM (using NetPBM) produces much nicer output than
felix@3266: # ImageMagick's "convert" binary.  I couldn't get the right combination of
felix@3266: # flags to make it look nice, anyway.
felix@3266: #
felix@3266: # To handle gray scale conversion, we pipe things through ppmtopgm in the
felix@3266: # middle.
felix@3266: #
felix@3266: # $(call convert-png,<png file>,<eps file>)
felix@3266: define convert-png
felix@3266: $(PNGTOPNM) "$1" \
felix@3266: 	$(if $3,| $(PPMTOPGM),) \
felix@3266: 	| $(PNMTOPS) -noturn \
felix@3266: 	> "$2"
felix@3266: endef
felix@3266: 
felix@3266: # Creation of .eps files from .jpg files
felix@3266: #
felix@3266: # Thanks to brubakee for this solution.
felix@3266: #
felix@3266: # Uses Postscript level 2 to avoid file size bloat
felix@3266: # $(call convert-jpg,<jpg file>,<eps file>)
felix@3266: define convert-jpg
felix@3266: $(CONVERT) $(if $3,-type Grayscale,) '$1' eps2:'$2'
felix@3266: endef
felix@3266: 
felix@3266: # Creation of .eps files from .fig files
felix@3266: # $(call convert-fig,<fig file>,<output file>,[gray])
felix@3266: convert-fig	= $(FIG2DEV) -L $(if $(filter %.pdf,$2),pdf,eps) $(if $3,-N,) $1 $2
felix@3266: 
felix@3266: # Creation of .pstex files from .fig files
felix@3266: # $(call convert-fig-pstex,<fig file>,<pstex file>)
felix@3266: convert-fig-pstex	= $(FIG2DEV) -L pstex $1 $2 > /dev/null 2>&1
felix@3266: 
felix@3266: # Creation of .pstex_t files from .fig files
felix@3266: # $(call convert-fig-pstex-t,<fig file>,<pstex file>,<pstex_t file>)
felix@3266: convert-fig-pstex-t	= $(FIG2DEV) -L pstex_t -p $3 $1 $2 > /dev/null 2>&1
felix@3266: 
felix@3266: # Creation of .dot_t files from .dot files
felix@3266: # #(call convert-dot-tex,<dot file>,<dot_t file>)
felix@3266: convert-dot-tex		= $(DOT2TEX) '$1' > '$2'
felix@3266: 
felix@3266: # Converts svg files into .eps files
felix@3266: #
felix@3266: # $(call convert-svg,<svg file>,<eps file>,[gray])
felix@3266: convert-svg	= $(INKSCAPE) --export-eps='$2' '$1'
felix@3266: 
felix@3266: # Converts xvg files into .eps files
felix@3266: #
felix@3266: # $(call convert-xvg,<xvg file>,<eps file>,[gray])
felix@3266: convert-xvg	= $(XMGRACE) '$1' -printfile - -hardcopy -hdevice $(if $3,-mono,) EPS > '$2'
felix@3266: 
felix@3266: # Converts .eps.gz files into .eps files
felix@3266: #
felix@3266: # $(call convert-epsgz,<eps.gz file>,<eps file>,[gray])
felix@3266: convert-epsgz	= $(GUNZIP) -c '$1' $(if $3,| $(call kill-ps-color)) > '$2'
felix@3266: 
felix@3266: # Converts .eps files into .eps files (usually a no-op, but can make grayscale)
felix@3266: #
felix@3266: # $(call convert-eps,<in file>,<out file>,[gray])
felix@3266: convert-eps	= $(if $3,$(call kill-ps-color) $1 > $2)
felix@3266: 
felix@3266: # The name of the file containing special postscript commands for grayscale
felix@3266: gray_eps_file	:= gray.eps.make
felix@3266: 
felix@3266: # Changes sethsbcolor and setrgbcolor calls in postscript to always produce
felix@3266: # grayscale.  In general, this is accomplished by writing new versions of those
felix@3266: # functions into the user dictionary space, which is looked up before the
felix@3266: # global or system dictionaries (userdict is one of the permanent dictionaries
felix@3266: # in postscript and is not read-only like systemdict).
felix@3266: #
felix@3266: # For setrgbcolor, the weighted average of the triple is computed and the
felix@3266: # triple is replaced with three copies of that average before the original
felix@3266: # procedure is called: .299R + .587G + .114B
felix@3266: #
felix@3266: # For sethsbcolor, the color is first converted to RGB, then to grayscale by
felix@3266: # the new setrgbcolor operator as described above.  Why is this done?
felix@3266: # Because simply using the value component will tend to make pure colors
felix@3266: # white, a very undesirable thing.  Pure blue should not translate to white,
felix@3266: # but to some level of gray.  Conversion to RGB does the right thing.  It's
felix@3266: # messy, but it works.
felix@3266: #
felix@3266: # From
felix@3266: # http://en.wikipedia.org/wiki/HSV_color_space#Transformation_from_HSV_to_RGB,
felix@3266: # HSB = HSV (Value = Brightness), and the formula used to convert to RGB is
felix@3266: # as follows:
felix@3266: #
felix@3266: # Hi = int(floor(6 * H)) mod 6
felix@3266: # f = 6 * H - Hi
felix@3266: # p = V(1-S)
felix@3266: # q = V(1-fS)
felix@3266: # t = V(1-(1-f)S)
felix@3266: # if Hi = 0: R G B <-- V t p
felix@3266: # if Hi = 1: R G B <-- q V p
felix@3266: # if Hi = 2: R G B <-- p V t
felix@3266: # if Hi = 3: R G B <-- p q V
felix@3266: # if Hi = 4: R G B <-- t p V
felix@3266: # if Hi = 5: R G B <-- V p q
felix@3266: #
felix@3266: # The messy stack-based implementation is below
felix@3266: # $(call create-gray-eps-file,filename)
felix@3266: define create-gray-eps-file
felix@3266: $(ECHO) -n -e '\
felix@3266: /OLDRGB /setrgbcolor load def\n\
felix@3266: /setrgbcolor {\n\
felix@3266:     .114 mul exch\n\
felix@3266:     .587 mul add exch\n\
felix@3266:     .299 mul add\n\
felix@3266:     dup dup\n\
felix@3266:     OLDRGB\n\
felix@3266: } bind def\n\
felix@3266: /OLDHSB /sethsbcolor load def\n\
felix@3266: /sethsbcolor {\n\
felix@3266:     2 index                     % H V S H\n\
felix@3266:     6 mul floor cvi 6 mod       % Hi V S H\n\
felix@3266:     3 index                     % H Hi V S H\n\
felix@3266:     6 mul                       % 6H Hi V S H\n\
felix@3266:     1 index                     % Hi 6H Hi V S H\n\
felix@3266:     sub                         % f Hi V S H\n\
felix@3266:     2 index 1                   % 1 V f Hi V S H\n\
felix@3266:     4 index                     % S 1 V f Hi V S H\n\
felix@3266:     sub mul                     % p f Hi V S H\n\
felix@3266:     3 index 1                   % 1 V p f Hi V S H\n\
felix@3266:     6 index                     % S 1 V p f Hi V S H\n\
felix@3266:     4 index                     % f S 1 V p f Hi V S H\n\
felix@3266:     mul sub mul                 % q p f Hi V S H\n\
felix@3266:     4 index 1 1                 % 1 1 V q p f Hi V S H\n\
felix@3266:     5 index                     % f 1 1 V q p f Hi V S H\n\
felix@3266:     sub                         % (1-f) 1 V q p f Hi V S H\n\
felix@3266:     8 index                     % S (1-f) 1 V q p f Hi V S H\n\
felix@3266:     mul sub mul                 % t q p f Hi V S H\n\
felix@3266:     4 -1 roll pop               % t q p Hi V S H\n\
felix@3266:     7 -2 roll pop pop           % t q p Hi V\n\
felix@3266:     5 -2 roll                   % Hi V t q p\n\
felix@3266:     dup 0 eq\n\
felix@3266:     {1 index 3 index 6 index}\n\
felix@3266:     {\n\
felix@3266:         dup 1 eq\n\
felix@3266:         {3 index 2 index 6 index}\n\
felix@3266:         {\n\
felix@3266:             dup 2 eq\n\
felix@3266:             {4 index 2 index 4 index}\n\
felix@3266:             {\n\
felix@3266:                 dup 3 eq\n\
felix@3266:                 {4 index 4 index 3 index}\n\
felix@3266:                 {\n\
felix@3266:                     dup 4 eq\n\
felix@3266:                     {2 index 5 index 3 index}\n\
felix@3266:                     {\n\
felix@3266:                         dup 5 eq\n\
felix@3266:                         {1 index 5 index 5 index}\n\
felix@3266:                         {0 0 0}\n\
felix@3266:                         ifelse\n\
felix@3266:                     }\n\
felix@3266:                     ifelse\n\
felix@3266:                 }\n\
felix@3266:                 ifelse\n\
felix@3266:             }\n\
felix@3266:             ifelse\n\
felix@3266:         }\n\
felix@3266:         ifelse\n\
felix@3266:     }\n\
felix@3266:     ifelse                      % B G R Hi V t q p\n\
felix@3266:     setrgbcolor\n\
felix@3266:     5 {pop} repeat\n\
felix@3266: } bind def\n'\
felix@3266: > $1
felix@3266: endef
felix@3266: 
felix@3266: # This actually inserts the color-killing code into a postscript file
felix@3266: # $(call kill-ps-color)
felix@3266: define kill-ps-color
felix@3266: $(SED) -e '/%%EndComments/r $(gray_eps_file)'
felix@3266: endef
felix@3266: 
felix@3266: # Converts graphviz .dot files into .eps files
felix@3266: # Grayscale is not directly supported by dot, so we pipe it through fig2dev in
felix@3266: # that case.
felix@3266: # $(call convert-dot,<dot file>,<eps file>,<log file>,[gray])
felix@3266: define convert-dot
felix@3266: $(DOT) -Tps '$1' 2>'$3' $(if $4,| $(call kill-ps-color)) > $2; \
felix@3266: $(call colorize-dot-errors,$3)
felix@3266: endef
felix@3266: 
felix@3266: # Convert DVI to Postscript
felix@3266: # $(call make-ps,<dvi file>,<ps file>,<log file>,[<paper size>])
felix@3266: make-ps		= \
felix@3266: 	$(DVIPS) -o '$2' $(if $(filter-out BEAMER,$4),-t$(firstword $4),) '$1' \
felix@3266: 		$(if $(filter BEAMER,$4),| $(enlarge_beamer)) > $3 2>&1
felix@3266: 
felix@3266: # Convert Postscript to PDF
felix@3266: # $(call make-pdf,<ps file>,<pdf file>,<log file>,<embed file>)
felix@3266: make-pdf	= \
felix@3266: 	$(call ps2pdf,$1,$2,$(filter 1,$(shell $(CAT) '$4'))) > '$3' 2>&1
felix@3266: 
felix@3266: # Display information about what is being done
felix@3266: # $(call echo-build,<input file>,<output file>,[<run number>])
felix@3266: echo-build	= $(ECHO) "$(C_BUILD)= $1 --> $2$(if $3, ($3),) =$(C_RESET)"
felix@3266: echo-graphic	= $(ECHO) "$(C_GRAPHIC)= $1 --> $2 =$(C_RESET)"
felix@3266: echo-dep	= $(ECHO) "$(C_DEP)= $1 --> $2 =$(C_RESET)"
felix@3266: 
felix@3266: # Display a list of something
felix@3266: # $(call echo-list,<values>)
felix@3266: echo-list	= for x in $1; do $(ECHO) "$$x"; done
felix@3266: 
felix@3266: #
felix@3266: # DEFAULT TARGET
felix@3266: #
felix@3266: 
felix@3266: .PHONY: all
felix@3266: all: $(default_pdf_targets) ;
felix@3266: 
felix@3266: .PHONY: all-pdf
felix@3266: all-pdf: $(default_pdf_targets) ;
felix@3266: 
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: .PHONY: all-ps
felix@3266: all-ps: $(default_ps_targets) ;
felix@3266: 
felix@3266: .PHONY: all-dvi
felix@3266: all-dvi: $(default_dvi_targets) ;
felix@3266: endif
felix@3266: 
felix@3266: #
felix@3266: # VIEWING TARGET
felix@3266: #
felix@3266: .PHONY: show
felix@3266: show: all
felix@3266: 	$(QUIET)for x in $(default_pdf_targets); do \
felix@3266: 		[ -e "$$x" ] && $(VIEW_PDF) $$x & \
felix@3266: 	done
felix@3266: 
felix@3266: #
felix@3266: # INCLUDES
felix@3266: #
felix@3266: source_includes	:= $(addsuffix .d,$(source_stems_to_include))
felix@3266: graphic_includes := $(addsuffix .gpi.d,$(graphic_stems_to_include))
felix@3266: 
felix@3266: # Include only the dependencies used
felix@3266: ifneq "" "$(source_includes)"
felix@3266: include $(source_includes)$(call include-message,$(source_includes))
felix@3266: endif
felix@3266: ifneq "" "$(graphic_includes)"
felix@3266: include $(graphic_includes)$(call include-message,$(graphic_includes))
felix@3266: endif
felix@3266: 
felix@3266: #
felix@3266: # MAIN TARGETS
felix@3266: #
felix@3266: 
felix@3266: # Note that we don't just say %: %.pdf here - this can tend to mess up our
felix@3266: # includes, which detect what kind of file we are asking for.  For example,
felix@3266: # asking to build foo.pdf is much different than asking to build foo when
felix@3266: # foo.gpi exists, because we look through all of the goals for *.pdf that
felix@3266: # matches *.gpi, then use that to determine which include files we need to
felix@3266: # build.
felix@3266: #
felix@3266: # Thus, we invoke make recursively with better arugments instead, restarting
felix@3266: # all of the appropriate machinery.
felix@3266: .PHONY: $(default_stems_ss)
felix@3266: $(default_stems_ss): %: %.pdf ;
felix@3266: 
felix@3266: # This builds and displays the wanted file.
felix@3266: .PHONY: $(addsuffix ._show,$(stems_ssg))
felix@3266: %._show: %.pdf
felix@3266: 	$(QUIET)$(VIEW_PDF) $< &
felix@3266: 
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: .SECONDARY: $(all_pdf_targets)
felix@3266: %.pdf: %.ps %.embed.make
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call make-pdf,$<,$@.temp,$@.log,$*.embed.make); \
felix@3266: 	if [ x"$$?" = x"0" ]; then \
felix@3266: 	    $(if $(VERBOSE),$(CAT) $@.log,:); \
felix@3266: 	    $(RM) -f '$@'; \
felix@3266: 	    $(MV) '$@.temp' '$@'; \
felix@3266: 	    $(TOUCH) '$@'; \
felix@3266: 	    $(call copy-with-logging,$@,$(BINARY_TARGET_DIR)); \
felix@3266: 	else \
felix@3266: 	    $(CAT) $@.log; \
felix@3266: 	    $(call remove-temporary-files,'$@.temp'); \
felix@3266: 	    $(sh_false); \
felix@3266: 	fi
felix@3266: 
felix@3266: .SECONDARY: $(all_ps_targets)
felix@3266: %.ps: %.dvi %.paper.make
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call make-ps,$<,$@.temp,$@.log,\
felix@3266: 			$(firstword $(shell $(CAT) $*.paper.make))); \
felix@3266: 	if [ x"$$?" = x"0" ]; then \
felix@3266: 	    $(if $(VERBOSE),$(CAT) $@.log,:); \
felix@3266: 	    $(RM) -f '$@'; \
felix@3266: 	    $(MV) '$@.temp' '$@'; \
felix@3266: 	    $(TOUCH) '$@'; \
felix@3266: 	    $(call copy-with-logging,$@,$(BINARY_TARGET_DIR)); \
felix@3266: 	else \
felix@3266: 	    $(CAT) $@.log; \
felix@3266: 	    $(call remove-temporary-files,'$@.temp'); \
felix@3266: 	    $(sh_false); \
felix@3266: 	fi
felix@3266: endif
felix@3266: 
felix@3266: # Build the final target (dvi or pdf) file.  This is a very tricky rule because
felix@3266: # of the way that latex runs multiple times, needs graphics after the first run
felix@3266: # (or maybe already has them), and relies on bibliographies or indices that may
felix@3266: # not exist.
felix@3266: #
felix@3266: #	Check the log for fatal errors.  If they exist, colorize and bail.
felix@3266: #
felix@3266: #	Create the .auxtarget.cookie file.  (Needed for next time if not present)
felix@3266: #
felix@3266: #	If any of the following are true, we must rebuild at least one time:
felix@3266: #
felix@3266: #	* the .bbl was recently rebuilt
felix@3266: #
felix@3266: #		check a cookie, then delete it
felix@3266: #
felix@3266: #	* any of several output files was created or changed:
felix@3266: #
felix@3266: #		check $*.run.cookie, then delete it
felix@3266: #
felix@3266: #	* the .aux file changed in a way that necessitates attention
felix@3266: #
felix@3266: #		Note that if the .auxtarget.make file doesn't exist, this means
felix@3266: #		that we are doing a clean build, so it doesn't figure into the
felix@3266: #		test for running again.
felix@3266: #
felix@3266: #		compare against .auxtarget.make
felix@3266: #
felix@3266: #		move if different, remove if not
felix@3266: #
felix@3266: #	* the .log file has errors or warnings requiring at least one more run
felix@3266: #
felix@3266: #	We use a loop over a single item to simplify the process of breaking
felix@3266: #	out when we find one of the conditions to be true.
felix@3266: #
felix@3266: #	If we do NOT need to run latex here, then we move the $@.1st.make file
felix@3266: #	over to $@ because the target file has already been built by the first
felix@3266: #	dependency run and is valid.
felix@3266: #
felix@3266: #	If we do, we delete that cookie file and do the normal multiple-runs
felix@3266: #	routine.
felix@3266: #
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: .SECONDARY: $(all_dvi_targets)
felix@3266: endif
felix@3266: %.$(build_target_extension): %.bbl %.aux %.$(build_target_extension).1st.make
felix@3266: 	$(QUIET)\
felix@3266: 	fatal=`$(call colorize-latex-errors,$*.log)`; \
felix@3266: 	if [ x"$$fatal" != x"" ]; then \
felix@3266: 		$(ECHO) "$$fatal"; \
felix@3266: 		exit 1; \
felix@3266: 	fi; \
felix@3266: 	$(call make-auxtarget-file,$*.aux.make,$*.auxtarget.cookie); \
felix@3266: 	run=0; \
felix@3266: 	for i in 1; do \
felix@3266: 		if $(call test-exists,$*.bbl.cookie); then \
felix@3266: 			run=1; \
felix@3266: 			break; \
felix@3266: 		fi; \
felix@3266: 		if $(call test-exists,$*.run.cookie); then \
felix@3266: 			run=1; \
felix@3266: 		    	break; \
felix@3266: 		fi; \
felix@3266: 		if $(call \
felix@3266: 		test-exists-and-different,$*.auxtarget.cookie,$*.auxtarget.make);\
felix@3266: 		then \
felix@3266: 			run=1; \
felix@3266: 			break; \
felix@3266: 		fi; \
felix@3266: 		if $(call test-log-for-need-to-run,$*); then \
felix@3266: 			run=1; \
felix@3266: 			break; \
felix@3266: 		fi; \
felix@3266: 	done; \
felix@3266: 	$(call remove-temporary-files,$*.bbl.cookie $*.run.cookie); \
felix@3266: 	$(MV) $*.auxtarget.cookie $*.auxtarget.make; \
felix@3266: 	if [ x"$$run" = x"1" ]; then \
felix@3266: 		$(call remove-files,$@.1st.make); \
felix@3266: 		for i in 2 3 4 5; do \
felix@3266: 			$(if $(findstring 3.79,$(MAKE_VERSION)),\
felix@3266: 				$(call echo-build,$*.tex,$@,$(RESTARTS)-$$$$i),\
felix@3266: 				$(call echo-build,$*.tex,$@,$(RESTARTS)-$$i)\
felix@3266: 			); \
felix@3266: 			$(call run-latex,$*); \
felix@3266: 			$(CP) '$*.log' '$*.'$(RESTARTS)-$$i'.log'; \
felix@3266: 			$(call test-run-again,$*) || break; \
felix@3266: 		done; \
felix@3266: 	else \
felix@3266: 		$(MV) '$@.1st.make' '$@'; \
felix@3266: 	fi; \
felix@3266: 	$(call copy-with-logging,$@,$(BINARY_TARGET_DIR)); \
felix@3266: 	$(call latex-color-log,$*)
felix@3266: 
felix@3266: # Build the .bbl file.  When dependencies are included, this will (or will
felix@3266: # not!) depend on something.bib, which we detect, acting accordingly.  The
felix@3266: # dependency creation also produces the %.auxbbl.make file.  BibTeX is a bit
felix@3266: # finicky about what you call the actual files, but we can rest assured that if
felix@3266: # a .auxbbl.make file exists, then the .aux file does, as well.  The
felix@3266: # .auxbbl.make file is a cookie indicating whether the .bbl needs to be
felix@3266: # rewritten.  It only changes if the .aux file changes in ways relevant to .bbl
felix@3266: # creation.
felix@3266: #
felix@3266: # Note that we do NOT touch the .bbl file if there is no need to
felix@3266: # create/recreate it.  We would like to leave existing files alone if they
felix@3266: # don't need to be changed, thus possibly avoiding a rebuild trigger.
felix@3266: %.bbl: %.auxbbl.make
felix@3266: 	$(QUIET)\
felix@3266: 	$(if $(filter %.bib,$^),\
felix@3266: 		$(call echo-build,$(filter %.bib,$?) $*.aux,$@); \
felix@3266: 		$(call run-bibtex,$*); \
felix@3266: 		$(TOUCH) $@.cookie; \
felix@3266: 	) \
felix@3266: 	if $(EGREP) -q 'bibstyle.(apacann|chcagoa|[^}]*annot)' '$*.aux'; then \
felix@3266: 		$(call echo-build,** annotated extra latex **,output ignored,$(RESTARTS)-1); \
felix@3266: 		$(call run-latex,$*); \
felix@3266: 		$(CP) '$*.log' '$*.$(RESTARTS)-annotated.log'; \
felix@3266: 		$(if $(filter %.bib,$^),\
felix@3266: 			$(call echo-build,** annotated extra bibtex ** $(filter %.bib,$?) $*.aux,$@); \
felix@3266: 			$(call run-bibtex,$*); \
felix@3266: 			$(TOUCH) $@.cookie; \
felix@3266: 		) \
felix@3266: 		$(call echo-build,** annotated extra latex **,output ignored,$(RESTARTS)-2); \
felix@3266: 		$(call run-latex,$*); \
felix@3266: 	fi
felix@3266: 
felix@3266: # Create the index file - note that we do *not* depend on %.tex here, since
felix@3266: # that unnecessarily restricts the kinds of indices that we can build to those
felix@3266: # with exactly the same stem as the source file.  Things like splitidx create
felix@3266: # idx files with other names.
felix@3266: #
felix@3266: # Therefore, we add the .tex dependency in the sourcestem.d file in the call to
felix@3266: # get index file dependencies from the logs.
felix@3266: %.ind:	%.idx
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call run-makeindex,$<,$@,$*.ilg)
felix@3266: 
felix@3266: # Create the glossary file
felix@3266: %.gls:	%.glo %.tex
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call run-makeindex,$<,$@,$*.glg,-s nomencl.ist)
felix@3266: 
felix@3266: # Create the nomenclature file
felix@3266: %.nls:	%.nlo %.tex
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call run-makeindex,$<,$@,$*.nlg,-s nomencl.ist)
felix@3266: 
felix@3266: # SCRIPTED LaTeX TARGETS
felix@3266: #
felix@3266: # Keep the generated .tex files around for debugging if needed.
felix@3266: .SECONDARY: $(all_tex_targets)
felix@3266: 
felix@3266: %.tex::	%.tex.sh
felix@3266: 	$(QUIET)$(call run-script,$(SHELL),$<,$@)
felix@3266: 
felix@3266: %.tex::	%.tex.py
felix@3266: 	$(QUIET)$(call run-script,$(PYTHON),$<,$@)
felix@3266: 
felix@3266: %.tex::	%.tex.pl
felix@3266: 	$(QUIET)$(call run-script,$(PERL),$<,$@)
felix@3266: 
felix@3266: %.tex::	%.rst $(RST_STYLE_FILE)
felix@3266: 	$(QUIET)\
felix@3266: 	$(call run-script,$(RST2LATEX)\
felix@3266: 		--documentoptions=letterpaper\
felix@3266: 		$(if $(RST_STYLE_FILE),--stylesheet=$(RST_STYLE_FILE),),$<,$@)
felix@3266: 
felix@3266: #
felix@3266: # GRAPHICS TARGETS
felix@3266: #
felix@3266: .PHONY: all-graphics
felix@3266: all-graphics:	$(all_graphics_targets);
felix@3266: 
felix@3266: ifneq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: .PHONY: all-pstex
felix@3266: all-pstex:	$(all_pstex_targets);
felix@3266: endif
felix@3266: 
felix@3266: .PHONY: all-dot2tex
felix@3266: all-dot2tex:	$(all_dot2tex_targets);
felix@3266: 
felix@3266: .PHONY: show-graphics
felix@3266: show-graphics: all-graphics
felix@3266: 	$(VIEW_GRAPHICS) $(all_known_graphics)
felix@3266: 
felix@3266: $(gray_eps_file):
felix@3266: 	$(QUIET)$(call echo-build,$^,$@)
felix@3266: 	$(QUIET)$(call create-gray-eps-file,$@)
felix@3266: 
felix@3266: ifeq "$(strip $(BUILD_STRATEGY))" "pdflatex"
felix@3266: %.pdf: %.eps $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-eps-to-pdf,$<,$@,$(GRAY))
felix@3266: 
felix@3266: ifeq "$(strip $(GNUPLOT_OUTPUT_EXTENSION))" "pdf"
felix@3266: %.pdf:	%.gpi %.gpi.d $(gpi_sed)
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-gpi,$<,$@,$(GRAY))
felix@3266: endif
felix@3266: 
felix@3266: %.pdf:	%.fig
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-fig,$<,$@,$(GRAY))
felix@3266: 
felix@3266: endif
felix@3266: 
felix@3266: %.eps:	%.gpi %.gpi.d $(gpi_sed)
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-gpi,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.fig
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-fig,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.dot $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-dot,$<,$@,$<.log,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.xvg $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-xvg,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.svg $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-svg,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.jpg $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-jpg,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.png $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-png,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.eps: %.eps.gz $(if $(GRAY),$(gray_eps_file))
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-epsgz,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.pstex: %.fig
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-fig-pstex,$<,$@,$(GRAY))
felix@3266: 
felix@3266: %.pstex_t: %.fig %.pstex
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-fig-pstex-t,$<,$@,$*.pstex,$(GRAY))
felix@3266: 
felix@3266: %.dot_t: %.dot
felix@3266: 	$(QUIET)$(call echo-graphic,$^,$@)
felix@3266: 	$(QUIET)$(call convert-dot-tex,$<,$@)
felix@3266: 
felix@3266: #
felix@3266: # DEPENDENCY-RELATED TARGETS.
felix@3266: #
felix@3266: 
felix@3266: # Generate all of the information needed to get dependencies
felix@3266: # As a side effect, this creates a .dvi or .pdf file (depending on the build
felix@3266: # strategy).  We need to be sure to remove it if there are errors.  Errors can
felix@3266: # take several forms and all of them are found within the log file:
felix@3266: #	* There was a LaTeX error
felix@3266: #	* A needed file was not found
felix@3266: #	* Cross references need adjustment
felix@3266: #
felix@3266: # Behavior:
felix@3266: #	This rule is responsible for generating the following:
felix@3266: #	%.aux
felix@3266: #	%.d
felix@3266: #	%.aux.make
felix@3266: #	%.(pdf|dvi).1st.make (the .pdf or .dvi output file, moved)
felix@3266: #
felix@3266: #	Steps:
felix@3266: #
felix@3266: #	Run latex
felix@3266: #	Move .pdf or .dvi somewhere else (make no judgements about success)
felix@3266: #	Flatten the .aux file into another file
felix@3266: #	Add source dependencies
felix@3266: #	Add graphic dependencies
felix@3266: #	Add bib dependencies
felix@3266: #
felix@3266: #	Create cookies for various suffixes that may represent files that
felix@3266: #	need to be read by LaTeX in order for it to function properly.
felix@3266: #
felix@3266: #	Note that if some of the dependencies are discovered because they turn
felix@3266: #	up missing in the log file, we really need the .d file to be reloaded.
felix@3266: #	Adding a sleep command helps with this.  Otherwise make is extremely
felix@3266: #	nondeterministic, sometimes working, sometimes not.
felix@3266: #
felix@3266: #	Usually we can force this by simply removing the generated pdf file and
felix@3266: #	not creating a .1st.make file..
felix@3266: #
felix@3266: %.$(build_target_extension).1st.make %.d %.aux %.aux.make %.fls: %.tex
felix@3266: 	$(QUIET)$(call echo-build,$<,$*.d $*.$(build_target_extension).1st.make,$(RESTARTS)-1)
felix@3266: 	$(QUIET)\
felix@3266: 	$(call run-latex,$<,--recorder) || $(sh_true); \
felix@3266: 	$(CP) '$*.log' '$*.$(RESTARTS)-1.log'; \
felix@3266: 	$(call die-on-dot2tex,$*.log); \
felix@3266: 	$(call die-on-no-aux,$*); \
felix@3266: 	$(call flatten-aux,$*.aux,$*.aux.make); \
felix@3266: 	$(ECHO) "# vim: ft=make" > $*.d; \
felix@3266: 	$(ECHO) ".PHONY: $*._graphics" >> $*.d; \
felix@3266: 	$(call get-inputs,$*.fls,$(addprefix $*.,aux aux.make d $(build_target_extension))) >> $*.d; \
felix@3266: 	$(call get-missing-inputs,$*.log,$(addprefix $*.,aux aux.make d $(build_target_extension))) >> $*.d; \
felix@3266: 	$(ECHO) ".SECONDEXPANSION:" >> $*.d; \
felix@3266: 	$(call get-graphics,$*) >> $*.d; \
felix@3266: 	$(call get-log-index,$*,$(addprefix $*.,d aux aux.make)) >> $*.d; \
felix@3266: 	$(call get-bibs,$*.aux.make,$(addprefix $*.,bbl aux aux.make)) >> $*.d; \
felix@3266: 	$(EGREP) -q "# MISSING" $*.d && $(SLEEP) 1 && $(RM) $*.pdf; \
felix@3266: 	$(call move-if-exists,$*.$(build_target_extension),$*.$(build_target_extension).1st.make); \
felix@3266: 	for s in toc out lot lof lol nav; do \
felix@3266: 		if [ -e "$*.$$s" ]; then \
felix@3266: 			if ! $(DIFF) -q $*.$$s $*.$$s.make >/dev/null 2>&1; then \
felix@3266: 				$(TOUCH) $*.run.cookie; \
felix@3266: 			fi; \
felix@3266: 			$(CP) $*.$$s $*.$$s.make; \
felix@3266: 		fi; \
felix@3266: 	done
felix@3266: 
felix@3266: # This is a cookie that is updated if the flattened aux file has changed in a
felix@3266: # way that affects the bibliography generation.
felix@3266: .SECONDARY: $(addsuffix .auxbbl.make,$(stems_ssg))
felix@3266: %.auxbbl.make: %.aux.make
felix@3266: 	$(QUIET)\
felix@3266: 	$(call make-auxbbl-file,$<,$@.temp); \
felix@3266: 	$(call replace-if-different-and-remove,$@.temp,$@)
felix@3266: 
felix@3266: # Build a dependency file for .gpi files.  These often plot data files that
felix@3266: # also reside in the directory, so if a data file changes, it's nice to know
felix@3266: # about it.  This also handles loaded .gpi files, whose filename should have
felix@3266: # _include_. in it.
felix@3266: %.gpi.d: %.gpi
felix@3266: 	$(QUIET)$(call echo-build,$<,$@)
felix@3266: 	$(QUIET)$(call make-gpi-d,$<,$@)
felix@3266: 
felix@3266: # Store the paper size for this document -- note that if beamer is used we set
felix@3266: # it to the special BEAMER paper size.  We only do this, however, if the
felix@3266: # special comment exists, in which case we enlarge the output with psnup.
felix@3266: #
felix@3266: #	The paper size is extracted from a documentclass attribute.
felix@3266: %.paper.make: %.tex
felix@3266: 	$(QUIET)$(SED) \
felix@3266: 	-e '/\\documentclass/,/}/{' \
felix@3266: 	-e '  s/%.*//' \
felix@3266: 	-e '  H' \
felix@3266: 	-e '  /}/{' \
felix@3266: 	-e '    s/.*//' \
felix@3266: 	-e '    x' \
felix@3266: 	-e '    /\\documentclass/!d' \
felix@3266: 	-e '    s/[\n[:space:]]*//g' \
felix@3266: 	-e '    s/\([,{[]\)\([[:alnum:]]\{1,\}\)paper\([],}]\)/\1%-\2-%\3/g' \
felix@3266: 	-e '    s/\([,{[]\)\(landscape\)\([],}]\)/\1%-\2-%\3/g' \
felix@3266: 	-e '    s/^[^%]*%-//' \
felix@3266: 	-e '    s/-%[^%]*$$//' \
felix@3266: 	-e '    s/-%[^%]%-/ /g' \
felix@3266: 	-e '    p' \
felix@3266: 	-e '  }' \
felix@3266: 	-e '  d' \
felix@3266: 	-e '}' \
felix@3266: 	-e 'd' \
felix@3266: 	$< > $@; \
felix@3266: 	$(EGREP) -q '^[^%]*\\documentclass[^{]*{beamer}' $< && \
felix@3266: 	(\
felix@3266: 		$(EGREP) -q '^%%[[:space:]]*BEAMER[[:space:]]*LARGE$$' $< && \
felix@3266: 		$(ECHO) "BEAMER" > $@ || \
felix@3266: 		: > $@ \
felix@3266: 	) || $(sh_true)
felix@3266: 
felix@3266: # Store embedding instructions for this document using a special comment
felix@3266: %.embed.make: %.tex
felix@3266: 	$(QUIET)$(EGREP) '^%%[[:space:]]*NO[[:space:]]*EMBED[[:space:]]*$$' $< \
felix@3266: 		&& $(ECHO) '' > $@ \
felix@3266: 		|| $(ECHO) '1' > $@;
felix@3266: 
felix@3266: #
felix@3266: # HELPFUL PHONY TARGETS
felix@3266: #
felix@3266: 
felix@3266: .PHONY: _all_programs
felix@3266: _all_programs:
felix@3266: 	$(QUIET)$(ECHO) "== All External Programs Used =="
felix@3266: 	$(QUIET)$(call output-all-programs)
felix@3266: 
felix@3266: .PHONY: _check_programs
felix@3266: _check_programs:
felix@3266: 	$(QUIET)$(ECHO) "== Checking Makefile Dependencies =="; $(ECHO)
felix@3266: 	$(QUIET) \
felix@3266: 	$(ECHO) hi; \
felix@3266: 	allprogs=`\
felix@3266: 	 ($(call output-all-programs)) | \
felix@3266: 	 $(SED) \
felix@3266: 	 -e 's/^[[:space:]]*//' \
felix@3266: 	 -e '/^#/d' \
felix@3266: 	 -e 's/[[:space:]]*#.*//' \
felix@3266: 	 -e '/^=/s/[[:space:]]/_/g' \
felix@3266: 	 -e '/^[[:space:]]*$$/d' \
felix@3266: 	 -e 's/^[^=].*=[[:space:]]*\([^[:space:]]\{1,\}\).*$$/\\1/' \
felix@3266: 	 `; \
felix@3266: 	spaces='                             '; \
felix@3266: 	for p in $${allprogs}; do \
felix@3266: 	case $$p in \
felix@3266: 		=*) $(ECHO); $(ECHO) "$$p";; \
felix@3266: 		*) \
felix@3266: 			$(ECHO) -n "$$p:$$spaces" | $(SED) -e 's/^\(.\{0,20\}\).*$$/\1/'; \
felix@3266: 			loc=`$(WHICH) $$p`; \
felix@3266: 			if [ x"$$?" = x"0" ]; then \
felix@3266: 				$(ECHO) "$(C_SUCCESS)Found:$(C_RESET) $$loc"; \
felix@3266: 			else \
felix@3266: 				$(ECHO) "$(C_FAILURE)Not Found$(C_RESET)"; \
felix@3266: 			fi; \
felix@3266: 			;; \
felix@3266: 	esac; \
felix@3266: 	done
felix@3266: 
felix@3266: .PHONY: _check_gpi_files
felix@3266: _check_gpi_files:
felix@3266: 	$(QUIET)$(ECHO) "== Checking all .gpi files for common errors =="; \
felix@3266: 	$(ECHO); \
felix@3266: 	for f in $(files.gpi); do \
felix@3266: 	result=`$(EGREP) '^([^#]*set terminal |set output )' $$f`; \
felix@3266: 	$(ECHO) -n "$$f: "; \
felix@3266: 	if [ x"$$result" = x"" ]; then \
felix@3266: 		$(ECHO) "$(C_SUCCESS)Okay$(C_RESET)"; \
felix@3266: 	else \
felix@3266: 		$(ECHO) "$(C_FAILURE)Warning: Problematic commands:$(C_RESET)";\
felix@3266: 		$(ECHO) "$(C_ERROR)$$result$(C_RESET)"; \
felix@3266: 	fi; \
felix@3266: 	done; \
felix@3266: 	$(ECHO)
felix@3266: 
felix@3266: .PHONY: _all_stems
felix@3266: _all_stems:
felix@3266: 	$(QUIET)$(ECHO) "== All Stems =="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(default_stems_ss)))
felix@3266: 
felix@3266: .PHONY: _includes
felix@3266: _includes:
felix@3266: 	$(QUIET)$(ECHO) "== Include Stems =="
felix@3266: 	$(QUIET)$(ECHO) "=== Sources ==="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(source_includes)))
felix@3266: 	$(QUIET)$(ECHO) "=== Graphics ==="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(graphic_includes)))
felix@3266: 
felix@3266: .PHONY: _all_sources
felix@3266: _all_sources:
felix@3266: 	$(QUIET)$(ECHO) "== All Sources =="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(all_files.tex)))
felix@3266: 
felix@3266: .PHONY: _dependency_graph
felix@3266: _dependency_graph:
felix@3266: 	$(QUIET)$(ECHO) "/* LaTeX Dependency Graph */"
felix@3266: 	$(QUIET)$(call output-dependency-graph)
felix@3266: 
felix@3266: .PHONY: _show_dependency_graph
felix@3266: _show_dependency_graph:
felix@3266: 	$(QUIET)$(call output-dependency-graph,$(graph_stem).dot)
felix@3266: 	$(QUIET)$(DOT) -Tps -o $(graph_stem).eps $(graph_stem).dot
felix@3266: 	$(QUIET)$(VIEW_POSTSCRIPT) $(graph_stem).eps
felix@3266: 	$(QUIET)$(call remove-temporary-files,$(graph_stem).*)
felix@3266: 
felix@3266: .PHONY: _sources
felix@3266: _sources:
felix@3266: 	$(QUIET)$(ECHO) "== Sources =="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(files.tex)))
felix@3266: 
felix@3266: .PHONY: _scripts
felix@3266: _scripts:
felix@3266: 	$(QUIET)$(ECHO) "== Scripts =="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(files_scripts)))
felix@3266: 
felix@3266: .PHONY: _graphic_outputs
felix@3266: _graphic_outputs:
felix@3266: 	$(QUIET)$(ECHO) "== Graphic Outputs =="
felix@3266: 	$(QUIET)$(call echo-list,$(sort $(all_graphics_targets)))
felix@3266: 
felix@3266: .PHONY: _env
felix@3266: _env:
felix@3266: ifdef .VARIABLES
felix@3266: 	$(QUIET)$(ECHO) "== MAKE VARIABLES =="
felix@3266: 	$(QUIET)$(call echo-list,$(foreach var,$(sort $(.VARIABLES)),'$(var)'))
felix@3266: endif
felix@3266: 	$(QUIET)$(ECHO) "== ENVIRONMENT =="
felix@3266: 	$(QUIET)$(ENV)
felix@3266: 
felix@3266: #
felix@3266: # CLEAN TARGETS
felix@3266: #
felix@3266: # clean-generated is somewhat unique - it relies on the .fls file being
felix@3266: # properly built so that it can determine which of the files was generated, and
felix@3266: # which was not.  Expect it to silently fail if the .fls file is missing.
felix@3266: #
felix@3266: # This is used to, e.g., clean up index files that are generated by the LaTeX.
felix@3266: .PHONY: clean-generated
felix@3266: clean-generated:
felix@3266: 	$(QUIET)$(call clean-files,$(foreach e,$(addsuffix .fls,$(all_stems_source)),\
felix@3266: 						$(shell $(call get-generated-names,$e))))
felix@3266: 
felix@3266: .PHONY: clean-deps
felix@3266: clean-deps:
felix@3266: 	$(QUIET)$(call clean-files,$(all_d_targets) *.make *.make.temp *.cookie)
felix@3266: 
felix@3266: .PHONY: clean-tex
felix@3266: clean-tex: clean-deps
felix@3266: 	$(QUIET)$(call clean-files,$(rm_tex))
felix@3266: 
felix@3266: .PHONY: clean-graphics
felix@3266: # TODO: This *always* deletes pstex files, even if they were not generated by
felix@3266: # anything....  In other words, if you create a pstex and pstex_t pair by hand
felix@3266: # an drop them in here without the generating fig file, they will be deleted
felix@3266: # and you won't get them back.  It's a hack put in here because I'm not sure we
felix@3266: # even want to keep pstex functionality, so my motivation is not terribly high
felix@3266: # for doing it right.
felix@3266: clean-graphics:
felix@3266: 	$(QUIET)$(call clean-files,$(all_graphics_targets) $(intermediate_graphics_targets) *.gpi.d *.pstex *.pstex_t *.dot_t)
felix@3266: 
felix@3266: .PHONY: clean-backups
felix@3266: clean-backups:
felix@3266: 	$(QUIET)$(call clean-files,$(backup_patterns) *.temp)
felix@3266: 
felix@3266: .PHONY: clean-auxiliary
felix@3266: clean-auxiliary:
felix@3266: 	$(QUIET)$(call clean-files,$(graph_stem).*)
felix@3266: 
felix@3266: .PHONY: clean-nographics
felix@3266: clean-nographics: clean-tex clean-deps clean-backups clean-auxiliary ;
felix@3266: 
felix@3266: .PHONY: clean
felix@3266: clean:	clean-generated clean-tex clean-graphics clean-deps clean-backups clean-auxiliary
felix@3266: 
felix@3266: #
felix@3266: # HELP TARGETS
felix@3266: #
felix@3266: 
felix@3266: .PHONY: help
felix@3266: help:
felix@3266: 	$(help_text)
felix@3266: 
felix@3266: .PHONY: version
felix@3266: version:
felix@3266: 	$(QUIET)\
felix@3266: 	$(ECHO) "$(fileinfo) Version $(version)"; \
felix@3266: 	$(ECHO) "by $(author)"; \
felix@3266: 
felix@3266: #
felix@3266: # HELP TEXT
felix@3266: #
felix@3266: 
felix@3266: define help_text
felix@3266: # $(fileinfo) Version $(version)
felix@3266: #
felix@3266: # by $(author)
felix@3266: #
felix@3266: # Generates a number of possible output files from a LaTeX document and its
felix@3266: # various dependencies.  Handles .bib files, \include and \input, and .eps
felix@3266: # graphics.  All dependencies are handled automatically by running LaTeX over
felix@3266: # the source.
felix@3266: #
felix@3266: # USAGE:
felix@3266: #
felix@3266: #    make [GRAY=1] [VERBOSE=1] [SHELL_DEBUG=1] <target(s)>
felix@3266: #
felix@3266: # STANDARD OPTIONS:
felix@3266: #    GRAY:
felix@3266: #        Setting this variable forces all recompiled graphics to be grayscale.
felix@3266: #        It is useful when creating a document for printing.  The default is
felix@3266: #        to allow colors.  Note that it only changes graphics that need to be
felix@3266: #        rebuilt!  It is usually a good idea to do a 'make clean' first.
felix@3266: #
felix@3266: #    VERBOSE:
felix@3266: #        This turns off all @ prefixes for commands invoked by make.  Thus,
felix@3266: #        you get to see all of the gory details of what is going on.
felix@3266: #
felix@3266: #    SHELL_DEBUG:
felix@3266: #        This enables the -x option for sh, meaning that everything it does is
felix@3266: #        echoed to stderr.  This is particularly useful for debugging
felix@3266: #        what is going on in $$(shell ...) invocations.  One of my favorite
felix@3266: #        debugging tricks is to do this:
felix@3266: #
felix@3266: #        make -d SHELL_DEBUG=1 VERBOSE=1 2>&1 | less
felix@3266: #
felix@3266: # STANDARD AUXILIARY FILES:
felix@3266: #
felix@3266: #      Makefile.ini
felix@3266: #
felix@3266: #          This file can contain variable declarations that override various
felix@3266: #          aspects of the makefile.  For example, one might specify
felix@3266: #
felix@3266: #          neverclean := *.pdf *.ps
felix@3266: #          onlysources.tex := main.tex
felix@3266: #          LATEX_COLOR_WARNING := 'bold red uline'
felix@3266: #
felix@3266: #          And this would override the neverclean setting to ensure that pdf
felix@3266: #          and ps files always remain behind, set the makefile to treat all
felix@3266: #          .tex files that are not "main.tex" as includes (and therefore not
felix@3266: #          default targets).  It also changes the LaTeX warning output to be
felix@3266: #          red, bold, and underlined.
felix@3266: #
felix@3266: #          There are numerous variables in this file that can be overridden in
felix@3266: #          this way.  Search for '?=' to find them all.
felix@3266: #
felix@3266: #          Also, you can put arbitrary targets into it if, for example, you
felix@3266: #          want your source built from something else, e.g.:
felix@3266: #
felix@3266: #          generated.tex: generating_script.weird_lang depA depB
felix@3266: #          	./generating_script.weird_lang > $$@
felix@3266: #
felix@3266: #          Note that if you are not careful, you can override the default
felix@3266: #          target (what happens when you type "make" without arguments), so if
felix@3266: #          you do use Makefile.ini, you probably want to start it with
felix@3266: #          something like the following line:
felix@3266: #
felix@3266: #          default: all
felix@3266: #
felix@3266: #          Since the first target in any makefile is automatically the default,
felix@3266: #          and the makefile already has a sensible "all" target, this will do
felix@3266: #          what you want.
felix@3266: #
felix@3266: #          The Makefile.ini is imported before *anything else* is done, so go
felix@3266: #          wild with your ideas for changes to this makefile in there.  It
felix@3266: #          makes it easy to test them before submitting patches.
felix@3266: #
felix@3266: # STANDARD ENVIRONMENT VARIABLES:
felix@3266: #
felix@3266: #      LATEX_COLOR_WARNING		'$(LATEX_COLOR_WARNING)'
felix@3266: #      LATEX_COLOR_ERROR		'$(LATEX_COLOR_ERROR)'
felix@3266: #      LATEX_COLOR_UNDERFULL		'$(LATEX_COLOR_UNDERFULL)'
felix@3266: #      LATEX_COLOR_OVERFULL		'$(LATEX_COLOR_OVERFULL)'
felix@3266: #      LATEX_COLOR_PAGES		'$(LATEX_COLOR_PAGES)'
felix@3266: #      LATEX_COLOR_BUILD		'$(LATEX_COLOR_BUILD)'
felix@3266: #      LATEX_COLOR_GRAPHIC		'$(LATEX_COLOR_GRAPHIC)'
felix@3266: #      LATEX_COLOR_DEP			'$(LATEX_COLOR_DEP)'
felix@3266: #      LATEX_COLOR_SUCCESS		'$(LATEX_COLOR_SUCCESS)'
felix@3266: #      LATEX_COLOR_FAILURE		'$(LATEX_COLOR_FAILURE)'
felix@3266: #
felix@3266: #   These may be redefined in your environment to be any of the following:
felix@3266: #
felix@3266: #      black
felix@3266: #      red
felix@3266: #      green
felix@3266: #      yellow
felix@3266: #      blue
felix@3266: #      magenta
felix@3266: #      cyan
felix@3266: #      white
felix@3266: #
felix@3266: #   Bold or underline may be used, as well, either alone or in combination
felix@3266: #   with colors:
felix@3266: #
felix@3266: #      bold
felix@3266: #      uline
felix@3266: #
felix@3266: #   Order is not important.  You may want, for example, to specify:
felix@3266: #
felix@3266: #   export LATEX_COLOR_SUCCESS='bold blue uline'
felix@3266: #
felix@3266: #   in your .bashrc file.  I don't know why, but you may want to.
felix@3266: #
felix@3266: # STANDARD TARGETS:
felix@3266: #
felix@3266: #    all:
felix@3266: #        Make all possible documents in this directory.  The documents are
felix@3266: #        determined by scanning for .tex and .tex.sh (described in more detail
felix@3266: #        later) and omitting any file that ends in ._include_.tex or
felix@3266: #        ._nobuild_.tex.  The output is a set of .pdf files.
felix@3266: #
felix@3266: #        If you wish to omit files without naming them with the special
felix@3266: #        underscore names, set the following near the top of the Makefile,
felix@3266: #        or (this is recommended) within a Makefile.ini in the same directory:
felix@3266: #
felix@3266: #        	includes.tex := file1.tex file2.tex
felix@3266: #
felix@3266: #        This will cause the files listed to be considered as include files.
felix@3266: #
felix@3266: #        If you have only few source files, you can set
felix@3266: #
felix@3266: #        	onlysources.tex := main.tex
felix@3266: #
felix@3266: #        This will cause only the source files listed to be considered in
felix@3266: #        dependency detection.  All other .tex files will be considered as
felix@3266: #        include files.  Note that these options work for *any* source type,
felix@3266: #        so you could do something similar with includes.gpi, for example.
felix@3266: #        Note that this works for *any valid source* target.  All of the
felix@3266: #        onlysources.* variables are commented out in the shipping version of
felix@3266: #        this file, so it does the right thing when they simply don't exist.
felix@3266: #        The comments are purely documentation.  If you know, for example, that
felix@3266: #        file.mycoolformat is supported by this Makefile, but don't see the
felix@3266: #        "onlysources.mycoolformat" declared in the comments, that doesn't mean
felix@3266: #        you can't use it.  Go ahead and set "onlysources.mycoolformat" and it
felix@3266: #        should do the right thing.
felix@3266: #
felix@3266: #    show:
felix@3266: #        Builds and displays all documents in this directory.  It uses the
felix@3266: #        environment-overridable value of VIEW_PDF (currently $(VIEW_PDF)) to
felix@3266: #        do its work.
felix@3266: #
felix@3266: #    all-graphics:
felix@3266: #        Make all of the graphics in this directory.
felix@3266: #
felix@3266: #    all-pstex (only for BUILD_STRATEGY=latex):
felix@3266: #        Build all fig files into pstex and pstex_t files.  Gray DOES NOT WORK.
felix@3266: #
felix@3266: #    all-gray-pstex (only for BUILD_STRATEGY=latex):
felix@3266: #    	 Build all fig files into grayscale pstex and pstex_t files.
felix@3266: #
felix@3266: #    all-dot2tex:
felix@3266: #    	 Build all dot files into tex files.
felix@3266: #
felix@3266: #    show-graphics:
felix@3266: #        Builds and displays all graphics in this directory.  Uses the
felix@3266: #        environment-overridable value of VIEW_GRAPHICS (currently
felix@3266: #        $(VIEW_GRAPHICS)) to do its work.
felix@3266: #
felix@3266: #    clean:
felix@3266: #        Remove ALL generated files, leaving only source intact.
felix@3266: #        This will *always* skip files mentioned in the "neverclean" variable,
felix@3266: #        either in this file or specified in Makefile.ini:
felix@3266: #
felix@3266: #        	neverclean := *.pdf *.ps
felix@3266: #
felix@3266: #       The neverclean variable works on all "clean" targets below, as well.
felix@3266: #
felix@3266: #    clean-graphics:
felix@3266: #        Remove all generated graphics files.
felix@3266: #
felix@3266: #    clean-backups:
felix@3266: #        Remove all backup files: $(backup_patterns)
felix@3266: #        (XFig and other editors have a nasty habit of leaving them around)
felix@3266: #        Also removes Makefile-generated .temp files
felix@3266: #
felix@3266: #    clean-tex:
felix@3266: #        Remove all files generated from LaTeX invocations except dependency
felix@3266: #        information.  Leaves graphics alone.
felix@3266: #
felix@3266: #    clean-deps:
felix@3266: #        Removes all auto-generated dependency information.
felix@3266: #
felix@3266: #    clean-auxiliary:
felix@3266: #        Removes extra files created by various targets (like the dependency
felix@3266: #        graph output).
felix@3266: #
felix@3266: #    clean-nographics:
felix@3266: #        Cleans everything *except* the graphics files.
felix@3266: #
felix@3266: #    help:
felix@3266: #        This help text.
felix@3266: #
felix@3266: #    version:
felix@3266: #        Version information about this LaTeX makefile.
felix@3266: #
felix@3266: # DEBUG TARGETS:
felix@3266: #
felix@3266: #    _all_programs:
felix@3266: #        A list of the programs used by this makefile.
felix@3266: #
felix@3266: #    _check_programs:
felix@3266: #        Checks your system for the needed software and reports what it finds.
felix@3266: #
felix@3266: #    _check_gpi_files:
felix@3266: #        Checks the .gpi files in the current directory for common errors, such
felix@3266: #        as specification of the terminal or output file inside of the gpi file
felix@3266: #        itself.
felix@3266: #
felix@3266: #    _dependency_graph:
felix@3266: #        Outputs a .dot file to stdout that represents a graph of LaTeX
felix@3266: #        dependencies.  To see it, use the _show_dependency_graph target or
felix@3266: #        direct the output to a file, run dot on it, and view the output, e.g.:
felix@3266: #
felix@3266: #        make _dependency_graph > graph.dot
felix@3266: #        dot -T ps -o graph.eps graph.dot
felix@3266: #        gv graph.eps
felix@3266: #
felix@3266: #    _show_dependency_graph:
felix@3266: #        Makes viewing the graph simple: extracts, builds and displays the
felix@3266: #        dependency graph given in the _dependency_graph target using the value
felix@3266: #        of the environment-overridable VIEW_POSTSCRIPT variable (currently set
felix@3266: #        to $(VIEW_POSTSCRIPT)).  The postscript viewer is used because it
felix@3266: #        makes it easier to zoom in on the graph, a critical ability for
felix@3266: #        something so dense and mysterious.
felix@3266: #
felix@3266: #    _all_sources:
felix@3266: #        List all .tex files in this directory.
felix@3266: #
felix@3266: #    _sources:
felix@3266: #        Print out a list of all compilable sources in this directory.  This is
felix@3266: #        useful for determining what make thinks it will be using as the
felix@3266: #        primary source for 'make all'.
felix@3266: #
felix@3266: #    _scripts:
felix@3266: #        Print out a list of scripts that make knows can be used to generate
felix@3266: #        .tex files (described later).
felix@3266: #
felix@3266: #    _all_stems:
felix@3266: #        Print a list of stems.  These represent bare targets that can be
felix@3266: #        executed.  Listing <stem> as a bare target will produce <stem>.pdf.
felix@3266: #
felix@3266: #    _includes:
felix@3266: #        A list of .d files that would be included in this run if _includes
felix@3266: #        weren't specified.  This target may be used alone or in conjunction
felix@3266: #        with other targets.
felix@3266: #
felix@3266: #    _graphic_outputs:
felix@3266: #        A list of all generated .eps files
felix@3266: #
felix@3266: #    _env:
felix@3266: #        A list of environment variables and their values.  If supported by
felix@3266: #        your version of make, also a list of variables known to make.
felix@3266: #
felix@3266: # FILE TARGETS:
felix@3266: #
felix@3266: #    %, %.pdf:
felix@3266: #        Build a PDF file from the corresponding %.tex file.
felix@3266: #
felix@3266: #        If BUILD_STRATEGY=pdflatex, then this builds the pdf directly.
felix@3266: #        Otherwise, it uses this old-school but effective approach:
felix@3266: #
felix@3266: #            latex -> dvips -> ps2pdf
felix@3266: #
felix@3266: #        The BUILD_STRATEGY can be overridden in Makefile.ini in the same
felix@3266: #        directory.  The default is pdflatex.
felix@3266: #
felix@3266: #        Reasons for using latex -> dvips include the "psfrag" package, and the
felix@3266: #        generation of postscript instead of PDF.  Arguments for using pdflatex
felix@3266: #        include "new and shiny" and "better supported."  I can't argue with
felix@3266: #        either of those, and supporting them both didn't turn out to be that
felix@3266: #        difficult, so there you have it.  Choices.
felix@3266: #
felix@3266: #    %._show:
felix@3266: #        A phony target that builds the pdf file and then displays it using the
felix@3266: #        environment-overridable value of VIEW_PDF ($(VIEW_PDF)).
felix@3266: #
felix@3266: #    %._graphics:
felix@3266: #        A phony target that generates all graphics on which %.pdf (or %.dvi)
felix@3266: #        depends.
felix@3266: #
felix@3266: #    %.ps (only for BUILD_STRATEGY=latex):
felix@3266: #        Build a Postscript file from the corresponding %.tex file.
felix@3266: #        This is done using dvips.  Paper size is automatically
felix@3266: #        extracted from the declaration
felix@3266: #
felix@3266: #        \documentclass[<something>paper]
felix@3266: #
felix@3266: #        or it is the system default.
felix@3266: #
felix@3266: #        If using beamer (an excellent presentation class), the paper
felix@3266: #        size is ignored.  More on this later.
felix@3266: #
felix@3266: #    %.dvi (only for BUILD_STRATEGY=latex):
felix@3266: #        Build the DVI file from the corresponding %.tex file.
felix@3266: #
felix@3266: #    %.ind:
felix@3266: #        Build the index for this %.tex file.
felix@3266: #
felix@3266: #    %.gls:
felix@3266: #        Build the nomenclature glossary for this %.tex file.
felix@3266: #
felix@3266: #    %.nls:
felix@3266: #        Build the (newer) nomenclature file for this %.tex file.
felix@3266: #
felix@3266: #    %.eps:
felix@3266: #        Build an eps file from one of the following file types:
felix@3266: #
felix@3266: #       .dot    : graphviz
felix@3266: #       .gpi    : gnuplot
felix@3266: #       .fig    : xfig
felix@3266: #       .xvg    : xmgrace
felix@3266: #       .svg    : scalable vector graphics (goes through inkscape)
felix@3266: #       .png    : png (goes through NetPBM)
felix@3266: #       .jpg	: jpeg (goes through ImageMagick)
felix@3266: #       .eps.gz : gzipped eps
felix@3266: #
felix@3266: #       The behavior of this makefile with each type is described in
felix@3266: #       its own section below.
felix@3266: #
felix@3266: #    %.pstex{,_t} (only for BUILD_STRATEGY=latex):
felix@3266: #       Build a .pstex_t file from a .fig file.
felix@3266: #
felix@3266: # FEATURES:
felix@3266: #
felix@3266: #    Optional Binary Directory:
felix@3266: #        If you create the _out_ directory in the same place as the makefile,
felix@3266: #        it will automatically be used as a dumping ground for .pdf (or .dvi,
felix@3266: #        .ps, and .pdf) output files.
felix@3266: #
felix@3266: #        Alternatively, you can set the BINARY_TARGET_DIR variable, either as a
felix@3266: #        make argument or in Makefile.ini, to point to your directory of
felix@3266: #        choice.  Note that no pathname wildcard expansion is done in the
felix@3266: #        makefile, so make sure that the path is complete before going in
felix@3266: #        there.  E.g., if you want to specify something in your home directory,
felix@3266: #        use $$HOME/ instead of ~/ so that the shell expands it before it gets
felix@3266: #        to the makefile.
felix@3266: #
felix@3266: #    External Program Dependencies:
felix@3266: #        Every external program used by the makefile is represented by an
felix@3266: #        ALLCAPS variable at the top of this file.  This should allow you to
felix@3266: #        make judgments about whether your system supports the use of this
felix@3266: #        makefile.  The list is available in the ALL_PROGRAMS variable and,
felix@3266: #        provided that you are using GNU make 3.80 or later (or you haven't
felix@3266: #        renamed this file to something weird like "mylatexmakefile" and like
felix@3266: #        invoking it with make -f) can be viewed using
felix@3266: #
felix@3266: #        make _all_programs
felix@3266: #
felix@3266: #        Additionally, the availability of these programs can be checked
felix@3266: #        automatically for you by running
felix@3266: #
felix@3266: #        make _check_programs
felix@3266: #
felix@3266: #        The programs are categorized according to how important they are and
felix@3266: #        what function they perform to help you decide which ones you really
felix@3266: #        need.
felix@3266: #
felix@3266: #    Colorized Output:
felix@3266: #        The output of commands is colorized to highlight things that are often
felix@3266: #        important to developers.  This includes {underfull,overfull}
felix@3266: #        {h,v}boxes, general LaTeX Errors, each stage of document building, and
felix@3266: #        the number of pages in the final document.  The colors are obtained
felix@3266: #        using 'tput', so colorization should work pretty well on any terminal.
felix@3266: #
felix@3266: #        The colors can be customized very simply by setting any of the
felix@3266: #        LATEX_COLOR_<CONTEXT> variables in your environment (see above).
felix@3266: #
felix@3266: #    Predecessors to TeX Files:
felix@3266: #        Given a target <target>, if no <target>.tex file exists but a
felix@3266: #        corresponding script or predecessor file exists, then appropriate
felix@3266: #        action will be taken to generate the tex file.
felix@3266: #
felix@3266: #        Currently supported script or predecessor languages are:
felix@3266: #
felix@3266: #        sh:     %.tex.sh
felix@3266: #        perl:   %.tex.pl
felix@3266: #        python: %.tex.py
felix@3266: #
felix@3266: #           Calls the script using the appropriate interpreter, assuming that
felix@3266: #           its output is a .tex file.
felix@3266: #
felix@3266: #           The script is called thus:
felix@3266: #
felix@3266: #              <interpreter> <script file name> <target tex file>
felix@3266: #
felix@3266: #           and therefore sees exactly one parameter: the name of the .tex
felix@3266: #           file that it is to create.
felix@3266: #
felix@3266: #           Why does this feature exist?  I ran into this while working on
felix@3266: #           my paper dissertation.  I wrote a huge bash script that used a
felix@3266: #           lot of sed to bring together existing papers in LaTeX.  It
felix@3266: #           would have been nice had I had something like this to make my
felix@3266: #           life easier, since as it stands I have to run the script and
felix@3266: #           then build the document with make.  This feature provides hooks
felix@3266: #           for complicated stuff that you may want to do, but that I have
felix@3266: #           not considered.  It should work fine with included dependencies,
felix@3266: #           too.
felix@3266: #
felix@3266: #           Scripts are run every time make is invoked.  Some trickery is
felix@3266: #           employed to make sure that multiple restarts of make don't cause
felix@3266: #           them to be run again.
felix@3266: #
felix@3266: #        reST: %.rst
felix@3266: #
felix@3266: #           Runs the reST to LaTeX converter to generate a .tex file
felix@3266: #           If it finds a file names _rststyle_._include_.tex, uses it as
felix@3266: #           the "stylesheet" option to rst2latex.
felix@3266: #
felix@3266: #           Note that this does not track sub-dependencies in rst files.  It
felix@3266: #           assumes that the top-level rst file will change if you want a
felix@3266: #           rebuild.
felix@3266: #
felix@3266: #    Dependencies:
felix@3266: #
felix@3266: #        In general, dependencies are extracted directly from LaTeX output on
felix@3266: #        your document.  This includes
felix@3266: #
felix@3266: #        *    Bibliography information
felix@3266: #        *    \include or \input files (honoring \includeonly, too)
felix@3266: #        *    Graphics files inserted by the graphicx package
felix@3266: #
felix@3266: #        Where possible, all of these are built correctly and automatically.
felix@3266: #        In the case of graphics files, these are generated from the following
felix@3266: #        file types:
felix@3266: #
felix@3266: #        GraphViz:      .dot
felix@3266: #        GNUPlot:       .gpi
felix@3266: #        XFig:          .fig
felix@3266: #        XMgrace:       .xvg
felix@3266: #        SVG:           .svg
felix@3266: #        PNG:           .png
felix@3266: #        JPEG:          .jpg
felix@3266: #        GZipped EPS:   .eps.gz
felix@3266: #
felix@3266: #        If the file exists as a .eps already, it is merely used (and will not
felix@3266: #        be deleted by 'clean'!).
felix@3266: #
felix@3266: #        LaTeX and BibTeX are invoked correctly and the "Rerun to get
felix@3266: #        cross-references right" warning is heeded a reasonable number of
felix@3266: #        times.  In my experience this is enough for even the most troublesome
felix@3266: #        documents, but it can be easily changed (if LaTeX has to be run after
felix@3266: #        BibTeX more than three times, it is likely that something is moving
felix@3266: #        back and forth between pages, and no amount of LaTeXing will fix
felix@3266: #        that).
felix@3266: #
felix@3266: #        \includeonly is honored by this system, so files that are not
felix@3266: #        specified there will not trigger a rebuild when changed.
felix@3266: #
felix@3266: #    Beamer:
felix@3266: #        A special TeX source comment is recognized by this makefile (only when
felix@3266: #        BUILD_STRATEGY=latex, since this invokes psnup):
felix@3266: #
felix@3266: #        %%[[:space:]]*BEAMER[[:space:]]*LARGE
felix@3266: #
felix@3266: #        The presence of this comment forces the output of dvips through psnup
felix@3266: #        to enlarge beamer slides to take up an entire letter-sized page.  This
felix@3266: #        is particularly useful when printing transparencies or paper versions
felix@3266: #        of the slides.  For some reason landscape orientation doesn't appear
felix@3266: #        to work, though.
felix@3266: #
felix@3266: #        If you want to put multiple slides on a page, use this option and then
felix@3266: #        print using mpage, a2ps, or psnup to consolidate slides.  My personal
felix@3266: #        favorite is a2ps, but your mileage may vary.
felix@3266: #
felix@3266: #        When beamer is the document class, dvips does NOT receive a paper size
felix@3266: #        command line attribute, since beamer does special things with sizes.
felix@3266: #
felix@3266: #    GNUPlot Graphics:
felix@3266: #        When creating a .gpi file, DO NOT INCLUDE the "set terminal" or "set
felix@3266: #        output" commands!  The makefile will include terminal information for
felix@3266: #        you.  Besides being unnecessary and potentially harmful, including the
felix@3266: #        terminal definition in the .gpi file makes it harder for you, the one
felix@3266: #        writing the document, to preview your graphics, e.g., with
felix@3266: #
felix@3266: #           gnuplot -persist myfile.gpi
felix@3266: #
felix@3266: #        so don't do specify a terminal or an output file in your .gpi files.
felix@3266: #
felix@3266: #        When building a gpi file into an eps file, there are several features
felix@3266: #        available to the document designer:
felix@3266: #
felix@3266: #        Global Header:
felix@3266: #            The makefile searches for the files in the variable GNUPLOT_GLOBAL
felix@3266: #            in order:
felix@3266: #
felix@3266: #            ($(GNUPLOT_GLOBAL))
felix@3266: #
felix@3266: #            Only the first found is used.  All .gpi files in the directory are
felix@3266: #            treated as though the contents of GNUPLOT_GLOBAL were directly
felix@3266: #            included at the top of the file.
felix@3266: #
felix@3266: #            NOTE: This includes special comments! (see below)
felix@3266: #
felix@3266: #        Font Size:
felix@3266: #            A special comment in a .gpi file (or a globally included file) of
felix@3266: #            the form
felix@3266: #
felix@3266: #            ## FONTSIZE=<number>
felix@3266: #
felix@3266: #            will change the font size of the GPI output.  If font size is
felix@3266: #            specified in both the global file and the GPI file, the
felix@3266: #            specification in the individual GPI file is used.
felix@3266: #
felix@3266: #        Grayscale Output:
felix@3266: #            GNUplot files also support a special comment to force them to be
felix@3266: #            output in grayscale *no matter what*:
felix@3266: #
felix@3266: #            ## GRAY
felix@3266: #
felix@3266: #            This is not generally advisable, since you can always create a
felix@3266: #            grayscale document using the forms mentioned above.  But, if your
felix@3266: #            plot simply must be grayscale even in a document that allows
felix@3266: #            colors, this is how you do it.
felix@3266: #
felix@3266: #    XFig Graphics:
felix@3266: #            No special handling is done with XFig, except when a global
felix@3266: #            grayscale method is used, e.g.
felix@3266: #
felix@3266: #                make GRAY=1 document
felix@3266: #
felix@3266: #            In these cases the .eps files is created using the -N switch to
felix@3266: #            fig2dev to turn off color output.  (Only works with eps, not pstex
felix@3266: #            output)
felix@3266: #
felix@3266: #    GraphVis Graphics:
felix@3266: #            Color settings are simply ignored here.  The 'dot' program is used
felix@3266: #            to transform a .dot file into a .eps file.
felix@3266: #
felix@3266: #            If you want, you can use the dot2tex program to convert dot files
felix@3266: #            to tex graphics.  The default is to just call dot2tex with no
felix@3266: #            arguments, but you can change the DOT2TEX definition to include
felix@3266: #            options as needed (in your Makefile.ini).
felix@3266: #
felix@3266: #            Note that, as with pstex, the makefile cannot use latex's own
felix@3266: #            output to discover all missing dot_t (output) files, since anytime
felix@3266: #            TeX includes TeX, it has to bail when it can't find the include
felix@3266: #            file.  It can therefore only stop on the first missing file it
felix@3266: #            discovers, and we can't get a large list of them out easily.
felix@3266: #
felix@3266: #            So, the makefile errors out if it's missing an included dot_t
felix@3266: #            file, then prompts the user to run this command manually:
felix@3266: #
felix@3266: #                make all-dot2tex
felix@3266: #
felix@3266: #    GZipped EPS Graphics:
felix@3266: #
felix@3266: #        A .eps.gz file is sometimes a nice thing to have.  EPS files can get
felix@3266: #        very large, especially when created from bitmaps (don't do this if you
felix@3266: #        don't have to).  This makefile will unzip them (not in place) to
felix@3266: #        create the appropriate EPS file.
felix@3266: #
felix@3266: endef
felix@3266: 
felix@3266: #
felix@3266: # DEPENDENCY CHART:
felix@3266: #
felix@3266: #digraph "g" {
felix@3266: #    rankdir=TB
felix@3266: #    size="9,9"
felix@3266: #    edge [fontsize=12 weight=10]
felix@3266: #    node [shape=box fontsize=14 style=rounded]
felix@3266: #
felix@3266: #    eps [
felix@3266: #        shape=Mrecord
felix@3266: #        label="{{<gpi> GNUplot|<epsgz> GZip|<dot> Dot|<fig> XFig}|<eps> eps}"
felix@3266: #        ]
felix@3266: #    pstex [label="%.pstex"]
felix@3266: #    pstex_t [label="%.pstex_t"]
felix@3266: #    tex_outputs [shape=point]
felix@3266: #    extra_tex_files [shape=point]
felix@3266: #    gpi_data [label="<data>"]
felix@3266: #    gpi_includes [label="_include_.gpi"]
felix@3266: #    aux [label="%.aux"]
felix@3266: #    fls [label="%.fls"]
felix@3266: #    idx [label="%.idx"]
felix@3266: #    glo [label="%.glo"]
felix@3266: #    ind [label="%.ind"]
felix@3266: #    log [label="%.log"]
felix@3266: #    tex_sh [label="%.tex.sh"]
felix@3266: #    rst [label="%.rst"]
felix@3266: #    tex [
felix@3266: #        shape=record
felix@3266: #        label="<tex> %.tex|<include> _include_.tex"
felix@3266: #        ]
felix@3266: #    include_aux [label="_include_.aux"]
felix@3266: #    file_bib [label=".bib"]
felix@3266: #    bbl [label="%.bbl"]
felix@3266: #    dvi [label="%.dvi"]
felix@3266: #    ps [label="%.ps"]
felix@3266: #    pdf [label="%.pdf"]
felix@3266: #    fig [label=".fig"]
felix@3266: #    dot [label=".dot"]
felix@3266: #    gpi [label=".gpi"]
felix@3266: #    eps_gz [label=".eps.gz"]
felix@3266: #
felix@3266: #    gpi_files [shape=point]
felix@3266: #
felix@3266: #    rst -> tex:tex [label="reST"]
felix@3266: #    tex_sh -> tex:tex [label="sh"]
felix@3266: #    tex_pl -> tex:tex [label="perl"]
felix@3266: #    tex_py -> tex:tex [label="python"]
felix@3266: #    tex -> tex_outputs [label="latex"]
felix@3266: #    tex_outputs -> dvi
felix@3266: #    tex_outputs -> aux
felix@3266: #    tex_outputs -> log
felix@3266: #    tex_outputs -> fls
felix@3266: #    tex_outputs -> idx
felix@3266: #    tex_outputs -> include_aux
felix@3266: #    aux -> bbl [label="bibtex"]
felix@3266: #    file_bib -> bbl [label="bibtex"]
felix@3266: #    idx -> ind [label="makeindex"]
felix@3266: #    glo -> gls [label="makeindex"]
felix@3266: #    nlo -> nls [label="makeindex"]
felix@3266: #    gls -> extra_tex_files
felix@3266: #    nls -> extra_tex_files
felix@3266: #    ind -> extra_tex_files
felix@3266: #    bbl -> extra_tex_files
felix@3266: #    eps -> extra_tex_files
felix@3266: #    extra_tex_files -> dvi [label="latex"]
felix@3266: #    gpi_files -> eps:gpi [label="gnuplot"]
felix@3266: #    gpi -> gpi_files
felix@3266: #    gpi_data -> gpi_files
felix@3266: #    gpi_includes -> gpi_files
felix@3266: #    eps_gz -> eps:epsgz [label="gunzip"]
felix@3266: #    fig -> eps:fig [label="fig2dev"]
felix@3266: #    fig -> pstex [label="fig2dev"]
felix@3266: #    fig -> pstex_t [label="fig2dev"]
felix@3266: #    pstex -> pstex_t [label="fig2dev"]
felix@3266: #    dot -> eps:dot [label="dot"]
felix@3266: #    dvi -> ps [label="dvips"]
felix@3266: #    include_aux -> bbl [label="bibtex"]
felix@3266: #    ps -> pdf [label="ps2pdf"]
felix@3266: #
felix@3266: #    edge [ color=blue label="" style=dotted weight=1 fontcolor=blue]
felix@3266: #    fls -> tex:include [label="INPUT: *.tex"]
felix@3266: #    fls -> file_bib [label="INPUT: *.aux"]
felix@3266: #    aux -> file_bib [label="\\bibdata{...}"]
felix@3266: #    include_aux -> file_bib [label="\\bibdata{...}"]
felix@3266: #    log -> gpi [label="Graphic file"]
felix@3266: #    log -> fig [label="Graphic file"]
felix@3266: #    log -> eps_gz [label="Graphic file"]
felix@3266: #    log -> dot [label="Graphic file"]
felix@3266: #    log -> idx [label="No file *.ind"]
felix@3266: #    log -> glo [label="No file *.gls"]
felix@3266: #    log -> nlo [label="No file *.nls"]
felix@3266: #    gpi -> gpi_data [label="plot '...'"]
felix@3266: #    gpi -> gpi_includes [label="load '...'"]
felix@3266: #    tex:tex -> ps [label="paper"]
felix@3266: #    tex:tex -> pdf [label="embedding"]
felix@3266: #}
felix@3266: 
felix@3266: #
felix@3266: # DEPENDENCY CHART SCRIPT
felix@3266: #
felix@3266: # $(call output_dependency_graph,[<output file>])
felix@3266: define output-dependency-graph
felix@3266: 	if [ -f '$(this_file)' ]; then \
felix@3266: 	$(SED) \
felix@3266: 		-e '/^[[:space:]]*#[[:space:]]*DEPENDENCY CHART:/,/^$$/!d' \
felix@3266: 		-e '/DEPENDENCY CHART/d' \
felix@3266: 		-e '/^$$/d' \
felix@3266: 		-e 's/^[[:space:]]*#//' \
felix@3266: 		$(this_file) $(if $1,> '$1',); \
felix@3266: 	else \
felix@3266: 		$(ECHO) "Cannot determine the name of this makefile."; \