File: latex.mk.in.in

package info (click to toggle)
latex-mk 2.1-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,988 kB
  • ctags: 243
  • sloc: sh: 4,252; makefile: 165
file content (1168 lines) | stat: -rw-r--r-- 35,274 bytes parent folder | download | duplicates (2)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
# -*- Makefile -*-
# $Id: latex.mk.in.in,v 1.68 2010/03/28 05:51:58 dan Exp $ 
#
# Makefile fragment for handling LaTeX projects
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Dan McMahill
# All rights reserved.
#
# This code is derived from software written by Dan McMahill
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#        This product includes software developed by Dan McMahill
#  4. The name of the author may not be used to endorse or promote products
#     derived from this software without specific prior written permission.
# 
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
#  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
#  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
#  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#  SUCH DAMAGE.
#


#######################################
#
# README:
#
# To use this makefile fragment, set the variable:
#	NAME	= Top level project name.  Your top level LaTeX 
#		  file should be called $(NAME).tex
#
#	TEXSRCS	= Additional LaTeX input files (.tex)
#
# and add the line:
#	.include "latex.mk"
# in your top level Makefile
#
# The following variables may be overridden in your top level Makefile
#
#  BIBTEX	= the BibTeX executable
#  BIBEX_FLAGS	= flags passed to the BibTeX executable
#  CONVERT      = the 'convert' program which is part of ImageMagick
#  DVIPDFM      = the dvipdfm executable
#  DVIPDFM_ENV  = environment variables set when running the dvipdfm executable
#  DVIPDFM_FLAGS= flags passed to the dvipdfm executable
#  DVIPS	= the dvips executable
#  DVIPS_ENV    = environment variables set when running the dvips executable
#  DVIPS_FLAGS	= flags passed to the dvips executable
#  GZIP		= gzip program
#  GV		= a postscript previewer executable
#  GV_FLAGS	= flags passed to the postscript previewer executable
#  JPG2EPS      = program and flags used to convert JPEG files to EPS
#  LATEX	= the LaTeX executable
#  LATEX_ENV	= environment variables set when running the LaTeX executable
#  LATEX_FLAGS	= flags passed to the LaTeX executable
#  LATEX2HTML   = LaTeX2HTML executable
#  LATEX2HTML_ENV
#               = environment variables set when running LATEX2HTML
#  LATEX2HTML_FLAGS
#               = flags passed to LATEX2HTML
#  LATEX2RTF    = LaTeX2RTF executable
#  LATEX2RTF_ENV
#               = environment variables set when running LATEX2RTF
#  LATEX2RTF_FLAGS
#               = flags passed to LATEX2RTF
#  LPR		= executable to print postscript files
#  LPR_FLAGS	= flags passed to the executable to print postscript files
#  MAKEIDX      = the makeindex executable
#  MAKEIDX_FLAGS= flags passed to the makeindex executable
#  MAKEGLS      = executable to create glossary
#  MAKEGLS_FLAGS= flags passed to the executable to create glossary
#  PDFLATEX     = pdflatex executable
#  PDFLATEX_ENV = environment variables set when running the PDFLaTeX executable
#  PDFLATEX_FLAGS= flags passed to the PDFLaTeX executable
#  PNG2EPS      = program and flags used to convert PNG files to EPS
#  PS2PDF	= ps2pdf executable
#  PS2PDF_FLAGS	= flags passed to the ps2pdf executable
#  TAR          = tape archiver program
#  VIEWPDF      = PDF viewer
#  VIEWPDF_FLAGS= PDF viewer flags
#  XDVI		= a .dvi previewer executable
#  XDVI_FLAGS	= flags passed to the .dvi previewer executable
#
#  USE_DVIPDFM  = set to use dvipdfm to create pdf files from dvi
#                 instead of using dvips and ps2pdf
#  USE_PDFLATEX = set to use pdflatex to create pdf files from .tex
#                 files instead of using latex, dvips and ps2pdf
#
#######################################

GMK:# figure out the name of the Makefile.  We'll need this to include
GMK:# in the tar file created as part of the 'dist' target
GMK:MAKEFILE:=	$(word 1,${MAKEFILE_LIST})

BMK:MAKECONF?=	@MAKECONF@
BMK:USER_MAKECONF?=	@USERMAKECONF@
GMK:MAKECONF?=	@GMAKECONF@
GMK:USER_MAKECONF?=	@USERGMAKECONF@

BMK:.if exists(${MAKECONF})
BMK:.include "${MAKECONF}"
BMK:.endif
BMK:
BMK:.if exists(${USER_MAKECONF})
BMK:.include "${USER_MAKECONF}"
BMK:.endif

GMK:_CONFS= $(wildcard ${MAKECONF})
GMK:_CONFS+=        $(wildcard ${USER_MAKECONF})
GMK:include ${_CONFS}

# Make sure we set at least 1 way for creating html files
BMK:.if !defined(USE_HEVEA) && !defined(USE_TEX2PAGE)
GMK:ifndef USE_HEVEA
GMK:ifndef USE_TEX2PAGE
USE_LATEX2HTML=	YES
BMK:.endif
GMK:endif
GMK:endif

# The location of the latex-mk .mk and .gmk files
# we do this instead of hard coding so the package
# can be tested before installation by setting this
# variable in a test config file
LATEX_MK_DIR?=	@pkgdatadir@

AWK?=		@AWK@
BIBTEX?=	@BIBTEX@
CONVERT?=	@CONVERT@
DVIPDFM?=	@DVIPDFM@
DVIPDFM_ENV?=	
DVIPDFM_FLAGS+=	
DVIPDFM_LANDSCAPE_FLAGS?=	-l
DVIPS?=		@DVIPS@
DVIPS_ENV?=	
DVIPS_FLAGS+=	-j0
DVIPS_LANDSCAPE_FLAGS?=	-t landscape
ECHO?=		@ECHO@
ENV_PROG?=	@ENV_PROG@
FALSE?=		@FALSE@
FIND?=		@FIND@
GREP?=		@GREP@
GV?=		@GV@
GV_FLAGS?=
GV_LANDSCAPE_FLAGS?=	-landscape
GZCAT?=		gunzip -c
GZIP?=		@GZIP@
HACHA?=		@HACHA@
HACHA_ENV?=
HACHA_FLAGS?=
HEVEA?=		@HEVEA@
HEVEA_ENV?=
HEVEA_FLAGS?=	-fix
IMAGEN?=	@IMAGEN@
JPG2EPS?=	${CONVERT} 
LATEX_MK?=	@latexmkbindir@/latex-mk
LATEX_MK_FLAGS?=
LATEX?=		@LATEX@
LATEX_ENV?=	
LATEX2HTML?=	@LATEX2HTML@
LATEX2HTML_ENV?=
LATEX2HTML_FLAGS?=-image_type png -local_icons -show_section_numbers 
LATEX2RTF?=	@LATEX2RTF@
LATEX2RTF_ENV?=
LATEX2RTF_FLAGS?=
LPR?=		@LPR@
LPR_FLAGS?=	
MAKEIDX?=	@MAKEIDX@
MAKEIDX_FLAGS?=	
MAKEGLS?=	@MAKEIDX@
MAKEGLS_FLAGS?= 
PDFLATEX?=	@PDFLATEX@
PDFLATEX_ENV?=	
PDFLATEX_FLAGS?=	
PNG2EPS?=	${CONVERT} 
POST_BIBTEX_HOOK?=
RM?=		@RM@
RMDIR?=		@RMDIR@
PS2PDF?=	@PS2PDF@
PS2PDF_FLAGS?=	
TAR?=		@TAR@
TEX2PAGE?=	@TEX2PAGE@
TEX2PAGE_ENV?=
TEX2PAGE_FLAGS?=
XDVI?=		@XDVI@
XDVI_FLAGS?=	
XDVI_LANDSCAPE_FLAGS?=	-paper usr
VIEWPDF?=	${GV}
VIEWPDF_FLAGS?=	${GV_FLAGS}
VIEWPDF_LANDSCAPE_FLAGS?=	${GV_LANDSCAPE_FLAGS}


