File: lgrind.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 (249 lines) | stat: -rw-r--r-- 8,203 bytes parent folder | download | duplicates (3)
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
# -*- Makefile -*-
# $Id: lgrind.mk.in.in,v 1.7 2010/09/21 12:14:58 dan Exp $
#
# Makefile fragment for processing lgrind files to produce postscript
#
# Copyright (c) 2005, 2010 Dan McMahill
#
# Copyright (c) 2005 Peter Bex
# 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.
#


#######################################
#
# TODO:
# - Add a way to deal with specifying the language on a per-file
#   or maybe per-directory basis.  Maybe per-directory is a good
#   start.
#
# - Add support for files with no extension.  Need to make sure
#   we don't have problems with CVS/ directories.  In fact, we
#   need to make sure we don't have issues with foo.bar directories.
#
# - Add support for inline lgrind sources using the %(...)% notation
#
# README:
#
# To use this makefile fragment, set the variable:
#	LGRINDSRCS	= the source files to process
# in your top level Makefile.  You can also specify
# LGRINDDIRS which is a list of directories containing
# source files.  All source files in the specified directories
# are added to LGRINDSRCS
#
# The following variables may be overridden in your top level Makefile
#
#  LGRIND	= the lgrind executable
#  LGRIND_FLAGS	= flags passed to lgrind for exporting to tex
#
#######################################


# how to call lgrind to convert source files to TeX
LGRIND?=	@LGRIND@
LGRIND_FLAGS?=	-i

#######################################
#
# Process LGRINDDIRS, adding to LGRINDSRCS
#
#######################################

# pick out $(LGRINDDIRS)/*.* except for *.tex for each
# specified directory.  This is how we will
# deal with basically any source code file type.  The
# exception will be things like Makefiles which do not
# have an extension usually.

# While we're processing these directories, check for a directory
# specific LGRIND_FLAGS (i.e. mydir_LGRIND_FLAGS).  If it is defined
# then assign it to the file specific lgrind flags for each source
# file if the source file does not already have its own file specific
# flags

