summaryrefslogtreecommitdiff
path: root/web/glasgow/lit2x-0.16/mkworld/suffixes-GEN.ljm
blob: ad1fe6d2b7a409bf8afc3523cf191794e32cde81 (plain)
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
%************************************************************************
%*									*
\section[mkworld-suffix-rules]{Default stuff for suffix rules}
%*									*
%************************************************************************

We are keen on suffix rules, rather than pattern rules, because not
all makes do the latter.  Sigh.

Suffix rules come in three blobs: (1)~the unavoidable ones [few];
(2)~the ``always for this project'' ones [turn-off-able]; and (3)~the
per-Jmakefile ones (you must ``ask for'' these in each Jmakefile where
you need them.

%************************************************************************
%*									*
\subsection[mkworld-suffix-macros]{Macros for making up suffix rules}
%*									*
%************************************************************************

%************************************************************************
%*									*
\subsubsection[mkworld-suffix-macros-literate]{Suffix-rule macros for literate stuff}
%*									*
%************************************************************************

The following rule generator assumes the @beforesuff->aftersuff@ is
known to the literate programming system.

\begin{code}
#ifndef LitSuffixRule
#define LitSuffixRule(beforesuff,aftersuff)				@@\
CAT2(beforesuff,aftersuff):						@@\
	$(RM) $@							@@\
	$(LIT2PGM) $(LIT2PGMFLAGS) -o $@ $<				@@\
	@chmod 444 $@							@@\
									@@\
beforesuff.itxi:							@@\
	$(RM) $@							@@\
	$(LIT2TEXI) -c $(LIT2TEXIFLAGS) -o $@ $<			@@\
	@chmod 444 $@							@@\
									@@\
beforesuff.itex:							@@\
	$(RM) $@							@@\
	$(LIT2LATEX) -c $(LIT2LATEXFLAGS) -o $@ $<			@@\
	@chmod 444 $@
#endif /* LitSuffixRule */
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffix-macros-C]{Suffix-rule macros for C}
%*									*
%************************************************************************

For objects in libraries: these rules are invoked when you want to
override some default suffix rules.
\begin{code}
#ifndef NormalLibraryObjectRule
#define NormalLibraryObjectRule()					@@\
.c.o:									@@\
	RemoveTarget ($@)						@@\
	$(CC) -c $(CFLAGS) $*.c
#endif
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffix-macros-Haskell]{Suffix-rule macros for Haskell}
%*									*
%************************************************************************

There are several varying flavours of Haskell-related suffix rules;
each such ``set'' of suffix rules should include...:

\begin{verbatim}
.o	-> .hi	# hacky pseudo-dependency to mk .hi file if non-existent
.lhs	-> .o
.hs	-> .o
\end{verbatim}

This is the {\em default}; a project or setup could override it.
\begin{code}
#ifndef HaskellSuffixRules 
#define HaskellSuffixRules()				@@\
SuffixRule_o_hi()					@@\
SuffixRule_lhs_o()					@@\
SuffixRule_hs_o()
#endif /* !HaskellSuffixRules */
\end{code}

We use the internal mkworld CPP macro
@_body_HaskellCompileWithSpecifiedFlags@, which is shared w/ other
mkworld stuff.  This keeps the magic to exactly one place.

\begin{code}
#ifndef SuffixRule_o_hi
#define SuffixRule_o_hi()							@@\
.o.hi:										@@\
	@if [ ! -f $@ ] ; then \						@@\
    	    echo $(RM) $< ; \							@@\
    	    $(RM) $< ; \							@@\
	    set +e ; \								@@\
	    echo $(MAKE) HC="$(HC)" HCFLAGS="$(HCFLAGS)" $(MFLAGS) $< ; \	@@\
	    $(MAKE) HC="$(HC)" HCFLAGS="$(HCFLAGS)" $(MFLAGS) $< ; \		@@\
	    if [ $$? -ne 0 ] ; then \						@@\
		exit 1; \							@@\
	    fi ; \								@@\
	fi
#endif /* !SuffixRule_o_hi */
\end{code}

\begin{code}
#ifndef SuffixRule_hs_o
#define SuffixRule_hs_o()							@@\
.hs.o:										\
_body_HaskellCompileWithSpecifiedFlags($<,$*,hs,-c $(HCFLAGS))
#endif /* !SuffixRule_hs_o */

#ifndef SuffixRule_lhs_o
#define SuffixRule_lhs_o()							@@\
.lhs.o:										\
_body_HaskellCompileWithSpecifiedFlags($<,$*,lhs,-c $(HCFLAGS))
#endif /* !SuffixRule_lhs_o */
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffix-macros-doc]{Suffix-rule macros for document processing}
%*									*
%************************************************************************

You have to ask for these.

\begin{code}
#ifndef DocProcessingSuffixRules
#define DocProcessingSuffixRules()			@@\
.tex.dvi:						@@\
	$(RM) $@					@@\
	$(LTX) $<					@@\
							@@\