DRAFT_STAMP_PS?=	draft_stamp.ps
DATED_DRAFT_PS?=	${LATEX_MK_DIR}/dated_draft.ps

BMK:.if !target(default)
.PHONY: default
default: all
BMK:.endif

BMK:.if !target(all)
.MAIN: all
.PHONY: all
all:: view-all
BMK:.endif

BMK:.if defined(LANDSCAPE)
GMK:ifdef LANDSCAPE
DVIPS_FLAGS+=	${DVIPS_LANDSCAPE_FLAGS}
DVIPDFM_FLAGS+=	${DVIPDFM_LANDSCAPE_FLAGS}
GV_FLAGS+=	${GV_LANDSCAPE_FLAGS}
XDVI_FLAGS+=	${XDVI_LANDSCAPE_FLAGS}
VIEWPDF_FLAGS+=	${VIEWPDF_LANDSCAPE_FLAGS}
BMK:.endif
GMK:endif

BMK:REAL_LATEX_ENV+=	LATEX=${LATEX:Q}
BMK:REAL_LATEX_ENV+=	LATEX_FLAGS=${LATEX_FLAGS}
BMK:REAL_LATEX_ENV+=	BIBTEX=${BIBTEX:Q}
BMK:REAL_LATEX_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
BMK:REAL_LATEX_ENV+=	MAKEIDX=${MAKEIDX:Q}
BMK:REAL_LATEX_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
BMK:REAL_LATEX_ENV+=	MAKEGLS=${MAKEGLS:Q}
BMK:REAL_LATEX_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
BMK:REAL_LATEX_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
BMK:REAL_LATEX_ENV+=	${LATEX_ENV}
BMK:
BMK:REAL_PDFLATEX_ENV+=	PDFLATEX=${PDFLATEX:Q}
BMK:REAL_PDFLATEX_ENV+=	PDFLATEX_FLAGS=${PDFLATEX_FLAGS}
BMK:REAL_PDFLATEX_ENV+=	BIBTEX=${BIBTEX:Q}
BMK:REAL_PDFLATEX_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
BMK:REAL_PDFLATEX_ENV+=	MAKEIDX=${MAKEIDX:Q}
BMK:REAL_PDFLATEX_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
BMK:REAL_PDFLATEX_ENV+=	MAKEGLS=${MAKEGLS:Q}
BMK:REAL_PDFLATEX_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
BMK:REAL_PDFLATEX_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
BMK:REAL_PDFLATEX_ENV+=	${PDFLATEX_ENV}
BMK:
BMK:REAL_TEX2PAGE_ENV+=	TEX2PAGE=${TEX2PAGE:Q}
BMK:REAL_TEX2PAGE_ENV+=	TEX2PAGE_FLAGS=${TEX2PAGE_FLAGS}
BMK:REAL_TEX2PAGE_ENV+=	BIBTEX=${BIBTEX:Q}
BMK:REAL_TEX2PAGE_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
BMK:REAL_TEX2PAGE_ENV+=	MAKEIDX=${MAKEIDX:Q}
BMK:REAL_TEX2PAGE_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
BMK:REAL_TEX2PAGE_ENV+=	MAKEGLS=${MAKEGLS:Q}
BMK:REAL_TEX2PAGE_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
BMK:REAL_TEX2PAGE_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
BMK:REAL_TEX2PAGE_ENV+=	${TEX2PAGE_ENV}

GMK:REAL_LATEX_ENV+=	LATEX=${LATEX}
GMK:REAL_LATEX_ENV+=	LATEX_FLAGS=${LATEX_FLAGS}
GMK:REAL_LATEX_ENV+=	BIBTEX=${BIBTEX}
GMK:REAL_LATEX_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
GMK:REAL_LATEX_ENV+=	MAKEIDX=${MAKEIDX}
GMK:REAL_LATEX_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
GMK:REAL_LATEX_ENV+=	MAKEGLS=${MAKEGLS}
GMK:REAL_LATEX_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
GMK:REAL_LATEX_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
GMK:REAL_LATEX_ENV+=	${LATEX_ENV}
GMK:
GMK:REAL_PDFLATEX_ENV+=	PDFLATEX=${PDFLATEX}
GMK:REAL_PDFLATEX_ENV+=	PDFLATEX_FLAGS=${PDFLATEX_FLAGS}
GMK:REAL_PDFLATEX_ENV+=	BIBTEX=${BIBTEX}
GMK:REAL_PDFLATEX_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
GMK:REAL_PDFLATEX_ENV+=	MAKEIDX=${MAKEIDX}
GMK:REAL_PDFLATEX_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
GMK:REAL_PDFLATEX_ENV+=	MAKEGLS=${MAKEGLS}
GMK:REAL_PDFLATEX_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
GMK:REAL_PDFLATEX_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
GMK:REAL_PDFLATEX_ENV+=	${PDFLATEX_ENV}
GMK:
GMK:REAL_TEX2PAGE_ENV+=	TEX2PAGE=${TEX2PAGE}
GMK:REAL_TEX2PAGE_ENV+=	TEX2PAGE_FLAGS=${TEX2PAGE_FLAGS}
GMK:REAL_TEX2PAGE_ENV+=	BIBTEX=${BIBTEX}
GMK:REAL_TEX2PAGE_ENV+=	BIBTEX_FLAGS=${BIBTEX_FLAGS}
GMK:REAL_TEX2PAGE_ENV+=	MAKEIDX=${MAKEIDX}
GMK:REAL_TEX2PAGE_ENV+=	MAKEIDX_FLAGS=${MAKEIDX_FLAGS}
GMK:REAL_TEX2PAGE_ENV+=	MAKEGLS=${MAKEGLS}
GMK:REAL_TEX2PAGE_ENV+=	MAKEGLS_FLAGS=${MAKEGLS_FLAGS}
GMK:REAL_TEX2PAGE_ENV+=	POST_BIBTEX_HOOK=${POST_BIBTEX_HOOK}
GMK:REAL_TEX2PAGE_ENV+=	${TEX2PAGE_ENV}

