-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
2799 lines (2598 loc) · 93.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2004 Chris Monson ([email protected])
# Latest version available at http://www.bouncingchairs.net/oss
#
# This file is part of ``Chris Monson's Free Software''.
#
# ``Chris Monson's Free Software'' is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, Version 2.
#
# ``Chris Monson's Free Software'' is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with ``Chris Monson's Free Software''; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# It is also available on the web at http://www.gnu.org/copyleft/gpl.html
#
# Note that using this makefile to build your documents does NOT place them
# under the GPL unless you, the author, specifically do so. In other words,
# I, Chris Monson, the copyright holder and author of this makefile,
# consider it impossible to ``link'' to this makefile in any way covered by
# the GPL.
#
# TO OBTAIN INSTRUCTIONS FOR USING THIS FILE, RUN:
# make help
#
fileinfo := LaTeX Makefile
author := Chris Monson
version := 2.1.25
svninfo := $$Id: Makefile 49 2009-03-27 13:24:47Z shiblon $$
#
# If you specify sources here, all other files with the same suffix
# will be treated as if they were _include_ files.
#onlysources.tex ?= main.tex
#onlysources.tex.sh ?=
#onlysources.rst ?=
#onlysources.fig ?=
#onlysources.gpi ?=
#onlysources.dot ?=
#onlysources.xvg ?=
#onlysources.eps.gz ?=
#onlysources.eps ?=
#
# If you list files here, they will be treated as _include_ files
#includes.tex ?= file1.tex file2.tex
#includes.tex.sh ?=
#includes.rst ?=
#includes.fig ?=
#includes.gpi ?=
#includes.dot ?=
#includes.xvg ?=
#includes.eps.gz ?=
#includes.eps ?=
#
# If you list files or wildcards here, they will *not* be cleaned - default is
# to allow everything to be cleaned.
#neverclean ?= *.pdf
#
# Alternatively (recommended), you can add those lines to a Makefile.ini file
# and it will get picked up automatically without your having to edit this
# Makefile.
-include Makefile.ini
# TODO:
# * Sometimes we get
# "mv: cannot stat '*.dvi.1st.make': No such file or directory"
# on the second build (if nothing triggered a .d rebuild, but
# the .dvi rule fired anyway). To reproduce in the
# dissertation directory:
#
# make clean
# make byumsphd-example
# make byumsphd-example
#
# KNOWN ISSUES:
# * The following occurs:
# file with: \usepackage{named}\bibliographystyle{named}
# Compile
# change to: \usepackage{apalike}\bibliographystyle{apalike}
# Compile again -- BARF!
#
# The workaround: make clean-nographics; make
#
# Note that we may not be able to fix this. LaTeX itself barfs
# on this, not the makefile. The very first invocation of LaTeX
# (when something like this has happened) reads the existing .aux
# file and discovers invalid commands like \citeauthoryear that
# are only valid in the package that was just removed. It then
# tries to parse them and explodes. It's not at all clear to me
# how to fix this. I tried removing the .aux files on the first
# run of LaTeX, but that necessarily requires more subsequent
# rebuilds on common edits. There does not appear to be a
# graceful solution to this issue.
#
# CHANGES:
# Chris Monson (2009-03-27):
# * Bumped version to 2.1.25
# * Cleaned up a bunch of variable setting stuff - more stuff is now
# settable from Makefile.ini
# * Cleaned up documentation for various features, especially settable
# variables.
# * issue 28: support for png -> eps conversion (it even looks good!)
# * issue 29: support for "neverclean" files in Makefile.ini
# * issue 30: make ps2pdf14 the default - fall back when not there
# Chris Monson (2009-03-09):
# * Bumped version to 2.1.24
# * issue 27: xmgrace support (thanks to rolandschulzhd)
# Chris Monson (2008-10-23):
# * Bumped version to 2.1.23
# * issue 23: fixed _check_programs to not use bash string subs
# Chris Monson (2008-09-02):
# * Bumped version to 2.1.22
# * Appled patch from Holger <[email protected]> to add include
# sources and some documentation updates.
# * Updated backup_patterns to be a bit more aggressive (also thanks to
# Holger)
# Chris Monson (2008-08-30):
# * Bumped version to 2.1.21
# * Added ability to specify onlysources.* variables to indicate the only
# files that should *not* be considered includes. Thanks to Holger
# <[email protected]> for this patch.
# * Added an automatic include of Makefile.ini if it exists. Allows
# settings to be made outside of this makefile.
# Chris Monson (2008-05-21):
# * Bumped version to 2.1.20
# * Added manual pstex compilation support (run make all-pstex first)
# * Removed all automatic pstex support. It was totally breaking
# everything and is very hard to incorporate into the makefile
# concept because it requires LaTeX to *fail* before it can
# determine that it needs the files.
# Chris Monson (2008-04-17):
# * Bumped version to 2.1.19
# * Changed the pstex build hack to be on by default
# Chris Monson (2008-04-09):
# * Bumped version to 2.1.18
# * issue 16: fixed pstex build problems, seems nondeterministic. Added
# gratuitious hack for testing: set PSTEX_BUILD_ALL_HACK=1.
# Chris Monson (2008-04-09):
# * Bumped version to 2.1.17
# * issue 20: fixed accumulation of <pid>*.make files - wildcard was
# refusing to work on files that are very recently created.
# Chris Monson (2008-04-02):
# * Bumped version to 2.1.16
# * issue 19: Removed the use of "type" to fix broken "echo" settings
# Chris Monson (2008-03-27):
# * Bumped version to 2.1.15
# * issue 18: Favors binary echo over builtin, as binary understands -n
# * issue 16: Fixed handling of missing pstex_t files in the log
# * issue 9: Added .SECONDARY target for .pstex files
# Chris Monson (2008-03-21):
# * Bumped version to 2.1.14
# * Fixed broken aux file flattening, which caused included bibs to be
# missed.
# Chris Monson (2008-03-20):
# * Bumped version to 2.1.13
# * Changed error output colorization to show errors for missing files
# that are not graphics files.
# Chris Monson (2008-03-20):
# * Bumped version to 2.1.12
# * Fixed a regression introduced in r28 that makes bibtex fail when
# there is no index file present
# Chris Monson (2008-03-03):
# * Bumped version to 2.1.11
# * Fixed issue 11 (handle index files, reported by abachn)
# * Cleaned up some comments and help text
# Chris Monson (2008-01-24):
# * Bumped version to 2.1.10
# * Fixed to work when 'sh' is a POSIX shell like 'dash'
# Chris Monson (2007-12-12):
# * Bumped version to 2.1.9
# * Fixed documentation and dependency graph for pstex files
# Chris Monson (2007-12-12):
# * Bumped version to 2.1.8
# * Added basic pstex_t support for fig files (Issue 9 by favonia)
# I still suggest that psfrag be used instead.
# Chris Monson (2007-10-16):
# * Bumped version to 2.1.7
# * Removed todo item: allow other comment directives for rst conversion
# * Added ability to use global rst style file _rststyle_._include_.tex
# * Added help text to that effect
# Chris Monson (2007-05-20):
# * Bumped version to 2.1.6
# * Changed default paper size for rst files
# * Added todo item: fix paper size for rst files
# * Added todo item: allow other comment directives for rst conversion
# Chris Monson (2007-04-02):
# * Bumped version to 2.1.5
# * Addressed Issue 7, incorrect .gpi.d generation in subdirectories
# Chris Monson (2007-03-28):
# * Bumped version to 2.1.4
# * Fixed syntax error in dot output
# Chris Monson (2007-03-01):
# * Bumped version to 2.1.3
# * Added reST to the included documentation
# * Fixed graphics and script generation to be settable in the
# environment.
# Chris Monson (2007-02-23):
# * Bumped version to 2.1.2
# * Added the ability to generate .tex files from .rst files
# Chris Monson (2006-10-17):
# * Bumped version to 2.1.1
# * Fixed includes from subdirectories (sed-to-sed slash escape problem)
# Chris Monson (2006-10-05):
# * Bumped version to 2.1.0 (pretty serious new feature added)
# * New feature: bib files can now be anywhere on the BIBINPUTS path
# * New programs: kpsewhich (with tetex) and xargs (BSD)
# Chris Monson (2006-09-28):
# * Bumped version to 2.0.9
# * Added ability to parse more than one bibliography
# Chris Monson (2006-06-01):
# * Bumped version to 2.0.8
# * Added .vrb to the list of cleaned files
# Chris Monson (2006-04-26):
# * Bumped version to 2.0.7
# * Fixed so that clean-nographics does not remove .gpi.d files
# * Removed jpg -> eps hack (not working properly -- just pre-convert)
# * Fixed so that postscript grayscale can be done with BSD sed
# Chris Monson (2006-04-25):
# * Bumped version to 2.0.6
# * Fixed so that changed toc, lot, lof, or out causes a rebuild
# Chris Monson (2006-04-17):
# * Bumped version to 2.0.5
# * Added jpg -> eps conversion target
# Chris Monson (2006-04-12):
# * Bumped version to 2.0.4
# * Fixed BSD sed invocation to not use \| as a branch delimiter
# * Added a comment section on what is and is not allowed in BSD sed
# * Made paper size handling more robust while I was at it
# * Fixed postscript RGB grayscale to use a weighted average
# * Fixed postscript HSB grayscale to convert to RGB first
# * Fixed a problem with rebuilding .bbl files
# Chris Monson (2006-04-11):
# * Bumped version to 2.0.3
# * Fixed some BSD sed problems: can't use \n in substitutions
# Chris Monson (2006-04-10):
# * Bumped version to 2.0.2
# * Once again removed ability to create .tex files from scripts
# * \includeonly works again
# Chris Monson (2006-04-09):
# * Bumped version to 2.0.1
# * Fixed grayscale postscript handling to be more robust
# * Added ability to generate ._gray_. files from eps and eps.gz
# * Added ability to clean ._gray_.eps files created from .eps files
# Chris Monson (2006-04-07):
# * Bumped version to 2.0.0
# * Removed clunky ability to create included .tex files from scripts
# * Added note in the help about included tex scripting not working
# * Fixed the .eps generation to delete %.gpihead.make when finished
# * Abandoned designs to use shell variables to create sed scripts
# * Abandoned __default__.tex.sh idea: it causes recursion with %: .
# * Removed web page to-do. All items are now complete.
# * Added better grayscale conversion for dot figures (direct ps fixup).
# * Include files can now be scripted (at the expense of \includeonly).
# * Updated dependency graph to contain better node names.
# Chris Monson (2006-04-06):
# * Bumped version to 2.0b3
# * Top level includes now fail if there is no rule to build them
# * A helpful message is printed when they do fail
# * Grayscale has been changed to be ._gray_, other phonies use _ now, too
# * Grayscale handling has been completed
# * Changed _include_stems target to _includes target.
# * Fixed _includes target to be useful by itself.
# * Removed the ability to specify clean and build targets at once
# * Verified that epsfig works fine with current code
# * Fixed included scripts so that they are added to the dep files
# * Fixed so that graphics includes don't happen if they aren't for gpi
# * Fixed dot output to allow grayscale.
# Chris Monson (2006-04-05):
# * Bumped version to 2.0b2
# * Removed automatic -gray output. It needs fixing in a bad way.
# * Revamped dependency creation completely.
# * Fixed conditional inclusion to actually work (test.nobuild.d, test.d).
# * Fixed clean target to remove log targets
# * Added the 'monochrome' word for gray gpi output
# * Added a _check_gpi_files target that checks for common problems
# * Changed the _version target into the version target (no _)
# * Added better handling of grayscale files. Use the .gray.pdf target.
# * Fixed testing for rebuilds
# Chris Monson (2006-04-04):
# * Bumped version to 2.0b1
# * Changed colorization of output
# * Made .auxbbl and .auxtex .make files secondary targets
# * Shortened and simplified the final latex invocation loop
# * Added version-specific output ($$i vs. $$$$i) in latex loop
# * Added a build message for the first .dvi run (Building .dvi (0))
# * Removed some build messages that most people don't care about.
# * Simplified procedure for user-set colors -- simple text specification
# * Fixed diff output to...not output.
# * Fixed rerun bug -- detect not only when preceded with LaTeX Warning
# * Sped up gpi plotting
# * Added error handling and colorized output for gpi failure
# * Documented color changing stuff.
# * Now sort the flattened aux file to avoid false recompilation needs
# * Added clean-nographics target
# * Don't remove self.dvi file if self.aux is missing in the log
# * Clarified some code. Did some very minor adjusting.
# Chris Monson (2006-04-03):
# * Bumped version to 2.0a7
# * Added .dvi and .ps files as secondary files.
# * Fixed handling of multiple run detection when includeonly is in use.
# * Added code to flatten .aux files.
# * Added more files as .SECONDARY prerequisites to avoid recompilation.
# * Fixed the inputs generation to be much simpler and to use pipes.
# * Added the dependency graph directly into the makefile.
# * Changed flatten-aux to remove \@writefile \relax \newlabel, etc.
# * Undid pipe changes with sed usage (BSD sed doesn't know -f-).
# * Added a _check_programs target that tells you what your system has.
# * Fixed an error in colorization that made unnecessary errors appear
# * Added view targets.
# * Updated help text.
# * Augmented cookies so that .aux can trigger .bbl and .dvi rebuilds
# * Added more informative error handling for dvips and ps2pdf
# Chris Monson (2006-04-02):
# * Bumped version to 2.0a6
# * Added indirection to .bbl dependencies to avoid rebuilding .bbl files
# * Streamlined the diff invocation to eliminate an existence test
# * Removed special shell quote escape variables
# * Moved includes to a more prominent location
# * Fixed .inputs.make to not contain .aux files
# * Fixed embedding to use a file instead of always grepping.
# * Added *.make.temp to the list of cleanable files
# * Fixed Ruby. It should now be supported properly.
# * Now differentiate between all, default, and buildable files.
# * Fixed to bail out on serious errors.
# * Revised the handling of includable files. Still working on it.
# Chris Monson (2006-03-31):
# * Bumped version to 2.0a5
# * Fixed a bug with LaTeX error detection (there can be spaces)
# * Added .bbl support, simplifying everything and making it more correct
# * Refactored some tests that muddy the code
# * Did a little cleanup of some shell loops that can safely be make loops
# * Added support for graphviz .dot files
# * Made _all_programs output easier to read
# * Added the ruby support that has long been advertised
# * Font embedding was screwed up for PostScript -- now implicit
# * Changed the generation of -gray.gpi files to a single command
# * Changed any make-generated file that is not included from .d to .make
# Chris Monson (2006-03-30):
# * Bumped version to 2.0a4
# * Fixed a bug with very long graphics file names
# * Added a todo entry for epsfig support
# * Fixed a bug paper size bug: sometimes more than one entry appears
# * Fixed DVI build echoing to display the number instead of process ID
# * DVI files are now removed on first invocation if ANY file is missing
# * Added a simple grayscale approach: if a file ends with -gray.gpi, it
# is created from the corresponding .gpi file with a special
# comment ##GRAY in its header, which causes coloring to be
# turned off.
# * Fixed a bug in the handling of .tex.sh files. For some reason I had
# neglected to define file stems for scripted output.
# * Removed a trailing ; from the %.graphics dependencies
# * Added dvips embedding (I think it works, anyway)
# Chris Monson (2006-03-29):
# * Bumped version to 2.0a3
# * Fixed error in make 3.79 with MAKEFILE_LIST usage
# * Added the presumed filename to the _version output
# * Added a vim macro for converting sed scripts to make commands
# * Added gpi dependency support (plotting external files and loading gpi)
# * Allow .gpi files to be ignored if called .include.gpi or .nobuild.gpi
# * Fixed sed invocations where \+ was used. BSD sed uses \{1,\}.
# Chris Monson (2006-03-28):
# * Bumped version to 2.0a2
# * Added SHELL_DEBUG and VERBOSE options
# * Changed the default shell back to /bin/sh (unset, in other words)
# * Moved .PHONY declarations closer to their targets
# * Moved help text into its own define block to obtain better formatting
# * Removed need for double-entry when adding a new program invocation
# * Moved .SECONDARY declaration closer to its relevant occurrence
# * Commented things more heavily
# * Added help text about setting terminal and output in gnuplot
# * Created more fine-grained clean targets
# * Added a %.graphics target that generates all of %'s graphics
# * Killed backward-compatible graphics generation (e.g., eps.gpi=gpi.eps)
# * For now, we're just GPL 2, not 3. Maybe it will change later
# * Made the version and svninfo into variables
# Chris Monson (2006-03-27):
# * Bumped version to 2.0a1
# * Huge, sweeping changes -- automatic dependencies
# IMPORTANT!
#
# When adding to the following list, do not introduce any blank lines. The
# list is extracted for documentation using sed and is terminated by a blank
# line.
#
# EXTERNAL PROGRAMS:
# = ESSENTIAL PROGRAMS =
# == Basic Shell Utilities ==
CAT ?= cat
CP ?= cp -f
DIFF ?= diff
ECHO ?= echo
EGREP ?= egrep
ENV ?= env
MV ?= mv -f
SED ?= sed
SORT ?= sort
TOUCH ?= touch
UNIQ ?= uniq
WHICH ?= which
XARGS ?= xargs
# == LaTeX (tetex-provided) ==
BIBTEX ?= bibtex
DVIPS ?= dvips
LATEX ?= latex
MAKEINDEX ?= makeindex
KPSEWHICH ?= kpsewhich
PS2PDF_NORMAL ?= ps2pdf
PS2PDF_EMBED13 ?= ps2pdf13
PS2PDF_EMBED ?= ps2pdf14
# = OPTIONAL PROGRAMS =
# == Makefile Color Output ==
TPUT ?= tput
# == TeX Generation ==
RST2LATEX ?= rst2latex.py
# == EPS Generation ==
DOT ?= dot # GraphViz
FIG2DEV ?= fig2dev # XFig
GNUPLOT ?= gnuplot # GNUplot
XMGRACE ?= xmgrace # XMgrace
PNGTOPNM ?= pngtopnm # From NetPBM - step 1 for png -> eps
PPMTOPGM ?= ppmtopgm # From NetPBM - (gray) step 2 for png -> eps
PNMTOPS ?= pnmtops # From NetPBM - step 3 for png -> eps
GUNZIP ?= gunzip # GZipped EPS
# == Beamer Enlarged Output ==
PSNUP ?= psnup
# == Viewing Stuff ==
VIEW_POSTSCRIPT ?= gv
VIEW_PDF ?= xpdf
VIEW_GRAPHICS ?= display
# This ensures that even when echo is a shell builtin, we still use the binary
# (the builtin doesn't always understand -n)
FIXED_ECHO := $(if $(findstring -n,$(shell $(ECHO) -n)),$(shell which echo),$(ECHO))
ECHO := $(if $(FIXED_ECHO),$(FIXED_ECHO),$(ECHO))
# Fall back to ps2pdf13 (and ultimately ps2pdf) if ps2pdf14 is not on the system:
PS2PDF_EMBED := \
$(if \
$(shell $(WHICH) $(PS2PDF_EMBED)), \
$(PS2PDF_EMBED), \
$(if \
$(shell $(WHICH) $(PS2PDF_EMBED13)), \
$(PS2PDF_EMBED13), \
$(PS2PDF_NORMAL) \
) \
)
# SH NOTES
#
# On some systems, /bin/sh, which is the default shell, is not linked to
# /bin/bash. While bash is supposed to be sh-compatible when invoked as sh, it
# just isn't. This section details some of the things you have to stay away
# from to remain sh-compatible.
#
# * File pattern expansion does not work for {}
# * [ "$x" = "$y" ] has to be [ x"$x" x"$y" ]
# * &> for stderr redirection doesn't work, use 2>&1 instead
#
# BSD SED NOTES
#
# BSD SED is not very nice compared to GNU sed, but it is the most
# commonly-invoked sed on Macs (being based on BSD), so we have to cater to
# it or require people to install GNU sed. It seems like the GNU
# requirement isn't too bad since this makefile is really a GNU makefile,
# but apparently GNU sed is much less common than GNU make in general, so
# I'm supporting it here.
#
# Sad experience has taught me the following about BSD sed:
#
# * \+ is not understood to mean \{1,\}
# * \| is meaningless (does not branch)
# * \n cannot be used as a substitution character
# * ? does not mean \{0,1\}, but is literal
# * a\ works, but only reliably for a single line if subsequent lines
# have forward slashes in them (as is the case in postscript)
#
# For more info (on the Mac) you can consult
#
# man -M /usr/share/man re_format
#
# And look for the word "Obsolete" near the bottom.
#
# EXTERNAL PROGRAM DOCUMENTATION SCRIPT
#
# $(call output-all-programs,[<output file>])
define output-all-programs
[ -f '$(this_file)' ] && \
$(SED) \
-e '/^[[:space:]]*#[[:space:]]*EXTERNAL PROGRAMS:/,/^$$/!d' \
-e '/EXTERNAL PROGRAMS/d' \
-e '/^$$/d' \
-e '/^[[:space:]]*#/i\ '\
-e 's/^[[:space:]]*#[[:space:]][^=]*//' \
$(this_file) $(if $1,> '$1',) || \
$(ECHO) "Cannot determine the name of this makefile."
endef
# If they misspell gray, it should still work.
GRAY ?= $(call get-default,$(GREY),)
#
# Utility Functions and Definitions
#
# While not exactly a make function, this vim macro is useful. It takes a
# verbatim sed script and converts each line to something suitable in a command
# context. Just paste the script's contents into the editor, yank this into a
# register (starting at '0') and run the macro once for each line of the
# original script:
#
# 0i -e :s/\$/$$/eg:s/'/'"'"'/eg^Ela'A' \:nohj
# don't call this directly - it is here to avoid calling wildcard more than
# once in remove-files.
remove-files-helper = $(if $1,$(RM) $1,:)
# $(call remove-files,file1 file2)
remove-files = $(call remove-files-helper,$(wildcard $1))
# Removes all cleanable files in the given list
# $(call clean-files,file1 file2 file3 ...)
# Works exactly like remove-files, but filters out files in $(neverclean)
clean-files = \
$(call remove-files-helper,$(call cleanable-files,$(wildcard $1)))
# This removes files without checking whether they are there or not. This
# sometimes has to be used when the file is created by a series of shell
# commands, but there ends up being a race condition: make doesn't know about
# the file generation as quickly as the system does, so $(wildcard ...) doesn't
# work right. Blech.
# $(call remove-temporary-files,filenames)
remove-temporary-files = $(if $1,$(RM) $1,:)
# Create an identifier from a file name
# $(call cleanse-filename,filename)
cleanse-filename = $(subst .,_,$(subst /,__,$1))
# Escape dots
# $(call escape-dots,str)
escape-dots = $(subst .,\\.,$1)
# Test that a file exists
# $(call test-exists,file)
test-exists = [ -e '$1' ]
# Copy file1 to file2 only if file2 doesn't exist or they are different
# $(call copy-if-different,sfile,dfile)
copy-if-different = $(call test-different,$1,$2) && $(CP) '$1' '$2'
copy-if-exists = $(call test-exists,$1) && $(CP) '$1' '$2'
move-if-different = $(call test-different,$1,$2) && $(MV) '$1' '$2'
replace-if-different-and-remove = \
$(call test-different,$1,$2) \
&& $(MV) '$1' '$2' \
|| $(call remove-files,'$1')
# Note that $(DIFF) returns success when the files are the SAME....
# $(call test-different,sfile,dfile)
test-different = ! $(DIFF) -q '$1' '$2' >/dev/null 2>&1
test-exists-and-different = \
$(call test-exists,$2) && $(call test-different,$1,$2)
# Return value 1, or value 2 if value 1 is empty
# $(call get-default,<possibly empty arg>,<default value if empty>)
get-default = $(if $1,$1,$2)
# Gives a reassuring message about the failure to find include files
# $(call include-message,<list of include files>)
define include-message
$(strip \
$(if $(filter-out $(wildcard $1),$1),\
$(shell $(ECHO) \
"$(C_INFO)NOTE: You may ignore warnings about the"\
"following files:" >&2;\
$(ECHO) >&2; \
$(foreach s,$(filter-out $(wildcard $1),$1),$(ECHO) ' $s' >&2;)\
$(ECHO) "$(C_RESET)" >&2)
))
endef
# Characters that are hard to specify in certain places
space := $(empty) $(empty)
colon := \:
comma := ,
# Useful shell definitions
sh_true := :
sh_false := ! :
# Clear out the standard interfering make suffixes
.SUFFIXES:
# Turn off forceful rm (RM is usually mapped to rm -f)
ifdef SAFE_RM
RM := rm
endif
# Turn command echoing back on with VERBOSE=1
ifndef VERBOSE
QUIET := @
endif
# Turn on shell debugging with SHELL_DEBUG=1
# (EVERYTHING is echoed, even $(shell ...) invocations)
ifdef SHELL_DEBUG
SHELL += -x
endif
# Get the name of this makefile (always right in 3.80, often right in 3.79)
# This is only really used for documentation, so it isn't too serious.
ifdef MAKEFILE_LIST
this_file := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
else
this_file := $(wildcard GNUmakefile makefile Makefile)
endif
# Terminal color definitions
ifdef NO_COLOR
tput =
else
tput = $(shell $(TPUT) $1)
endif
black := $(call tput,setaf 0)
red := $(call tput,setaf 1)
green := $(call tput,setaf 2)
yellow := $(call tput,setaf 3)
blue := $(call tput,setaf 4)
magenta := $(call tput,setaf 5)
cyan := $(call tput,setaf 6)
white := $(call tput,setaf 7)
bold := $(call tput,bold)
uline := $(call tput,smul)
reset := $(call tput,sgr0)
#
# User-settable definitions
#
LATEX_COLOR_WARNING ?= magenta
LATEX_COLOR_ERROR ?= red
LATEX_COLOR_INFO ?= green
LATEX_COLOR_UNDERFULL ?= magenta
LATEX_COLOR_OVERFULL ?= red bold
LATEX_COLOR_PAGES ?= bold
LATEX_COLOR_BUILD ?= blue
LATEX_COLOR_GRAPHIC ?= yellow
LATEX_COLOR_DEP ?= green
LATEX_COLOR_SUCCESS ?= green bold
LATEX_COLOR_FAILURE ?= red bold
# Gets the real color from a simple textual definition like those above
# $(call get-color,ALL_CAPS_COLOR_NAME)
# e.g., $(call get-color,WARNING)
get-color = $(subst $(space),,$(foreach c,$(LATEX_COLOR_$1),$($c)))
#
# STANDARD COLORS
#
C_WARNING := $(call get-color,WARNING)
C_ERROR := $(call get-color,ERROR)
C_INFO := $(call get-color,INFO)
C_UNDERFULL := $(call get-color,UNDERFULL)
C_OVERFULL := $(call get-color,OVERFULL)
C_PAGES := $(call get-color,PAGES)
C_BUILD := $(call get-color,BUILD)
C_GRAPHIC := $(call get-color,GRAPHIC)
C_DEP := $(call get-color,DEP)
C_SUCCESS := $(call get-color,SUCCESS)
C_FAILURE := $(call get-color,FAILURE)
C_RESET := $(reset)
#
# PRE-BUILD TESTS
#
# Check that clean targets are not combined with other targets (weird things
# happen, and it's not easy to fix them)
hascleangoals := $(if $(sort $(filter clean clean-%,$(MAKECMDGOALS))),1)
hasbuildgoals := $(if $(sort $(filter-out clean clean-%,$(MAKECMDGOALS))),1)
ifneq "$(hasbuildgoals)" ""
ifneq "$(hascleangoals)" ""
$(error $(C_ERROR)Clean and build targets specified together$(C_RESET)))
endif
endif
#
# VARIABLE DECLARATIONS
#
# Names of sed scripts that morph gnuplot files -- only the first found is used
GNUPLOT_SED := global-gpi.sed gnuplot.sed
GNUPLOT_GLOBAL := global._include_.gpi gnuplot.global
# Files of interest
all_files.tex := $(wildcard *.tex)
all_files.tex.sh := $(wildcard *.tex.sh)
all_files.rst := $(wildcard *.rst)
all_files.fig := $(wildcard *.fig)
all_files.gpi := $(wildcard *.gpi)
all_files.dot := $(wildcard *.dot)
all_files.xvg := $(wildcard *.xvg)
all_files.png := $(wildcard *.png)
all_files.eps.gz := $(wildcard *.eps.gz)
all_files.eps := $(wildcard *.eps)
# Utility function for obtaining all files not specified in $(neverclean)
# $(call cleanable-files,file1 file2 file3 ...)
# Returns the list of files that is not in $(wildcard $(neverclean))
cleanable-files = $(filter-out $(wildcard $(neverclean)), $1)
# Utility function for getting all .$1 files that are to be ignored
# * files listed in $(includes.$1)
# * files not listed in $(onlysources.$1) if it is defined
ignore_files = \
$(includes.$1) \
$(if $(onlysources.$1),$(filter-out $(onlysources.$1), $(all_files.$1)))
# Patterns to never be allowed as source targets
ignore_patterns := %._include_
# Patterns allowed as source targets but not included in 'all' builds
nodefault_patterns := %._nobuild_ $(ignore_patterns)
# Utility function for getting targets suitable building
# $(call filter-buildable,suffix)
filter-buildable = \
$(filter-out $(call ignore_files,$1) \
$(addsuffix .$1,$(ignore_patterns)),$(all_files.$1))
# Utility function for getting targets suitable for 'all' builds
# $(call filter-default,suffix)
filter-default = \
$(filter-out $(call ignore_files,$1) \
$(addsuffix .$1,$(nodefault_patterns)),$(all_files.$1))
# Top level sources that can be built even when they are not by default
files.tex := $(filter-out %._gray_.tex,$(call filter-buildable,tex))
files.tex.sh := $(call filter-buildable,tex.sh)
files.rst := $(call filter-buildable,rst)
files.gpi := $(call filter-buildable,gpi)
files.dot := $(call filter-buildable,dot)
files.fig := $(call filter-buildable,fig)
files.xvg := $(call filter-buildable,xvg)
files.png := $(call filter-buildable,png)
files.eps.gz := $(call filter-buildable,eps.gz)
# Make all pstex targets secondary. The pstex_t target requires the pstex
# target, and nothing else really depends on it, so it often gets deleted.
# This avoids that by allowing *all* fig files to be pstex targets, which is
# perfectly valid and causes no problems even if they're going to become eps
# files in the end.
.SECONDARY: $(patsubst %.fig,%.pstex,$(files.fig))
.SECONDARY: $(patsubst %.fig,%._gray_.pstex,$(files.fig))
# Top level sources that are built by default targets
default_files.tex := $(filter-out %._gray_.tex,$(call filter-default,tex))
default_files.tex.sh := $(call filter-default,tex.sh)
default_files.rst := $(call filter-default,rst)
default_files.gpi := $(call filter-default,gpi)
default_files.dot := $(call filter-default,dot)
default_files.fig := $(call filter-default,fig)
default_files.xvg := $(call filter-default,xvg)
default_files.png := $(call filter-default,png)
default_files.eps.gz := $(call filter-default,eps.gz)
# Utility function for creating larger lists of files
# $(call concat-files,suffixes,[prefix])
concat-files = $(foreach s,$1,$($(if $2,$2_,)files.$s))
# Useful file groupings
all_files_source := $(call concat-files,tex,all)
all_files_scripts := $(call concat-files,tex.sh rst,all)
all_files_graphics := $(call concat-files,fig gpi eps.gz xvg png dot,all)
default_files_source := $(call concat-files,tex,default)
default_files_scripts := $(call concat-files,tex.sh rst,default)
default_files_graphics := $(call concat-files,fig gpi eps.gz xvg png dot,default)
files_source := $(call concat-files,tex)
files_scripts := $(call concat-files,tex.sh rst)
files_graphics := $(call concat-files,fig gpi eps.gz xvg png dot)
# Utility function for obtaining stems
# $(call get-stems,suffix,[prefix])
get-stems = $(sort $($(if $2,$2_,)files.$1:%.$1=%))
# List of all stems (including ._include_ and ._nobuild_ file stems)
all_stems.tex := $(call get-stems,tex,all)
all_stems.tex.sh := $(call get-stems,tex.sh,all)
all_stems.rst := $(call get-stems,rst,all)
all_stems.fig := $(call get-stems,fig,all)
all_stems.gpi := $(call get-stems,gpi,all)
all_stems.dot := $(call get-stems,dot,all)
all_stems.xvg := $(call get-stems,xvg,all)
all_stems.png := $(call get-stems,png,all)
all_stems.eps.gz := $(call get-stems,eps.gz,all)
all_stems.eps := $(call get-stems,eps,all)
# List of all default stems (all default PDF targets):
default_stems.tex := $(call get-stems,tex,default)
default_stems.tex.sh := $(call get-stems,tex.sh,default)
default_stems.rst := $(call get-stems,rst,default)
default_stems.fig := $(call get-stems,fig,default)
default_stems.gpi := $(call get-stems,gpi,default)
default_stems.dot := $(call get-stems,dot,default)
default_stems.xvg := $(call get-stems,xvg,default)
default_stems.png := $(call get-stems,png,default)
default_stems.eps.gz := $(call get-stems,eps.gz,default)
# List of all stems (all possible bare PDF targets created here):
stems.tex := $(call get-stems,tex)
stems.tex.sh := $(call get-stems,tex.sh)
stems.rst := $(call get-stems,rst)
stems.fig := $(call get-stems,fig)
stems.gpi := $(call get-stems,gpi)
stems.dot := $(call get-stems,dot)
stems.xvg := $(call get-stems,xvg)
stems.png := $(call get-stems,png)
stems.eps.gz := $(call get-stems,eps.gz)
# Utility function for creating larger lists of stems
# $(call concat-stems,suffixes,[prefix])
concat-stems = $(sort $(foreach s,$1,$($(if $2,$2_,)stems.$s)))
all_stems_source := $(call concat-stems,tex,all)
all_stems_script := $(call concat-stems,tex.sh rst,all)
all_stems_graphic := $(call concat-stems,fig gpi eps.gz xvg png dot,all)
all_stems_gray_graphic := $(addsuffix ._gray_,\
$(all_stems_graphic) $(all_stems.eps) \
)
all_stems_gg := $(sort \
$(all_stems_graphic) $(all_stems_gray_graphic))
all_stems_ss := $(sort $(all_stems_source) $(all_stems_script))
all_stems_gray := $(addsuffix ._gray_,$(all_stems_ss))
all_stems_sg := $(sort $(all_stems_script) $(all_stems_gray))
all_stems_ssg := $(sort $(all_stems_ss) $(all_stems_gray))
default_stems_source := $(call concat-stems,tex,default)
default_stems_script := $(call concat-stems,tex.sh rst,default)
default_stems_graphic := $(call concat-stems,fig gpi eps.gz xvg png dot,default)
default_stems_gray_graphic := $(addsuffix ._gray_,$(default_stems_graphic))
default_stems_gg := $(sort \
$(default_stems_graphic) $(default_stems_gray_graphic))
default_stems_ss := $(sort \
$(default_stems_source) $(default_stems_script))
default_stems_gray := $(addsuffix ._gray_,$(default_stems_ss))
default_stems_sg := $(sort $(default_stems_script) $(default_stems_gray))
default_stems_ssg := $(sort $(default_stems_ss) $(default_stems_gray))
stems_source := $(call concat-stems,tex)
stems_script := $(call concat-stems,tex.sh rst)
stems_graphic := $(call concat-stems,fig gpi eps.gz xvg png dot)
stems_gray_graphic := $(addsuffix ._gray_,\
$(stems_graphic) $(all_stems.eps))
stems_gg := $(sort $(stems_graphic) $(stems_gray_graphic))
stems_ss := $(sort $(stems_source) $(stems_script))
stems_gray := $(addsuffix ._gray_,$(stems_ss))
stems_sg := $(sort $(stems_script) $(stems_gray))
stems_ssg := $(sort $(stems_ss) $(stems_gray))
# Calculate names that can generate the need for an include file. We can't
# really do this with patterns because it's too easy to screw up, so we create
# an exhaustive list.
allowed_source_suffixes := \
pdf \
ps \
dvi \
ind \
bbl \
aux \
aux.make \
d \
tex \
auxbbl.make \
_graphics \
_show
allowed_source_patterns := $(addprefix %.,$(allowed_source_suffixes))
allowed_graphic_suffixes := \
eps \
gpihead.make \
gpi.d
allowed_graphic_patterns := $(addprefix %.,$(allowed_graphic_suffixes))
# All targets allowed to build documents
allowed_source_targets := \
$(foreach suff,$(allowed_source_suffixes),\
$(addsuffix .$(suff),$(stems_ssg)))
# All targets allowed to build graphics
allowed_graphic_targets := \
$(foreach suff,$(allowed_graphic_suffixes),\
$(addsuffix .$(suff),$(stems_gg)))
# All targets that build multiple documents (like 'all')
allowed_batch_source_targets := \
all \
all-pdf \
all-ps \
all-dvi \
all-bbl \
all-ind \
show
# All targets that build multiple graphics (independent of document)
allowed_batch_graphic_targets := \
all-graphics \
all-pstex \
all-gray-pstex \
show-graphics
# Now we figure out which stuff is available as a make target for THIS RUN.
real_goals := $(call get-default,$(filter-out _includes,$(MAKECMDGOALS)),\
all)
specified_source_targets := $(strip \
$(filter $(allowed_source_targets) $(stems_ssg),$(real_goals)) \
)
specified_batch_source_targets := $(strip \
$(filter $(allowed_batch_source_targets),$(real_goals)) \
)
specified_graphic_targets := $(strip \
$(filter $(allowed_graphic_targets),$(real_goals)) \
)
specified_batch_graphic_targets := $(strip \
$(filter $(allowed_batch_graphic_targets),$(real_goals)) \
)
specified_gpi_targets := $(patsubst %.gpi,%.eps,\
$(filter $(patsubst %.eps,%.gpi,$(specified_graphic_targets)),\
$(all_files.gpi)) \
)
# Determine which .d files need including from the information gained above.
# This is done by first checking whether a batch target exists. If it does,
# then all *default* stems are used to create possible includes (nobuild need
# not apply for batch status). If no batch targets exist, then the individual
# targets are considered and appropriate includes are taken from them.
source_stems_to_include := \
$(sort\
$(if $(specified_batch_source_targets),\
$(default_stems_ss),\
$(foreach t,$(specified_source_targets),\
$(foreach p,$(allowed_source_patterns),\
$(patsubst $p,%,$(filter $p $(stems_ssg),$t)) \
)) \
))
# Determine which .gpi.d files are needed using the above information. We
# first check whether a batch target is specified, then check individual
# graphics that may have been specified.
graphic_stems_to_include := \
$(sort\
$(if $(specified_batch_graphic_targets),\
$(default_stems.gpi),\
$(foreach t,$(specified_gpi_targets),\
$(foreach p,$(allowed_graphic_patterns),\
$(patsubst $p,%,$(filter $p,$t)) \
)) \
))
# All dependencies for the 'all' targets
all_pdf_targets := $(addsuffix .pdf,$(stems_ssg))
all_ps_targets := $(addsuffix .ps,$(stems_ssg))
all_dvi_targets := $(addsuffix .dvi,$(stems_ssg))
all_tex_targets := $(addsuffix .tex,$(stems_sg))
all_d_targets := $(addsuffix .d,$(stems_ssg))
all_graphics_targets := $(addsuffix .eps,$(stems_gg))
all_pstex_targets := $(addsuffix .pstex_t,$(stems.fig))
all_gray_pstex_targets := $(addsuffix ._gray_.pstex_t,$(stems.fig))
all_known_graphics := $(sort $(all_graphics_targets) $(wildcard *.eps))
default_pdf_targets := $(addsuffix .pdf,$(default_stems_ss))
default_ps_targets := $(addsuffix .ps,$(default_stems_ss))
default_dvi_targets := $(addsuffix .dvi,$(default_stems_ss))
# Extensions generated by LaTeX invocation that can be removed when complete
rm_ext := \
log aux dvi ps pdf blg bbl out nav snm toc lof lot pfg fls vrb \
idx ind ilg lox
backup_patterns := *~ *.bak *.backup
graph_stem := _graph
# All LaTeX-generated files that can be safely removed
rm_tex := \
$(foreach e,$(rm_ext),$(addsuffix .$e,$(all_stems_source))) \
$(foreach e,$(rm_ext) tex,$(addsuffix .$e,$(all_stems_sg))) \
$(addsuffix .log,$(all_ps_targets) $(all_pdf_targets)) \
$(addsuffix .*.log,$(stems_graphic))