-
Notifications
You must be signed in to change notification settings - Fork 30
/
Makefile.in
executable file
·2503 lines (2232 loc) · 81.2 KB
/
Makefile.in
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
(##include_as_comment("copyright") ##)
#
# TO OBTAIN INSTRUCTIONS FOR USING THIS FILE, RUN:
# make help
#
fileinfo := LaTeX Makefile
author := Chris Monson
version := 2.2.2
#
.DEFAULT_GOAL := all
# Note that the user-global version is imported *after* the source directory,
# so that you can use stuff like ?= to get proper override behavior.
.PHONY: Makefile GNUmakefile Makefile.ini $(HOME)/.latex-makefile/Makefile.ini
-include Makefile.ini
-include $(HOME)/.latex-makefile/Makefile.ini
# Better names for these things
.PHONY: Variables.ini $(HOME)/.latex-makefile/Variables.ini
-include Variables.ini
-include $(HOME)/.latex-makefile/Variables.ini
#
# This can be pdflatex or latex - you can change this by adding the following
# line to your Makefile.ini or Variables.ini file:
# BUILD_STRATEGY := latex
# Note that for LuaLaTeX, you would leave this alone - the addition of lua
# scripting has no impact on the build strategy, which is still pdflatex (as
# opposed to a latex -> dvips -> ps2pdf strategy). Instead, you would change
# the PDFLATEX variable to point to lualatex. See below.
BUILD_STRATEGY ?= pdflatex
# This can be used to pass extra options to latex.
LATEX_OPTS ?=
#
# Sets LC_ALL=C, by default, so that the locale-aware tools, like sort, be
# # immune to changes to the locale in the user environment.
export LC_ALL ?= C
#
#
# 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.lhs ?=
#onlysources.tex.sh ?=
#onlysources.tex.pl ?=
#onlysources.tex.py ?=
#onlysources.rst ?=
#onlysources.mp ?=
#onlysources.fig ?=
#onlysources.gpi ?=
#onlysources.dot ?=
#onlysources.xvg ?=
#onlysources.svg ?=
#onlysources.eps.gz ?=
#onlysources.eps ?=
#
# If you list files here, they will be treated as _include_ files
#includes.tex ?= file1.tex file2.tex
#includes.lhs ?=
#includes.tex.sh ?=
#includes.tex.pl ?=
#includes.tex.py ?=
#includes.rst ?=
#includes.mp ?=
#includes.fig ?=
#includes.gpi ?=
#includes.dot ?=
#includes.xvg ?=
#includes.svg ?=
#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
#
# A space-separated list of extra files to clean - you can specify this in the
# .ini files. Make sure you escape them properly, if that's needed!
#cleanextra ?=
#
# 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.
#
# KNOWN ISSUES:
(##include_as_comment("known-issues") ##)
#
# CHANGES:
(##include_as_comment("changes") ##)
# 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
EXPR ?= expr
MV ?= mv -f
SED ?= sed
SORT ?= sort
TOUCH ?= touch
UNIQ ?= uniq
WHICH ?= which
XARGS ?= xargs
SLEEP ?= sleep
# == LaTeX (tetex-provided) ==
BIBTEX ?= bibtex
DVIPS ?= dvips
LATEX ?= latex
PDFLATEX ?= pdflatex
XELATEX ?= xelatex
EPSTOPDF ?= epstopdf
MAKEINDEX ?= makeindex
XINDY ?= xindy
KPSEWHICH ?= kpsewhich
GS ?= gs
# = OPTIONAL PROGRAMS =
# == For MikTex under Cygwin, to get path names right ==
CYGPATH ?= cygpath
# == Makefile Color Output ==
TPUT ?= tput
# == TeX Generation ==
PERL ?= perl
PYTHON ?= python
RST2LATEX ?= rst2latex.py
LHS2TEX ?= lhs2tex
# == EPS Generation ==
CONVERT ?= convert # ImageMagick
DOT ?= dot # GraphViz
DOT2TEX ?= dot2tex # dot2tex - add options (not -o) as needed
MPOST ?= mpost # MetaPost
FIG2DEV ?= fig2dev # XFig
GNUPLOT ?= gnuplot # GNUplot
INKSCAPE ?= inkscape # Inkscape (svg support)
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
# Xindy glossaries
XINDYLANG ?= english
XINDYENC ?= utf8
# If cygpath is present, then we create a path-norm function that uses it,
# otherwise the function is just a no-op. Issue 112 has details.
USE_CYGPATH := $(if $(shell $(WHICH) $(CYGPATH) 2>/dev/null),yes,)
define path-norm
$(if $(USE_CYGPATH),$(shell $(CYGPATH) -u "$1"),$1)
endef
# Command options for embedding fonts and postscript->pdf conversion
PS_EMBED_OPTIONS ?= -dPDFSETTINGS=/printer -dEmbedAllFonts=true -dSubsetFonts=true -dMaxSubsetPct=100
PS_COMPATIBILITY ?= 1.4
# If set to something, will cause temporary files to not be deleted immediately
KEEP_TEMP ?=
# Defaults for GPI
DEFAULT_GPI_EPS_FONTSIZE ?= 22
DEFAULT_GPI_PDF_FONTSIZE ?= 12
# Style file for ReST
RST_STYLE_FILE ?= $(wildcard _rststyle_._include_.tex)
# 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))
define determine-gnuplot-output-extension
$(if $(shell $(WHICH) $(GNUPLOT) 2>/dev/null),
$(if $(findstring unknown or ambiguous, $(shell $(GNUPLOT) -e "set terminal pdf" 2>&1)),
eps, pdf),
none)
endef
GNUPLOT_OUTPUT_EXTENSION ?= $(strip $(call determine-gnuplot-output-extension))
# Internal code should use this because of :=. This means that the potentially
# expensive script invocation used to determine whether pdf is available will
# only be run once.
GPI_OUTPUT_EXTENSION := $(strip $(GNUPLOT_OUTPUT_EXTENSION))
# Note, if the terminal *does* understand fsize, then we expect this call to
# create a specific error here: "fsize: expecting font size". Otherwise, we
# assume that fsize is not understood.
GPI_FSIZE_SYNTAX := $(strip \
$(if \
$(filter pdf,$(GPI_OUTPUT_EXTENSION)),\
$(if \
$(findstring fsize: expecting font size,$(shell $(GNUPLOT) -e "set terminal pdf fsize" 2>&1)),\
fsize FONTSIZE,\
font ",FONTSIZE"),\
FONTSIZE))
# Directory into which we place "binaries" if it exists.
# Note that this can be changed on the commandline or in Makefile.ini:
#
# Command line:
# make BINARY_TARGET_DIR=$HOME/pdfs myfile.pdf
#
# Also, you can specify a relative directory (relative to the Makefile):
# make BINARY_TARGET_DIR=pdfs myfile.pdf
#
# Or, you can use Makefile.ini:
#
# BINARY_TARGET_DIR := $(HOME)/bin_out
#
BINARY_TARGET_DIR ?= _out_
RESTARTS := $(if $(MAKE_RESTARTS),$(MAKE_RESTARTS),0)
# 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
#
#
# Transcript
# For debug/testing purposes: writes a message to
# filename.transcript.make for each command that was run, including
# some human-readable justification for why it had to be run.
# For example: "Running latex (log-file indicated that this is necessary)"
# Set WRITE_TRANSCRIPT to something to activate
WRITE_TRANSCRIPT ?=
# Set reason for the next run call
# $(call set-run-reason,message)
set-run-reason = export run_reason="$1"
# Log command to the transcript file
# $(call set-run-reason,command,job_name)
define transcript
$(if $(WRITE_TRANSCRIPT), \
$(ECHO) "Running $1 ($$run_reason)" >> $2.transcript.make; \
export run_reason="", \
$(sh_true))
endef
# A debugging helper - warns and returns its first arguments, optionally
# prepending the second argument as a warning prefix.
# $(call tee-warning,<expression>,[optional warning prefix])
tee-warning = $(warning $2$1)$1
# 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,$(sh_true))
# $(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)))
# Outputs all generated files to STDOUT, along with some others that are
# created by these (e.g., .idx files end up producing .ilg and .ind files).
# Discovered by reading *.fls OUTPUT lines and producing corresponding .ind
# filenames as needed.
#
# $(call get-generated-names,<source recorder file (*.fls)>)
define get-generated-names
[ -f '$1' ] && \
$(SED) \
-e '/^OUTPUT /{' \
-e ' s///' \
-e ' p' \
-e ' s/\.idx/\.ind/p' \
-e ' s/\.ind/\.ilg/p' \
-e '}' \
-e 'd' \
'$1' \
| $(SORT) | $(UNIQ)
endef
# 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 $(KEEP_TEMP),:,$(if $1,$(RM) $1,:))
# Create an identifier from a file name
# $(call cleanse-filename,filename)
cleanse-filename = $(subst .,_,$(subst /,__,$1))
# Escape dots and forward slashes.
# $(call escape-fname-regex,str)
escape-fname-regex = $(subst /,\/,$(subst .,\.,$1))
# Test that a file exists
# $(call test-exists,file)
test-exists = [ -e '$1' ]
# $(call test-not-exists,file)
test-not-exists = [ ! -e '$1' ]
# $(call test-non-empty,file)
test-non-empty = [ -s '$1' ]
# $(call move-files,source,destination)
move-if-exists = $(call test-exists,$1) && $(MV) '$1' '$2'
# 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)
# Copy a file and log what's going on
# $(call copy-with-logging,<source>,<target>)
define copy-with-logging
if [ -d '$2/' ]; then \
if $(CP) '$1' '$2/'; then \
$(ECHO) "$(C_INFO)Copied '$1' to '$2/'$(C_RESET)"; \
else \
$(ECHO) "$(C_ERROR)Failed to copy '$1' to '$2/'$(C_RESET)"; \
fi; \
fi
endef
# 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 := $(firstword $(MAKEFILE_LIST))
else
this_file := $(wildcard GNUmakefile makefile Makefile)
endif
# Terminal color definitions
REAL_TPUT := $(if $(NO_COLOR),,$(shell $(WHICH) $(TPUT)))
# $(call get-term-code,codeinfo)
# e.g.,
# $(call get-term-code,setaf 0)
get-term-code = $(if $(REAL_TPUT),$(shell $(REAL_TPUT) $1),)
black := $(call get-term-code,setaf 0)
red := $(call get-term-code,setaf 1)
green := $(call get-term-code,setaf 2)
yellow := $(call get-term-code,setaf 3)
blue := $(call get-term-code,setaf 4)
magenta := $(call get-term-code,setaf 5)
cyan := $(call get-term-code,setaf 6)
white := $(call get-term-code,setaf 7)
bold := $(call get-term-code,bold)
uline := $(call get-term-code,smul)
reset := $(call get-term-code,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 ?= cyan
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
ifeq "$(strip $(BUILD_STRATEGY))" "latex"
default_graphic_extension ?= eps
latex_build_program ?= $(LATEX)
build_target_extension ?= dvi
hyperref_driver_pattern ?= hdvips
hyperref_driver_error ?= Using dvips: specify ps2pdf in the hyperref options.
endif
ifeq "$(strip $(BUILD_STRATEGY))" "pdflatex"
default_graphic_extension ?= pdf
latex_build_program ?= $(PDFLATEX)
build_target_extension ?= pdf
hyperref_driver_pattern ?= hpdf.*
hyperref_driver_error ?= Using pdflatex: specify pdftex in the hyperref options (or leave it blank).
endif
ifeq "$(strip $(BUILD_STRATEGY))" "xelatex"
default_graphic_extension ?= pdf
latex_build_program ?= $(XELATEX)
build_target_extension ?= pdf
hyperref_driver_pattern ?= hdvipdf.*
hyperref_driver_error ?= Using pdflatex: specify pdftex in the hyperref options (or leave it blank).
endif
# Files of interest
all_files.tex ?= $(wildcard *.tex)
all_files.tex.sh ?= $(wildcard *.tex.sh)
all_files.tex.pl ?= $(wildcard *.tex.pl)
all_files.tex.py ?= $(wildcard *.tex.py)
all_files.rst ?= $(wildcard *.rst)
all_files.lhs ?= $(wildcard *.lhs)
all_files.mp ?= $(wildcard *.mp)
all_files.fig ?= $(wildcard *.fig)
all_files.gpi ?= $(wildcard *.gpi)
all_files.dot ?= $(wildcard *.dot)
all_files.xvg ?= $(wildcard *.xvg)
all_files.svg ?= $(wildcard *.svg)
all_files.dia ?= $(wildcard *.dia)
all_files.png ?= $(wildcard *.png)
all_files.jpg ?= $(wildcard *.jpg)
all_files.jpeg ?= $(wildcard *.jpeg)
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 := $(call filter-buildable,tex)
files.tex.sh := $(call filter-buildable,tex.sh)
files.tex.pl := $(call filter-buildable,tex.pl)
files.tex.py := $(call filter-buildable,tex.py)
files.rst := $(call filter-buildable,rst)
files.lhs := $(call filter-buildable,lhs)
files.gpi := $(call filter-buildable,gpi)
files.dot := $(call filter-buildable,dot)
files.mp := $(call filter-buildable,mp)
files.fig := $(call filter-buildable,fig)
files.xvg := $(call filter-buildable,xvg)
files.svg := $(call filter-buildable,svg)
files.dia := $(call filter-buildable,dia)
files.png := $(call filter-buildable,png)
files.jpg := $(call filter-buildable,jpg)
files.jpeg := $(call filter-buildable,jpeg)
files.eps.gz := $(call filter-buildable,eps.gz)
files.eps := $(call filter-buildable,eps)
# 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))
# Make all .tex targets secondary that result .rst and .lhs:
.SECONDARY: $(patsubst %.rst,%.tex,$(files.rst))
.SECONDARY: $(patsubst %.lhs,%.tex,$(files.lhs))
# Top level sources that are built by default targets
default_files.tex := $(call filter-default,tex)
default_files.tex.sh := $(call filter-default,tex.sh)
default_files.tex.pl := $(call filter-default,tex.pl)
default_files.tex.py := $(call filter-default,tex.py)
default_files.rst := $(call filter-default,rst)
default_files.lhs := $(call filter-default,lhs)
default_files.gpi := $(call filter-default,gpi)
default_files.dot := $(call filter-default,dot)
default_files.mp := $(call filter-default,mp)
default_files.fig := $(call filter-default,fig)
default_files.xvg := $(call filter-default,xvg)
default_files.svg := $(call filter-default,svg)
default_files.dia := $(call filter-default,dia)
default_files.png := $(call filter-default,png)
default_files.jpg := $(call filter-default,jpg)
default_files.jpeg := $(call filter-default,jpeg)
default_files.eps.gz := $(call filter-default,eps.gz)
default_files.eps := $(call filter-default,eps)
# 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_source_gen := $(call concat-files,rst rhs,all)
all_files_scripts := $(call concat-files,tex.sh tex.pl tex.py,all)
.PHONY: $(all_files_scripts)
default_files_source := $(call concat-files,tex,default)
default_files_source_gen := $(call concat-files,rhs lhs,default)
default_files_scripts := $(call concat-files,tex.sh tex.pl tex.py,default)
files_source := $(call concat-files,tex)
files_source_gen := $(call concat-files,rst lhs)
files_scripts := $(call concat-files,tex.sh tex.pl tex.py)
# 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.tex.pl := $(call get-stems,tex.pl,all)
all_stems.tex.py := $(call get-stems,tex.py,all)
all_stems.rst := $(call get-stems,rst,all)
all_stems.lhs := $(call get-stems,lhs,all)
all_stems.mp := $(call get-stems,mp,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.svg := $(call get-stems,svg,all)
all_stems.dia := $(call get-stems,dia,all)
all_stems.png := $(call get-stems,png,all)
all_stems.jpg := $(call get-stems,jpg,all)
all_stems.jpeg := $(call get-stems,jpeg,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.tex.pl := $(call get-stems,tex.pl,default)
default_stems.tex.py := $(call get-stems,tex.py,default)
default_stems.rst := $(call get-stems,rst,default)
default_stems.lhs := $(call get-stems,lhs,default)
default_stems.mp := $(call get-stems,mp,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.svg := $(call get-stems,svg,default)
default_stems.dia := $(call get-stems,dia,default)
default_stems.png := $(call get-stems,png,default)
default_stems.jpg := $(call get-stems,jpg,default)
default_stems.jpeg := $(call get-stems,jpeg,default)
default_stems.eps.gz := $(call get-stems,eps.gz,default)
default_stems.eps := $(call get-stems,eps,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.tex.pl := $(call get-stems,tex.pl)
stems.tex.py := $(call get-stems,tex.py)
stems.rst := $(call get-stems,rst)
stems.lhs := $(call get-stems,lhs)
stems.mp := $(call get-stems,mp)
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.svg := $(call get-stems,svg)
stems.dia := $(call get-stems,dia)
stems.png := $(call get-stems,png)
stems.jpg := $(call get-stems,jpg)
stems.jpeg := $(call get-stems,jpeg)
stems.eps.gz := $(call get-stems,eps.gz)
stems.eps := $(call get-stems,eps)
# Utility function for creating larger lists of stems
# $(call concat-stems,suffixes,[prefix])
concat-stems = $(sort $(foreach s,$1,$($(if $2,$2_,)stems.$s)))
# The most likely to be source but not finished product go first
graphic_source_extensions := mp \
fig \
gpi \
xvg \
svg \
dia \
dot \
eps.gz
ifeq "$(strip $(BUILD_STRATEGY))" "latex"
graphic_source_extensions += png jpg jpeg eps
graphic_target_extensions := eps ps
endif
ifeq "$(strip $(BUILD_STRATEGY))" "pdflatex"
graphic_source_extensions += eps
graphic_target_extensions := pdf png jpg jpeg mps tif
endif
ifeq "$(strip $(BUILD_STRATEGY))" "xelatex"
graphic_source_extensions += eps
graphic_target_extensions := pdf png jpg jpeg mps tif
endif
all_stems_source := $(call concat-stems,tex,all)
all_stems_source_gen := $(call concat-stems,rst lhs,all)
all_stems_script := $(call concat-stems,tex.sh tex.pl tex.py,all)
all_stems_graphic := $(call concat-stems,$(graphic_source_extensions),all)
all_stems_ss := $(sort $(all_stems_source) $(all_stems_source_gen) $(all_stems_script))
all_stems_sg := $(sort $(all_stems_script) $(all_stems_source_gen))
all_stems_ssg := $(sort $(all_stems_ss))
default_stems_source := $(call concat-stems,tex,default)
default_stems_source_gen := $(call concat-stems,rst lhs,default)
default_stems_script := $(call concat-stems,tex.sh tex.pl tex.py,default)
default_stems_ss := $(sort $(default_stems_source) $(default_stems_source_gen) $(default_stems_script))
default_stems_sg := $(sort $(default_stems_script) $(default_stems_source_gen))
default_stems_ssg := $(sort $(default_stems_ss))
stems_source := $(call concat-stems,tex)
stems_source_gen := $(call concat-stems,rst lhs)
stems_script := $(call concat-stems,tex.sh tex.pl tex.py)
stems_graphic := $(call concat-stems,$(graphic_source_extensions))
stems_gg := $(sort $(stems_graphic))
stems_ss := $(sort $(stems_source) $(stems_source_gen) $(stems_script))
stems_sg := $(sort $(stems_script) $(stems_source_gen))
stems_ssg := $(sort $(stems_ss))
# 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 \
nls \
bbl \
aux \
aux.make \
d \
auxbbl.make \
_graphics \
_show
allowed_source_patterns := $(addprefix %.,$(allowed_source_suffixes))
allowed_graphic_suffixes := \
pdf \
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 \
all-gls \
all-nls \
show
# All targets that build multiple graphics (independent of document)
allowed_batch_graphic_targets := \
all-graphics \
all-pstex \
all-dot2tex \
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,%.$(default_graphic_extension),\
$(filter $(patsubst %.$(default_graphic_extension),%.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 .$(default_graphic_extension),$(stems_gg))
all_pstex_targets := $(addsuffix .pstex_t,$(stems.fig))
all_dot2tex_targets := $(addsuffix .dot_t,$(stems.dot))
all_known_graphics := $(sort $(all_graphics_targets) $(wildcard *.$(default_graphic_extension)))
default_pdf_targets := $(addsuffix .pdf,$(default_stems_ss))
ifeq "$(strip $(BUILD_STRATEGY))" "latex"
default_ps_targets := $(addsuffix .ps,$(default_stems_ss))
default_dvi_targets := $(addsuffix .dvi,$(default_stems_ss))
pre_pdf_extensions := dvi ps
endif
# Extensions generated by LaTeX invocation that can be removed when complete
rm_ext := \
log *.log aux $(pre_pdf_extensions) pdf blg bbl out nav snm toc lof lot lol pfg \
fls vrb idx ind ilg glg glo gls lox nls nlo nlg brf mtc* mlf* mlt* maf brf ist fmt
backup_patterns := *~ *.bak *.backup body.tmp head.tmp
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))
# These are the files that will affect .gpi transformation for all .gpi files.
#
# Use only the first one found. Backward compatible values are at the end.
# Note that we use foreach, even though wildcard also returns a list, to ensure
# that the order in the uppercase variables is preserved. Directory listings
# provide no such guarantee, so we avoid relying on them.
gpi_sed := $(strip \
$(firstword $(foreach f,$(GNUPLOT_SED),$(wildcard $f))))
gpi_global := $(strip \
$(firstword $(foreach f,$(GNUPLOT_GLOBAL),$(wildcard $f))))
#
# Functions used in generating output
#
# Outputs all source dependencies to stdout. The first argument is the file to
# be parsed, the second is a list of files that will show up as dependencies in
# the new .d file created here.
#
# $(call get-inputs,<parsed file>,<target files>)
define get-inputs
(##include_sed("$(SED)", "get-inputs.sed", "'$1'", target_files="$2")
##) | $(SORT) | $(UNIQ)
endef
# $(call get-format,<tex file>,<target files>)
define get-format
(##include_sed("$(SED)", "get-format.sed", "'$1'", target_files="$2")
##)
endef
# $(call get-missing-inputs,<log file>,<target files>)
define get-missing-inputs
(##include_sed("$(SED)", "get-missing-inputs.sed", "'$1'", target_files="$2")
##) | $(SORT) | $(UNIQ)
endef
# Get source file for specified graphics stem.
#
# Takes the first file it finds by appending the various
# graphic_source_extensions to the stem, each in turn. Thus, the
# graphic_source_extensions is a prioritized list of possible sources for
# graphics files.
#
# $(call graphics-source,<stem>,<fls stem>)
define graphics-source-helper
$(strip $(firstword \
$(wildcard \
$(addprefix $1.,\
$(graphic_source_extensions))) \
$1 \
))
endef
define graphics-source
$(call graphics-source-helper,$(call full-path,$1,$2))
endef
# Get the target file for the specified graphics file/stem
#
# Works by first trying to determine whether any of the
# graphic_target_extensions match the "stem" (which obviously isn't, since it
# has an extension). If so, it returns the stem directly, as it is a valid
# target already.
#
# Otherwise, no extensions match the stem. We then try to match against all
# possible source *and* target extensions. If any match, the stem is extracted
# from the filename and the default_graphic_extension is appended to it.
#
# If nothing matches, the stem is assumed to actually be a stem, and the