# Include other .mk files often times used with LaTeX

#######################################
#
# Check for lgrind
#
#######################################

# Check for LGRINDSRCS and LGRINDDIRS

BMK:.if defined(LGRINDSRCS) || defined(LGRINDDIRS)
BMK:_USE_LGRIND_MK=	YES
BMK:.endif

GMK:ifdef LGRINDSRCS
GMK:_USE_LGRIND_MK+=	YES
GMK:endif
GMK:ifdef LGRINDDIRS
GMK:_USE_LGRIND_MK+=	YES
GMK:endif

# Check for proj_LGRINDSRCS and proj_LGRINDDIRS

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(${__tmp__}_LGRINDSRCS) || defined(${__tmp__}_LGRINDDIRS)
BMK:_USE_LGRIND_MK=	YES
BMK:.endif
BMK:.endfor

GMK:
GMK:define add_lgrind_mk_template
GMK:ifdef $(1)_LGRINDSRCS
GMK:_USE_LGRIND_MK=	YES
GMK:endif
GMK:ifdef $(1)_LGRINDDIRS
GMK:_USE_LGRIND_MK=	YES
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call add_lgrind_mk_template,$(__tmp__))))

# pull in lgrind.[g]mk if needed

BMK:.if defined(_USE_LGRIND_MK)
BMK:.include "${LATEX_MK_DIR}/lgrind.mk"
BMK:.endif
GMK:ifdef _USE_LGRIND_MK
GMK:include ${LATEX_MK_DIR}/lgrind.gmk
GMK:endif

#######################################
#
# Check for METAPOST
#
#######################################

# Check for MPOSTSRCS and MPOSTDIRS

BMK:.if defined(MPOSTSRCS) || defined(MPOSTDIRS)
BMK:_USE_MPOST_MK=	YES
BMK:.endif

GMK:ifdef MPOSTSRCS
GMK:_USE_MPOST_MK+=	YES
GMK:endif
GMK:ifdef MPOSTDIRS
GMK:_USE_MPOST_MK+=	YES
GMK:endif

# Check for proj_MPOSTSRCS and proj_MPOSTDIRS

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(${__tmp__}_MPOSTSRCS) || defined(${__tmp__}_MPOSTDIRS)
BMK:_USE_MPOST_MK=	YES
BMK:.endif
BMK:.endfor

GMK:
GMK:define add_mpost_mk_template
GMK:ifdef $(1)_MPOSTSRCS
GMK:_USE_MPOST_MK=	YES
GMK:endif
GMK:ifdef $(1)_MPOSTDIRS
GMK:_USE_MPOST_MK=	YES
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call add_mpost_mk_template,$(__tmp__))))

# pull in mpost.[g]mk if needed

BMK:.if defined(_USE_MPOST_MK)
BMK:.include "${LATEX_MK_DIR}/mpost.mk"
BMK:.endif
GMK:ifdef _USE_MPOST_MK
GMK:include ${LATEX_MK_DIR}/mpost.gmk
GMK:endif

#######################################
#
# Check for tgif
#
#######################################

# Check for TGIFSRCS and TGIFDIRS

BMK:.if defined(TGIFSRCS) || defined(TGIFDIRS)
BMK:_USE_TGIF_MK=	YES
BMK:.endif

GMK:ifdef TGIFSRCS
GMK:_USE_TGIF_MK+=	YES
GMK:endif
GMK:ifdef TGIFDIRS
GMK:_USE_TGIF_MK+=	YES
GMK:endif

# Check for proj_TGIFSRCS and proj_TGIFDIRS

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(${__tmp__}_TGIFSRCS) || defined(${__tmp__}_TGIFDIRS)
BMK:_USE_TGIF_MK=	YES
BMK:.endif
BMK:.endfor

GMK:
GMK:define add_tgif_mk_template
GMK:ifdef $(1)_TGIFSRCS
GMK:_USE_TGIF_MK=	YES
GMK:endif
GMK:ifdef $(1)_TGIFDIRS
GMK:_USE_TGIF_MK=	YES
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call add_tgif_mk_template,$(__tmp__))))

# pull in tgif.[g]mk if needed

BMK:.if defined(_USE_TGIF_MK)
BMK:.error Support for tgif files is not available, see https://bugs.debian.org/768690
BMK:.include "${LATEX_MK_DIR}/tgif.mk"
BMK:.endif
GMK:ifdef _USE_TGIF_MK
GMK:$(error Support for tgif files is not available, see https://bugs.debian.org/768690)
GMK:include ${LATEX_MK_DIR}/tgif.gmk
GMK:endif

#######################################
#
# Check for xfig
#
#######################################

# Check for XFIGSRCS and XFIGDIRS

BMK:.if defined(XFIGSRCS) || defined(XFIGDIRS)
BMK:_USE_XFIG_MK=	YES
BMK:.endif

GMK:ifdef XFIGSRCS
GMK:_USE_XFIG_MK+=	YES
GMK:endif
GMK:ifdef XFIGDIRS
GMK:_USE_XFIG_MK+=	YES
GMK:endif

# Check for proj_XFIGSRCS and proj_XFIGDIRS

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(${__tmp__}_XFIGSRCS) || defined(${__tmp__}_XFIGDIRS)
BMK:_USE_XFIG_MK=	YES
BMK:.endif
BMK:.endfor

GMK:
GMK:define add_xfig_mk_template
GMK:ifdef $(1)_XFIGSRCS
GMK:_USE_XFIG_MK=	YES
GMK:endif
GMK:ifdef $(1)_XFIGDIRS
GMK:_USE_XFIG_MK=	YES
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call add_xfig_mk_template,$(__tmp__))))

# pull in xfig.[g]mk if needed

BMK:.if defined(_USE_XFIG_MK)
BMK:.include "${LATEX_MK_DIR}/xfig.mk"
BMK:.endif
GMK:ifdef _USE_XFIG_MK
GMK:include ${LATEX_MK_DIR}/xfig.gmk
GMK:endif

#######################################
#
# Targets
#
#######################################