.verb.tex:						@@\
	$(RM) $*.tex					@@\
	expand $*.verb | $(VERBATIM) > $*.tex		@@\
							@@\
.tib.tex:						@@\
	$(RM) $*.tex $*.verb-t.tex			@@\
	$(TIB) $*.tib					@@\
	expand $*.tib-t.tex | $(VERBATIM) > $*.tex	@@\
	$(RM) $*.tib-t.tex				@@\
							@@\
.fig.ps:						@@\
	$(RM) $@					@@\
	fig2dev -L ps $< $@				@@\
							@@\
.fig.tex:						@@\
	$(RM) $@					@@\
	fig2dev -L latex $< $@

#endif /* ! DocProcessingSuffixRules */
\end{code}

%************************************************************************
%*									*
\subsection[mkworld-suffix-rule-text]{Generate actual suffix-rule text}
%*									*
%************************************************************************

\begin{code}
.SUFFIXES: .xdvi .ps .dvi .tex .fig .tib .verb .itex .itxi .lit \
	_p.o .o .s .hi .hc .lhc .lhs .hs \
	.prl .lprl \
	.sh .lsh \
	.c .lc .h .lh .lex .llex .y \
	.ljm .jm
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffixes-general]{Suffix rules---very general ones}
%*									*
%************************************************************************

\begin{code}
.s.o:
	$(RM) $@
	$(AS) $(ASFLAGS) -o $@ $< || $(RM) $@
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffixes-literate]{Suffix rules for literate programming}
%*									*
%************************************************************************

The \tr{.ljm->.jm} rule isn't optional, because the mkworld system
uses it.

\begin{code}
LitSuffixRule(.ljm,.jm)		/* mkworld */

#if SuffixRules_WantLiterate == YES

LitSuffixRule(.lit,/*none*/)	/* no language really */
LitSuffixRule(.lhs,.hs)		/* Haskell */
LitSuffixRule(.lhc,.hc)		/* Haskell assembler (C) */
LitSuffixRule(.lprl,.prl)	/* Perl */
LitSuffixRule(.lsh,.sh)		/* Bourne shell */
LitSuffixRule(.lc,.c)		/* C */
LitSuffixRule(.lh,.h)
LitSuffixRule(.llex,.lex)	/* Lex */

/* extra rule... flex can't handle #line's yet */
/* also: save the .lex file in case of some debugging need */
.llex.c:
	$(RM) $@ $*.lex $*.lex.save
	$(LIT2PGM) $(LIT2PGMFLAGS) $< > $*.lex
	$(FLEX) $*.lex && mv $*.lex $*.lex.save && mv lex.yy.c $*.c

#endif /* SuffixRules_WantLiterate */
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffixes-C]{Suffix rules for C/lex/yacc programming}
%*									*
%************************************************************************

See also the ``literate lex'' (llex) rule in the literate section, above.

We don't support the \tr{.y.c} suffix rule; an explicit
@YaccRunWithExpectMsg@ is better.
\begin{code}
.y.c:
	@echo please use an explicit "YaccRunWithExpectMsg" macro

.lex.c: /* ToDo: should make it do flex */
	$(RM) $@
	$(LEX) -t $(LFLAGS) $< > $@ || ( $(RM) $@ && exit 1 )
\end{code}

NB: avoid \tr{-o <something>} because of braindead C compilers.
\begin{code}
#if CCompilerGroksMinusCMinusO == YES
.c.o:
	$(RM) $@
	$(CC) $(CFLAGS) -c $< -o $@
.c.s:
	$(RM) $@
	$(CC) $(CFLAGS) -S $< -o $@

#else /* ! CCompilerGroksMinusCMinusO */
.c.o:
	$(RM) $@
	$(CC) $(CFLAGS) -c $<
	@if [ \( $(@D) != '.' \) -a \( $(@D) != './' \) ] ; then \
	    echo mv $(@F) $@ ; \
	    mv $(@F) $@ ; \
	fi
.c.s:
	$(RM) $@
	$(CC) $(CFLAGS) -S $<
	@if [ \( $(@D) != '.' \) -a \( $(@D) != './' \) ] ; then \
	    echo mv $(@F) $@ ; \
	    mv $(@F) $@ ; \
	fi
#endif /* ! CCompilerGroksMinusCMinusO */
\end{code}

%************************************************************************
%*									*
\subsubsection[mkworld-suffixes-haskell]{Suffix rules for Haskell programming}
%*									*
%************************************************************************

Suffix rules for Haskell are {\em not} put in by default.  A Jmakefile
must ask for one specifically, using one of the macros defined in
macros section, above (\sectionref{mkworld-suffix-macros-Haskell}).

%************************************************************************
%*									*
\subsubsection[mkworld-suffixes-docs]{Suffix rules for document processing (LaTeX/tib/fig/etc)}
%*									*
%************************************************************************

\begin{code}
#if SuffixRules_WantDocProcessing == YES
DocProcessingSuffixRules()
#endif /* SuffixRules_WantDocProcessing */
\end{code}