BMK:.if defined(LGRINDDIRS)
BMK:.for __tmp__ in ${LGRINDDIRS}
BMK:.if exists(${__tmp__})
BMK:_LGRIND_ADDALL_${__tmp__}!=	ls ${__tmp__}/*.*
BMK:_LGRIND_ADD_${__tmp__}=	${_LGRIND_ADDALL_${__tmp__}:C/.*.tex$//g}
BMK:LGRINDSRCS+=	${_LGRIND_ADD_${__tmp__}}
BMK:.  if defined(${__tmp__}_LGRIND_FLAGS)
BMK:.    for __tmp2__ in ${_LGRIND_ADD_${__tmp__}}
BMK:${__tmp2__}_LGRIND_FLAGS?=	${${__tmp__}_LGRIND_FLAGS}
BMK:.    endfor
BMK:.  endif
BMK:.endif
BMK:.endfor
BMK:.endif


GMK:define lgrinddir_flag_template
GMK:$(1)_LGRIND_FLAGS?=	$($(2)_LGRIND_FLAGS)
GMK:endef

GMK:define lgrindsrcs_add_template
GMK:LGRINDSRCS+=	${_LGRIND_ADD_$(1)}
GMK:ifdef $(1)_LGRIND_FLAGS
GMK:$(foreach __tmp2__,$(_LGRIND_ADD_$(1)),$(eval $(call lgrinddir_flag_template,$(__tmp2__),$(1))))
GMK:endif
GMK:endef

GMK:define lgrinddirs_template
GMK:_LGRIND_ADD_$(1)=	$(filter-out %.tex,$(wildcard $(1)/*.*))
GMK:endef
GMK:$(foreach __tmp__,$(LGRINDDIRS),$(eval $(call lgrinddirs_template,$(__tmp__))))
GMK:$(foreach __tmp__,$(LGRINDDIRS),$(eval $(call lgrindsrcs_add_template,$(__tmp__))))


#######################################
#
# Process proj_LGRINDDIRS, adding to proj_LGRINDSRCS
#
#######################################

BMK:.for __name__ in ${NAME}
BMK:.if defined(${__name__}_LGRINDDIRS)
BMK:.for __tmp__ in ${${__name__}_LGRINDDIRS}
BMK:.if exists(${__tmp__})
BMK:_LGRIND_ADDALL2_${__tmp__}!=ls ${__tmp__}/*.*
BMK:_LGRIND_ADD2_${__tmp__}=	${_LGRIND_ADDALL2_${__tmp__}:C/.*.tex$//g}
BMK:${__name__}_LGRINDSRCS+=	${_LGRIND_ADD2_${__tmp__}}
BMK:.  if defined(${__tmp__}_LGRIND_FLAGS)
BMK:.    for __tmp2__ in ${_LGRIND_ADD2_${__tmp__}}
BMK:${__tmp2__}_LGRIND_FLAGS?=	${${__tmp__}_LGRIND_FLAGS}
BMK:.    endfor
BMK:.  endif
BMK:.endif
BMK:.endfor
BMK:.endif
BMK:${__name__}_DIST+=	${${__name__}_LGRINDSRCS} ${LGRINDSRCS}
BMK:.endfor


GMK:define proj_lgrindsrcs_add_template
GMK:$(2)_LGRINDSRCS+=	${_LGRIND_ADD2_$(1)}
GMK:ifdef $(1)_LGRIND_FLAGS
GMK:$(foreach __tmp2__,$(_LGRIND_ADD2_$(1)),$(eval $(call lgrinddir_flag_template,$(__tmp2__),$(1))))
GMK:endif
GMK:endef

GMK:define proj_lgrinddirs_template
GMK:_LGRIND_ADD2_$(1)=	$(filter-out %.tex,$(wildcard $(1)/*.*))
GMK:endef

GMK:define proj_lgrind_template
GMK:ifdef $(1)_LGRINDDIRS
GMK:$(foreach __tmp2__,$($(1)_LGRINDDIRS),$(eval $(call proj_lgrinddirs_template,$(__tmp2__))))
GMK:$(foreach __tmp2__,$($(1)_LGRINDDIRS),$(eval $(call proj_lgrindsrcs_add_template,$(__tmp2__),$(1))))
GMK:endif
GMK:$(1)_DIST+=	$($(1)_LGRINDSRCS) $(LGRINDSRCS)
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call proj_lgrind_template,$(__tmp__))))


#######################################
# 
# Process proj_LGRINDSRCS to add to
# prog_OTHER dependencies
#
#######################################

LGRINDOBJS?=	$(LGRINDSRCS:=.tex)
ALLLGRINDOBJS+=	$(LGRINDOBJS)

BMK:.for __tmp__ in ${NAME}
BMK:.if defined(${__tmp__}_LGRINDSRCS)
BMK:${__tmp__}_LGRINDOBJS?=	${${__tmp__}_LGRINDSRCS:=.tex}
BMK:${__tmp__}_OTHER+=	${${__tmp__}_LGRINDOBJS}
BMK:ALLLGRINDOBJS+=	${${__tmp__}_LGRINDOBJS}
BMK:.endif
BMK:.endfor

GMK:# note, this had to be done in two steps (create proj_LGRINDOBJS,
GMK:# and then add to proj_OTHER and ALLLGRINDOBJS) with GNU make 3.80
GMK:# don't really know why.
GMK:define lgrindobjs_template
GMK:ifdef $(1)_LGRINDSRCS
GMK:$(1)_LGRINDOBJS?=	${$(1)_LGRINDSRCS:=.tex}
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call lgrindobjs_template,$(__tmp__))))

GMK:define lgrinddeps_template
GMK:ifdef $(1)_LGRINDSRCS
GMK:$(1)_OTHER+=	${$(1)_LGRINDOBJS}
GMK:ALLLGRINDOBJS+=	${$(1)_LGRINDOBJS}
GMK:endif
GMK:endef
GMK:$(foreach __tmp__,$(NAME),$(eval $(call lgrinddeps_template,$(__tmp__))))


#######################################
# 
# Add the dependencies
#
#######################################


OTHER+=	$(LGRINDOBJS)
all::		$(ALLLGRINDOBJS)

clean::
BMK:.for __tmp__ in $(ALLLGRINDOBJS)
BMK:	$(RM) -f $(__tmp__:Q)
BMK:.endfor
GMK:	$(RM) -f $(ALLLGRINDOBJS)


#######################################
#
# And add the build rules.
# 
# Note that we do this as a loop with explicit
# rules for each file rather than a suffix
# rule because we want to work on any input 
# file that lgrind can deal with
#
#######################################

BMK:.for __tmp__ in ${ALLLGRINDOBJS}
BMK:${__tmp__}: ${__tmp__:.tex=}
BMK:	$(LGRIND:Q) $(LGRIND_FLAGS) ${${__tmp__:.tex=}_LGRIND_FLAGS} \
BMK:		-o $@ ${__tmp__:.tex=}
BMK:.endfor

GMK:define lgrindrun_template
GMK:$(1): $(1:.tex=)
GMK:	$(LGRIND) $(LGRIND_FLAGS) $($(1:.tex=)_LGRIND_FLAGS) -o $(1) $(1:.tex=)
GMK:endef
GMK:$(foreach __tmp__,$(ALLLGRINDOBJS),$(eval $(call lgrindrun_template,$(__tmp__))))