#######################################
# target:  view_<proj>
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:.PHONY: view_${__tmp__}
BMK:.if defined(USE_PDFLATEX)
BMK:view_${__tmp__}: viewpdf_${__tmp__}
BMK:.else
BMK:view_${__tmp__}: ${__tmp__}.dvi
BMK:	${XDVI:Q} ${XDVI_FLAGS} ${__tmp__}.dvi
BMK:.endif
BMK:DEFAULTVIEW?=	view_${__tmp__}
BMK:ALLVIEW+=	view_${__tmp__}
BMK:.endfor

GMK:define view_template
GMK:.PHONY: view_$(1)
GMK:ifdef USE_PDFLATEX
GMK:view_$(1): viewpdf_$(1)
GMK:else
GMK:view_$(1): $(1).dvi
GMK:	$(XDVI) $(XDVI_FLAGS) $(1).dvi
GMK:endif
GMK:ALLVIEW+= view_$(1)
GMK:DEFAULTVIEW?=	view_$(1)
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call view_template,$(__tmp__))))

#######################################
# target:  viewps_<proj>
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:.PHONY: viewps_${__tmp__}
BMK:viewps_${__tmp__}: ${__tmp__}.ps
BMK:	${GV:Q} ${GV_FLAGS}  ${__tmp__}.ps
BMK:DEFAULTVIEWPS?=	viewps_${__tmp__}
BMK:ALLVIEWPS+=	viewps_${__tmp__}
BMK:.PHONY: viewps_${__tmp__}-draft
BMK:viewps_${__tmp__}-draft: ${__tmp__}-draft.ps
BMK:	${GV:Q} ${GV_FLAGS}  ${__tmp__}-draft.ps
BMK:DEFAULTVIEWPS_DRAFT?=	viewps_${__tmp__}-draft
BMK:ALLVIEWPS_DRAFT+=	viewps_${__tmp__}-draft
BMK:${__tmp__}-draft.ps: ${__tmp__}.dvi ${DATED_DRAFT_PS}
BMK:	sed "s;DATE;`date`;g" ${DATED_DRAFT_PS:Q} > ${DRAFT_STAMP_PS:Q}
BMK:	${ENV_PROG:Q} ${DVIPS_ENV} ${DVIPS:Q} -h ${DRAFT_STAMP_PS:Q} ${$*_DVIPS_FLAGS} ${DVIPS_FLAGS} -o $@ ${__tmp__}.dvi
BMK:.endfor

GMK:define viewps_template
GMK:.PHONY: viewps_$(1)
GMK:viewps_$(1): $(1).ps
GMK:	$(GV) $(GV_FLAGS)  $(1).ps
GMK:DEFAULTVIEWPS?=	viewps_$(1)
GMK:ALLVIEWPS+=	viewps_$(1)
GMK:.PHONY: viewps_$(1)-draft
GMK:viewps_$(1)-draft: $(1)-draft.ps
GMK:	$(GV) $(GV_FLAGS)  $(1)-draft.ps
GMK:DEFAULTVIEWPS_DRAFT?=	viewps_$(1)-draft
GMK:ALLVIEWPS_DRAFT+=	viewps_$(1)-draft
GMK:$(1)-draft.ps: $(1).dvi ${DATED_DRAFT_PS}
GMK:	sed "s;DATE;`date`;g" ${DATED_DRAFT_PS} > ${DRAFT_STAMP_PS}
GMK:	${ENV_PROG} ${DVIPS_ENV} $(DVIPS) -h ${DRAFT_STAMP_PS} ${$*_DVIPS_FLAGS} $(DVIPS_FLAGS) -o $(1)-draft.ps $(1).dvi
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call viewps_template,$(__tmp__))))

#######################################
# target:  viewpdf_<proj>
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:.PHONY: viewpdf_${__tmp__}
BMK:viewpdf_${__tmp__}: ${__tmp__}.pdf
BMK:	${VIEWPDF:Q} ${VIEWPDF_FLAGS}  ${__tmp__}.pdf
BMK:DEFAULTVIEWPDF?=	viewpdf_${__tmp__}
BMK:ALLVIEWPDF+=	viewpdf_${__tmp__}
BMK:.PHONY: viewpdf_${__tmp__}-draft
BMK:viewpdf_${__tmp__}-draft: ${__tmp__}-draft.pdf
BMK:	${VIEWPDF:Q} ${VIEWPDF_FLAGS}  ${__tmp__}-draft.pdf
BMK:DEFAULTVIEWPDF_DRAFT?=	viewpdf_${__tmp__}-draft
BMK:ALLVIEWPDF_DRAFT+=	viewpdf_${__tmp__}-draft
BMK:.endfor

GMK:define viewpdf_template
GMK:.PHONY: viewpdf_$(1)
GMK:viewpdf_$(1): $(1).pdf
GMK:	$(VIEWPDF) $(VIEWPDF_FLAGS)  $(1).pdf
GMK:DEFAULTVIEWPDF?=	viewpdf_$(1)
GMK:ALLVIEWPDF+=	viewpdf_$(1)
GMK:.PHONY: viewpdf_$(1)-draft
GMK:viewpdf_$(1)-draft: $(1)-draft.pdf
GMK:	$(VIEWPDF) $(VIEWPDF_FLAGS)  $(1)-draft.pdf
GMK:DEFAULTVIEWPDF_DRAFT?=	viewpdf_$(1)-draft
GMK:ALLVIEWPDF_DRAFT+=	viewpdf_$(1)-draft
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call viewpdf_template,$(__tmp__))))

#######################################
# target:  print_<proj>
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:.PHONY: print_${__tmp__}
BMK:print_${__tmp__}: ${__tmp__}.ps
BMK:	${LPR:Q} ${LPR_FLAGS} ${__tmp__}.ps
BMK:DEFAULTPRINT?=	print_${__tmp__}
BMK:ALLPRINT+=	print_${__tmp__}
BMK:.PHONY: print_${__tmp__}-draft
BMK:print_${__tmp__}-draft: ${__tmp__}-draft.ps
BMK:	${LPR:Q} ${LPR_FLAGS} ${__tmp__}-draft.ps
BMK:DEFAULTPRINT_DRAFT?=	print_${__tmp__}-draft
BMK:ALLPRINT_DRAFT+=	print_${__tmp__}-draft
BMK:.endfor


GMK:define print_template
GMK:.PHONY: print_$(1)
GMK:print_$(1): $(1).ps
GMK:	$(LPR) $(LPR_FLAGS) $(1).ps
GMK:DEFAULTPRINT?=	print_$(1)
GMK:ALLPRINT+=	print_$(1)
GMK:.PHONY: print_$(1)-draft
GMK:print_$(1)-draft: $(1)-draft.ps
GMK:	$(LPR) $(LPR_FLAGS) $(1)-draft.ps
GMK:DEFAULTPRINT_DRAFT?=	print_$(1)-draft
GMK:ALLPRINT_DRAFT+=	print_$(1)-draft
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call print_template,$(__tmp__))))

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

ALLTEXSRCS=	${TEXSRCS}
ALLBIBTEXSRCS=	${BIBTEXSRCS}

#######################################
#
# master name for the distfile
#
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(ALLNAME)
BMK:ALLNAME:=       ${ALLNAME}_${__tmp__}
BMK:.else
BMK:ALLNAME=        ${__tmp__}
BMK:.endif
BMK:.endfor

GMK:define distname_template
GMK:ifdef ALLNAME
GMK:ALLNAME:=       ${ALLNAME}_$(1)
GMK:else
GMK:ALLNAME=        $(1)
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call distname_template,$(__tmp__))))

BMK:.if ${ALLNAME} != ${NAME}
GMK:ifneq (${ALLNAME}, ${NAME})
dist:	${ALLNAME}.tar.gz
${ALLNAME}.tar.gz: ${NAME:=.tar.gz}
GMK:	${RM} -fr ${ALLNAME}
BMK:	${RM:Q} -fr ${ALLNAME:Q}
GMK:	mkdir ${ALLNAME}
BMK:	mkdir ${ALLNAME:Q}
	for f in ${NAME:=.tar.gz} ; do \
GMK:		${GZCAT} $$f | (cd ${ALLNAME} && ${TAR} xpf -) ; \
BMK:		${GZCAT:Q} $$f | (cd ${ALLNAME:Q} && ${TAR:Q} xpf -) ; \
	done
GMK:	${TAR} cf - ${ALLNAME} | ${GZIP} > $@
BMK:	${TAR:Q} cf - ${ALLNAME:Q} | ${GZIP:Q} > $@
GMK:	${RM} -fr ${ALLNAME}
BMK:	${RM:Q} -fr ${ALLNAME:Q}
GMK:	@${ECHO} "******* Distfile left in ${ALLNAME}.tar.gz *******"
BMK:	@${ECHO:Q} "******* Distfile left in ${ALLNAME}.tar.gz *******"
GMK:endif
BMK:.endif

#######################################
#
# add the dependencies for each documents .dvi file
#
#######################################

BMK:.for __tmp__ in ${NAME}
BMK:${__tmp__}.dvi:	${__tmp__}.tex ${TEXSRCS} ${${__tmp__}_TEXSRCS} ${OTHER} ${${__tmp__}_OTHER}
BMK:# some older bmake versions will fail on the empty test if these variables
BMK:# do not already exist
BMK:BIBTEXSRCS?=
BMK:${__tmp__}_BIBTEXSRCS?=
BMK:.if !empty(BIBTEXSRCS) || !empty(${__tmp__}_BIBTEXSRCS)
BMK:${__tmp__}.dvi:		${__tmp__}.bib-stamp
BMK:${__tmp__}.html-stamp:	${__tmp__}.bib-stamp
BMK:.endif
BMK:.if defined(USE_PDFLATEX)
BMK:${__tmp__}.pdf:	${__tmp__}.tex ${TEXSRCS} ${${__tmp__}_TEXSRCS} ${OTHER} ${${__tmp__}_OTHER}
BMK:.  if !empty(BIBTEXSRCS) || !empty(${__tmp__}_BIBTEXSRCS)
BMK:${__tmp__}.pdf:	${__tmp__}.bib-stamp
BMK:.  endif
BMK:.endif
BMK:${__tmp__}.html-stamp:	${__tmp__}.tex ${TEXSRCS} ${${__tmp__}_TEXSRCS} ${OTHER} ${${__tmp__}_OTHER}
BMK:${__tmp__}.bib-stamp:	${BIBTEXSRCS} ${${__tmp__}_BIBTEXSRCS}
BMK:.if defined(USE_PDFLATEX)
BMK:	${ENV_PROG:Q} ${REAL_PDFLATEX_ENV} ${LATEX_MK:Q} ${LATEX_MK_FLAGS} --pdflatex --bibtex ${__tmp__}.tex
BMK:.else
BMK:	${ENV_PROG:Q} ${REAL_LATEX_ENV} ${LATEX_MK:Q} ${LATEX_MK_FLAGS} --bibtex ${__tmp__}.tex
BMK:.endif
BMK:	touch $@
BMK:
BMK:ALLTEXSRCS+=	${__tmp__}.tex ${${__tmp__}_TEXSRCS}
BMK:ALLBIBTEXSRCS+=	${${__tmp__}_BIBTEXSRCS}
BMK:dist:	${__tmp__}.tar.gz
BMK:dvi:	${__tmp__}.dvi
BMK:html:	${__tmp__}.html-stamp
BMK:.PHONY: ${__tmp__}.html
BMK:${__tmp__}.html:	${__tmp__}.html-stamp
BMK:
BMK:# latex2html needs latex to run first because it makes use of the
BMK:# .aux file.  It seems that tex2page and hevea do not require this.
BMK:.if defined(USE_LATEX2HTML)
BMK:${__tmp__}.html-stamp:	${__tmp__}.dvi
BMK:.endif
BMK:ps:	${__tmp__}.ps
BMK:pdf:	${__tmp__}.pdf
BMK:ps-draft:	${__tmp__}-draft.ps
BMK:pdf-draft:	${__tmp__}-draft.pdf
BMK:${__tmp__}.rtf:	${__tmp__}.dvi
BMK:rtf:	${__tmp__}.rtf
BMK:clean::
BMK:	if [ -f ${__tmp__}.www_files ]; then  \
BMK:		for f in `${AWK:Q} '{print $$2}' ${__tmp__}.www_files` ; do \
BMK:			if [ -f $$f ]; then ${RM:Q} -f $$f ; fi ;\
BMK:		done ;\
BMK:	fi
BMK:	${RM:Q} -f ${__tmp__}.www_files
BMK:.if defined(USE_LATEX2HTML)
BMK:	${RM:Q} -f ${__tmp__}.html_dir/images.aux
BMK:	${RM:Q} -f ${__tmp__}.html_dir/images.bbl
BMK:	${RM:Q} -f ${__tmp__}.html_dir/images.log
BMK:	${RM:Q} -f ${__tmp__}.html_dir/images.out
BMK:	${RM:Q} -f ${__tmp__}.html_dir/images.tex
BMK:.endif
BMK:	if [ -d ${__tmp__}.html_dir ]; then ${RMDIR:Q} ${__tmp__}.html_dir ; fi
BMK:
BMK:# And add dependencies for a source tarball
BMK:${__tmp__}_DIST+=	${__tmp__}.tex ${TEXSRCS} ${${__tmp__}_TEXSRCS} ${BIBTEXSRCS} ${${__tmp__}_BIBTEXSRCS} ${OTHER} ${${__tmp__}_OTHER} ${MAKEFILE} ${${__tmp__}_EXTRA_DIST} ${EXTRA_DIST}
BMK:ALL_DIST+=	${${__tmp__}_DIST}
BMK:
BMK:${__tmp__}.tar.gz: ${${__tmp__}_DIST}
BMK:	${TAR:Q} cf - ${${__tmp__}_DIST} | ${GZIP:Q} > $@
BMK:	@${ECHO:Q} "******* Distfile left in $@ *******"
BMK:.endfor

GMK:define dvideps_template
GMK:$(1).dvi:	$(1).tex ${TEXSRCS} ${$(1)_TEXSRCS} ${OTHER} ${$(1)_OTHER}
GMK:ifneq ($(strip $(BIBTEXSRCS)$($(1)_BIBTEXSRCS)),)
GMK:$(1).dvi:		$(1).bib-stamp
GMK:$(1).html-stamp:	$(1).bib-stamp
GMK:endif
GMK:ifdef USE_PDFLATEX
GMK:$(1).pdf:	$(1).tex ${TEXSRCS} ${$(1)_TEXSRCS} ${OTHER} ${$(1)_OTHER}
GMK:ifneq ($(strip $(BIBTEXSRCS)$($(1)_BIBTEXSRCS)),)
GMK:$(1).pdf:		$(1).bib-stamp
GMK:endif
GMK:endif
GMK:$(1).html-stamp:	$(1).tex ${TEXSRCS} ${$(1)_TEXSRCS} ${OTHER} ${$(1)_OTHER}
GMK:$(1).bib-stamp:	${BIBTEXSRCS} ${$(1)_BIBTEXSRCS}
GMK:ifdef USE_PDFLATEX
GMK:	$(ENV_PROG) $(REAL_PDFLATEX_ENV) $(LATEX_MK) $(LATEX_MK_FLAGS) --pdflatex --bibtex $(1).tex
GMK:else
GMK:	$(ENV_PROG) $(REAL_LATEX_ENV) $(LATEX_MK) $(LATEX_MK_FLAGS) --bibtex $(1).tex
GMK:endif
GMK:	touch $(1).bib-stamp
GMK:
GMK:ALLTEXSRCS+=	$(1).tex ${$(1)_TEXSRCS}
GMK:ALLBIBTEXSRCS+=	${$(1)_BIBTEXSRCS}
GMK:dist:	$(1).tar.gz
GMK:dvi:	$(1).dvi
GMK:html:	$(1).html-stamp
GMK:# latex2html needs latex to run first because it makes use of the
GMK:# .aux file.  It seems that tex2page and hevea do not require this.
GMK:ifdef USE_LATEX2HTML
GMK:$(1).html-stamp:	$(1).dvi
GMK:endif
GMK:.PHONY: $(1).html
GMK:$(1).html:	$(1).html-stamp
GMK:ps:	$(1).ps
GMK:pdf:	$(1).pdf
GMK:ps-draft:	$(1)-draft.ps
GMK:pdf-draft:	$(1)-draft.pdf
GMK:$(1).rtf:	$(1).dvi
GMK:rtf:	$(1).rtf
GMK:clean::
GMK:	if [ -f $(1).www_files ]; then  \
GMK:		for f in `${AWK} '{print $$2}' $(1).www_files` ; do \
GMK:			if [ -f $$$$f ]; then ${RM} -f $$$$f ; fi ;\
GMK:		done ;\
GMK:	fi
GMK:	${RM} -f $(1).www_files
GMK:ifdef USE_LATEX2HTML
GMK:	${RM} -f $(1).html_dir/images.aux
GMK:	${RM} -f $(1).html_dir/images.bbl
GMK:	${RM} -f $(1).html_dir/images.log
GMK:	${RM} -f $(1).html_dir/images.out
GMK:	${RM} -f $(1).html_dir/images.tex
GMK:endif
GMK:	if [ -d $(1).html_dir ] ; then ${RMDIR} $(1).html_dir ; fi
GMK:
GMK:# And add dependencies for a source tarball
GMK:$(1)_DIST+=	$(1).tex ${TEXSRCS} ${$(1)_TEXSRCS} ${BIBTEXSRCS} ${$(1)_BIBTEXSRCS} ${OTHER} ${$(1)_OTHER} ${MAKEFILE} ${$(1)_EXTRA_DIST} ${EXTRA_DIST}
GMK:
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call dvideps_template,$(__tmp__))))

GMK:define dist_template
GMK:ALL_DIST+=	$($(1)_DIST)
GMK:
GMK:$(1).tar.gz: $($(1)_DIST)
GMK:	${TAR} cf - ${$(1)_DIST} | ${GZIP} > $(1).tar.gz
GMK:	@${ECHO} "******* Distfile left in $(1).tar.gz *******"
GMK:
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call dist_template,$(__tmp__))))

#######################################
# target:  view, view-all
#######################################

.PHONY: view
view: ${DEFAULTVIEW}
.PHONY: view-all
view-all: ${ALLVIEW}


#######################################
# target:  viewps, viewps-all
#######################################

.PHONY: viewps
viewps: ${DEFAULTVIEWPS}
.PHONY: viewps-all
viewps-all: ${ALLVIEWPS}

#######################################
# target:  viewpdf, viewpdf-all
#######################################

.PHONY: viewpdf
viewpdf: ${DEFAULTVIEWPDF}
.PHONY: viewpdf-all
viewpdf-all: ${ALLVIEWPDF}

#######################################
# target:  viewps-draft, viewps-all-draft
#######################################

.PHONY: viewps-draft
viewps-draft: ${DEFAULTVIEWPS_DRAFT}
.PHONY: viewps-all-draft
viewps-all-draft: ${ALLVIEWPS_DRAFT}

#######################################
# target:  viewpdf-draft, viewpdf-all-draft
#######################################

.PHONY: viewpdf-draft
viewpdf-draft: ${DEFAULTVIEWPDF_DRAFT}
.PHONY: viewpdf-all-draft
viewpdf-all-draft: ${ALLVIEWPDF_DRAFT}

#######################################
# target:  print, print-all
#######################################

.PHONY: print
print: ${DEFAULTPRINT}
.PHONY: print-all
print-all: ${ALLPRINT}

#######################################
# target:  print-draft, print-all-draft
#######################################

.PHONY: print-draft
print-draft: ${DEFAULTPRINT_DRAFT}
.PHONY: print-all-draft
print-all-draft: ${ALLPRINT_DRAFT}

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

.SUFFIXES : .tex .dvi .ps .pdf .rtf .html-stamp .png .jpg .eps

BMK:.if defined(IGNORE_LATEX_ERRORS)
GMK:ifdef IGNORE_LATEX_ERRORS
LATEX_MK_FLAGS+=	--ignore-errors
BMK:.endif
GMK:endif

#######################################
#
# Graphic file conversions
#
#######################################
.jpg.eps : 
GMK:	$(JPG2EPS) $< $@
BMK:	${JPG2EPS:Q} $< $@

.png.eps : 
GMK:	$(PNG2EPS) $< $@
BMK:	${PNG2EPS:Q} $< $@

#######################################
#
# Distribution output (tarfile)
#
#######################################
.PHONY: dist

#######################################
#
# DVI Output (latex)
#
#######################################
.PHONY: dvi
.tex.dvi : 
GMK:	$(ENV_PROG) $(REAL_LATEX_ENV) $(LATEX_MK) $(LATEX_MK_FLAGS) $<
BMK:	${ENV_PROG:Q} ${REAL_LATEX_ENV} ${LATEX_MK:Q} ${LATEX_MK_FLAGS} $<

#######################################
#
# HTML Output (latex2html or HeVeA)
#
#######################################

# note:  we have to use a time stamp file here to keep track of what files
# get created by the html conversion.  Neither latex2html nor hevea provide
# a convenient way to get a list of files to clean.  In addition, hevea
# does not currently provide a DESTDIR type functionality which is needed
# for dealing with multiple top level documents.


.PHONY: html
.tex.html-stamp : 
	touch $@1
BMK:.if defined(USE_LATEX2HTML)
GMK:ifdef USE_LATEX2HTML
GMK:	@${ECHO} LaTeX-Mk:  Creating HTML output using latex2html
GMK:	$(ENV_PROG) $(LATEX2HTML_ENV) $(LATEX2HTML) $(LATEX2HTML_FLAGS) -mkdir -dir $*.html_dir $<
BMK:	@${ECHO:Q} LaTeX-Mk:  Creating HTML output using latex2html
BMK:	${ENV_PROG:Q} ${LATEX2HTML_ENV} ${LATEX2HTML:Q} ${LATEX2HTML_FLAGS} -mkdir -dir $*.html_dir $<
BMK:.elif defined(USE_TEX2PAGE)
GMK:else
GMK:ifdef USE_TEX2PAGE
GMK:	@${ECHO} LaTeX-Mk:  Creating HTML output using tex2page
GMK:	${ECHO} "$*.html_dir" > $*.hdir
GMK:	$(ENV_PROG) $(REAL_TEX2PAGE_ENV) $(LATEX_MK) --tex2page $(LATEX_MK_FLAGS) $<
BMK:	@${ECHO:Q} LaTeX-Mk:  Creating HTML output using tex2page
BMK:	${ECHO:Q} "$*.html_dir" > $*.hdir
BMK:	${ENV_PROG:Q} ${REAL_TEX2PAGE_ENV} ${LATEX_MK:Q} --tex2page ${LATEX_MK_FLAGS} $<
BMK:.elif defined(USE_HEVEA)
GMK:else
GMK:ifdef USE_HEVEA
GMK:	@${ECHO} LaTeX-Mk:  Creating HTML output using HeVeA
BMK:	@${ECHO:Q} LaTeX-Mk:  Creating HTML output using HeVeA
	mkdir -p $*.html_dir
GMK:	-$(ENV_PROG) $(HEVEA_ENV) $(HEVEA) $(HEVEA_FLAGS) $< 
GMK:	-$(ENV_PROG) $(HEVEA_ENV) ${IMAGEN}  `basename $< .tex`
GMK:	-$(ENV_PROG) $(HEVEA_ENV) $(HEVEA) $(HEVEA_FLAGS) $< 
BMK:	-${ENV_PROG:Q} ${HEVEA_ENV} ${HEVEA:Q} $(HEVEA_FLAGS) $< 
BMK:	-${ENV_PROG:Q} ${HEVEA_ENV} ${IMAGEN:Q}  `basename $< .tex`
BMK:	-${ENV_PROG:Q} ${HEVEA_ENV} ${HEVEA:Q} $(HEVEA_FLAGS) $< 
BMK:.endif
GMK:endif
GMK:endif
GMK:endif
	if [ ! -f $*.www_files ]; then touch $*.www_files ; fi
GMK:	for f in `${FIND} . -type f \( -name \*.html -o -name \*.htm -o -name \*.gif \
BMK:	for f in `${FIND:Q} . -type f \( -name \*.html -o -name \*.htm -o -name \*.gif \
		-o -name \*.png -o -name \*.css -o -name \*.pl -o -name WARNINGS \
		-o -name \*.scm -o -name \*.hlog \) \
		-newer $@1 -print` ; do \
		fn=`basename $$f` ; \
GMK:		if ${GREP} "^$$f " $*.www_files >/dev/null ; then \
BMK:		if ${GREP:Q} "^$$f " $*.www_files >/dev/null ; then \
			echo "$$f already recorded" ; \
		else \
			echo "recording file $$f ($*.html_dir/$$fn)" ; \
			echo "$$f $*.html_dir/$$fn" >> $*.www_files ; \
		fi ;\
	done
BMK:.if defined(USE_TEX2PAGE)
GMK:ifdef USE_TEX2PAGE
GMK:	for f in `${FIND} . -type f \( -name \*-Z-G-\*.tex -o -name \*-Z-G-\*.aux \
BMK:	for f in `${FIND} . -type f \( -name \*-Z-G-\*.tex -o -name \*-Z-G-\*.aux \
		-o -name \*-Z-G-\*.log -o -name \*-Z-G-\*.dvi -o -name \*-Z-G-\*.ps \
		-o -name .Z\*.tex \) -newer $@1 -print` ; do \
		fn=`basename $$f` ; \
GMK:		if ${GREP} "^$$f " $*.www_files >/dev/null ; then \
BMK:		if ${GREP:Q} "^$$f " $*.www_files >/dev/null ; then \
			echo "$$f already recorded" ; \
		elif test "`dirname $$f`" != "." ; then \
			echo "$$f is not in this directory, skipping" ; \
		else \
			echo "recording file $$f (./$$fn)" ; \
			echo "$$f ./$$fn" >> $*.www_files ; \
		fi ;\
	done
BMK:.endif
GMK:endif
BMK:.if defined(USE_HEVEA)
GMK:ifdef USE_HEVEA
GMK:	for f in `${AWK} '{print $$1}' $*.www_files` ; do \
GMK:		${ECHO} "Moving $$f to $*.html_dir" ; mv $$f $*.html_dir ; \
BMK:	for f in `${AWK:Q} '{print $$1}' $*.www_files` ; do \
BMK:		${ECHO:Q} "Moving $$f to $*.html_dir" ; mv $$f $*.html_dir ; \
	done
BMK:.endif
GMK:endif
	mv $@1 $@

#######################################
#
# Postscript Output (dvips)
#
#######################################
.PHONY:  ps

# if we're doing a *-draft target, then add the 
# DRAFT watermark and time stamp
BMK:.if make(*-draft)
GMK:ifeq ($(findstring -draft,${MAKECMDGOALS}),-draft)
__DRAFT=	yes
BMK:.endif
GMK:endif

.dvi.ps :
BMK:.if defined(__DRAFT)
GMK:ifdef __DRAFT
GMK:	sed "s;DATE;`date`;g" ${DATED_DRAFT_PS} > ${DRAFT_STAMP_PS}
GMK:	${ENV_PROG} ${DVIPS_ENV} $(DVIPS) -h ${DRAFT_STAMP_PS} ${$*_DVIPS_FLAGS} $(DVIPS_FLAGS) -o $*-draft.ps $<
BMK:	sed "s;DATE;`date`;g" ${DATED_DRAFT_PS:Q} > ${DRAFT_STAMP_PS:Q}
BMK:	${DVIPS:Q} -h ${DRAFT_STAMP_PS:Q} ${$*_DVIPS_FLAGS} ${DVIPS_FLAGS} -o $*-draft.ps $<
BMK:.else
BMK:	${ENV_PROG:Q} ${DVIPS_ENV} ${DVIPS:Q} ${$*_DVIPS_FLAGS} ${DVIPS_FLAGS} -o $@ $<
GMK:else
GMK:	${ENV_PROG} ${DVIPS_ENV} $(DVIPS) ${$*_DVIPS_FLAGS} $(DVIPS_FLAGS) -o $@ $<
BMK:.endif
GMK:endif

#######################################
#
# PDF Output (ps2pdf)
#
#######################################
.PHONY:  pdf

BMK:.if defined(USE_DVIPDFM)
GMK:ifdef USE_DVIPDFM
.dvi.pdf :
GMK:	$(ENV_PROG) $(DVIPDFM_ENV) $(DVIPDFM) ${$*_DVIPDFM_FLAGS} $(DVIPDFM_FLAGS) $<
BMK:	${ENV_PROG:Q} ${DVIPDFM_ENV} ${DVIPDFM:Q} ${$*_DVIPDFM_FLAGS} ${DVIPDFM_FLAGS} $<
BMK:.elif defined(USE_PDFLATEX)
GMK:else
GMK:ifdef USE_PDFLATEX
.tex.pdf : 
GMK:	$(ENV_PROG) $(REAL_PDFLATEX_ENV) $(LATEX_MK) --pdflatex $(LATEX_MK_FLAGS) $<
BMK:	${ENV_PROG:Q} ${REAL_PDFLATEX_ENV} ${LATEX_MK:Q} --pdflatex ${LATEX_MK_FLAGS} $<
BMK:.else
GMK:else
.ps.pdf :
GMK:	$(PS2PDF) $(PS2PDF_FLAGS) $<
BMK:	${PS2PDF:Q} ${PS2PDF_FLAGS} $<
BMK:.endif
GMK:endif
GMK:endif

#######################################
#
# RTF (Rich Text Format) output (latex2rtf)
#
#######################################
.PHONY:  rtf

.dvi.rtf :
GMK:	$(ENV_PROG) $(LATEX2RTF_ENV) $(LATEX2RTF) $(LATEX2RTF_FLAGS) -o $@ $*.tex
BMK:	${ENV_PROG:Q} ${LATEX2RTF_ENV} ${LATEX2RTF:Q} ${LATEX2RTF_FLAGS} -o $@ $*.tex

#######################################
#
# Clean up (clean)
#
#######################################
CLEAN_FILES+=	${ALLTEXSRCS:.tex=.aux}
CLEAN_FILES+=	${BIBTEXSRCS:.bib=.aux}
CLEAN_FILES+=	${NAME:=.ps}
CLEAN_FILES+=	${NAME:=-draft.ps}
CLEAN_FILES+=	${NAME:=.pdf}
CLEAN_FILES+=	${NAME:=-draft.pdf}
CLEAN_FILES+=	${NAME:=.rtf}
CLEAN_FILES+=	${NAME:=.aux}
CLEAN_FILES+=	${NAME:=.log}
CLEAN_FILES+=	${NAME:=.dvi}
CLEAN_FILES+=	${NAME:=.log}
CLEAN_FILES+=	${NAME:=.bbl}
CLEAN_FILES+=	${NAME:=.blg}
CLEAN_FILES+=	${NAME:=.glo}
CLEAN_FILES+=	${NAME:=.gls}
CLEAN_FILES+=	${NAME:=.ilg}
CLEAN_FILES+=	${NAME:=.idx}
CLEAN_FILES+=	${NAME:=.ind}
CLEAN_FILES+=	${NAME:=.lof}
CLEAN_FILES+=	${NAME:=.lot}
CLEAN_FILES+=	${NAME:=.toc}
CLEAN_FILES+=	${NAME:=.out}
CLEAN_FILES+=	$(DRAFT_STAMP_PS)
CLEAN_FILES+=	${NAME:=.bib-stamp}

# HTML generation
CLEAN_FILES+=	${NAME:=.html-stamp}
CLEAN_FILES+=	${NAME:=.www_files}

BMK:.ifdef USE_HEVEA
GMK:ifdef USE_HEVEA
CLEAN_FILES+=	${NAME:=.haux}
CLEAN_FILES+=	${NAME:=.image.tex}
BMK:.endif
GMK:endif

BMK:.ifdef USE_LATEX2HTML
GMK:ifdef USE_LATEX2HTML
CLEAN_FILES+=	${NAME:=.haux}
CLEAN_FILES+=	${NAME:=.image.tex}
BMK:.endif
GMK:endif


BMK:.ifdef USE_TEX2PAGE
GMK:ifdef USE_TEX2PAGE
CLEAN_FILES+=	${NAME:=.hdir}
BMK:.endif
GMK:endif


.PHONY: clean

GMK:define latex_mk_clean_template
clean::
GMK:	${LATEX_MK} --clean $(1)
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call latex_mk_clean_template,$(__tmp__)))) 

clean::
BMK:.for __tmp__ in ${NAME}
BMK:	${LATEX_MK:Q} --clean ${__tmp__}
BMK:.endfor
BMK:	${RM:Q} -f *~ texput.log ${CLEAN_FILES}
GMK:	$(RM) -f *~ texput.log $(CLEAN_FILES)

.PHONY: distclean
distclean: clean

#######################################
#
# Some helpful debugging targets
#
#######################################
.PHONY: show-var
show-var:
GMK:	@${ECHO} ${${VARNAME}}
BMK:	@${ECHO:Q} ${${VARNAME}}