[project @ 1997-09-03 23:17:33 by sof]
[ghc-hetmet.git] / mk / suffix.mk
1 #################################################################################
2 #
3 #                           suffix.mk
4 #
5 #               Suffix rules for fptools
6 #
7 #################################################################################
8
9
10 # This file contain the default suffix rules for all the fptools projects.
11 #
12
13
14 # No need to define .SUFFIXES because we don't use any suffix rules
15 # Instead we use gmake's pattern rules exlusively
16
17 .SUFFIXES:
18
19 # However, if $(way) is set then we have to define $(way_) and $(_way)
20 # from it in the obvious fashion.
21 # This must be done here (or earlier), but not in target.mk with the other
22 # way management, because the pattern rules in this file take a snapshot of
23 # the value of $(way_) and $(_way), and it's no good setting them later!
24
25 ifneq "$(way)" ""
26   way_ := $(way)_
27   _way := _$(way)
28 endif
29
30 #-----------------------------------------------------------------------------
31 # Haskell Suffix Rules
32
33 HASKELL_SPLIT_PRE= \
34  $(RM) $@ ; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
35  find $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food ; fi
36 HASKELL_SPLIT_POST= touch $@
37 HASKELL_PRE_COMPILE=$(patsubst %,$(HASKELL_SPLIT_PRE),$(filter -split-objs,$(HC_OPTS)))
38 HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(HC_OPTS)))
39
40 %.$(way_)o : %.hs
41         $(HASKELL_PRE_COMPILE)
42         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
43         $(HASKELL_POST_COMPILE)
44                          
45 %.$(way_)o : %.lhs       
46         $(HASKELL_PRE_COMPILE)
47         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
48         $(HASKELL_POST_COMPILE)
49                          
50 %.$(way_)hc : %.lhs      
51         $(RM) $@
52         $(HC) $(HC_OPTS) -C $< -o $@
53                          
54 %.$(way_)hc : %.hs       
55         $(RM) $@
56         $(HC) $(HC_OPTS) -C $< -o $@
57                          
58 %.$(way_)o : %.$(way_)hc 
59         $(HASKELL_PRE_COMPILE)
60         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
61         $(HASKELL_POST_COMPILE)
62
63 %.$(way_)hc : %.lhc
64         @$(RM) $@
65         $(UNLIT) $< $@
66         @chmod 444 $@
67
68
69 # Here's an interesting rule!
70 # The .hi file depends on the .o file,
71 # so if the .hi file is dated earlier than the .o file (commonly the case,
72 # when interfaces are stable) this rule just makes sure that the .o file,
73 # is up to date.  Then it does nothing to generate the .hi file from the 
74 # .o file, because the act of making sure the .o file is up to date also
75 # updates the .hi file (if necessary).
76
77 %.$(way_)hi : %.$(way_)o
78         @if [ ! -f $@ ] ; then \
79             echo Panic! $< exists, but $@ does not. \
80             exit 1; \
81         else exit 0 ; \
82         fi                                                      
83
84 %.$(way_)hi : %.$(way_)hc
85         @if [ ! -f $@ ] ; then \
86             echo Panic! $< exists, but $@ does not. \
87             exit 1; \
88         else exit 0 ; \
89         fi
90
91 #-----------------------------------------------------------------------------
92 # Happy Suffix Rules
93 #
94 .PRECIOUS: %.hs
95
96 %.hs : %.ly
97         $(HAPPY) $(HAPPY_OPTS) -g $<
98
99 #-----------------------------------------------------------------------------
100 # Lx Suffix Rules
101 #
102
103 %.hs : %.lx
104         $(LX) $(LX_OPTS) $<
105
106 #-----------------------------------------------------------------------------
107 # Green-card Suffix Rules
108 #
109
110 %.hs : %.gc
111         $(GREENCARD) $(GREENCARD_OPTS) $<
112
113 #-----------------------------------------------------------------------------
114 # C-related suffix rules
115
116 %.$(way_)o : %.$(way_)s
117         @$(RM) $@
118         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
119
120 %.$(way_)o : %.c
121         @$(RM) $@
122         $(CC) $(CC_OPTS) -c $< -o $@
123
124 #%.$(way_)s : %.c
125 #       @$(RM) $@
126 #       $(CC) $(CC_OPTS) -S $< -o $@
127
128 %.c : %.flex
129         @$(RM) $@
130         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
131 %.c : %.lex
132         @$(RM) $@
133         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
134
135 #-----------------------------------------------------------------------------
136 # Yacc stuff
137
138 %.tab.c %.tab.h : %.y
139         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
140         $(YACC) $(YACC_OPTS) $<
141         $(MV) y.tab.c $*.tab.c
142         @chmod 444 $*.tab.c
143         $(MV) y.tab.h $*.tab.h
144         @chmod 444 $*.tab.h
145
146
147 #-----------------------------------------------------------------------------
148 # Runtest rules for calling $(HC) on a single-file Haskell program
149
150 %.hs : %.runtest
151         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_FLAGS) -o2 $*.stderr $<
152
153 #-----------------------------------------------------------------------------
154 # Doc processing suffix rules
155 #
156 # ToDo: make these more robust
157 #
158 %.dvi : %.tex
159         @$(RM) $@
160         $(LTX) $<
161
162 %.ps : %.dvi
163         @$(RM) $@
164         dvips $< -o $@
165
166 %.tex : %.verb
167         @$(RM) $*.tex
168         expand $*.verb | $(VERBATIM) > $*.tex
169
170 %.tex : %.tib
171         @$(RM) $*.tex $*.verb-t.tex
172         $(TIB) $*.tib
173         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
174         @$(RM) $*.tib-t.tex
175
176 %.ps : %.fig
177         @$(RM) $@
178         fig2dev -L ps $< $@
179
180 %.tex : %.fig
181         @$(RM) $@
182         fig2dev -L latex $< $@
183
184 #-----------------------------------------------------------------------------
185 # Literate suffix rules
186
187 # ToDo: somehow macroize this lot. (if only!)
188
189 %.itxi : %.lit
190         @$(RM) $@
191         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
192         @chmod 444 $@
193
194 %.txt : %.lit
195         @$(RM) $@
196         $(LIT2TEXT) $(LIT2TEXT_OPTS) -o $@ $<
197         @chmod 444 $@
198
199 %.ihtml : %.lit
200         @$(RM) $@
201         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
202         @chmod 444 $@
203
204 %.itex : %.lit
205         @$(RM) $@
206         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
207         @chmod 444 $@
208
209 #
210 # Produce stand-alone TEX documents
211 #
212 %.tex : %.itex
213         @$(RM) $@
214         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
215         @chmod 444 $@
216
217 %.tex : %.lhs
218         @$(RM) $@
219         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
220         @chmod 444 $@
221
222 %.texi : %.lhs
223         @$(RM) $@
224         $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
225         @chmod 444 $@
226
227 %.html : %.lhs
228         @$(RM) $@ 
229         $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
230         $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
231         @touch $@
232
233 %.info:: %.texi
234         @$(RM) $@
235         $(MAKEINFO) $(MAKEINFO_OPTS) $< && $(POSTMAKEINFO) $@
236
237 %.hs : %.lhs
238         @$(RM) $@
239         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
240         @chmod 444 $@
241
242 %.itxi : %.lhs
243         @$(RM) $@
244         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
245         @chmod 444 $@
246
247 %.ihtml : %.lhs
248         @$(RM) $@
249         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
250         @chmod 444 $@
251
252 %.itex : %.lhs
253         @$(RM) $@
254         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
255         @chmod 444 $@
256
257 %.tex : %.lhs
258         $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
259         $(HC) $(HC_OPTS) -c $< -o $@
260
261
262 %.itxi : %.lhc
263         @$(RM) $@
264         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
265         @chmod 444 $@
266
267 %.ihtml : %.lhc
268         @$(RM) $@
269         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
270         @chmod 444 $@
271
272 %.itex : %.lhc
273         @$(RM) $@
274         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
275         @chmod 444 $@
276
277 #
278 # Temporary, until either unlit is lifted out of ghc/
279 # or literate is properly set up locally -- SOF
280 #
281 %.prl : %.lprl
282         @$(RM) $@
283         $(UNLIT) $(UNLIT_OPTS) $< $@
284         @chmod 444 $@
285
286 %.itxi : %.lprl
287         @$(RM) $@
288         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
289         @chmod 444 $@
290
291 %.ihtml : %.lprl
292         @$(RM) $@
293         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
294         @chmod 444 $@
295
296 %.itex : %.lprl
297         @$(RM) $@
298         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
299         @chmod 444 $@
300
301 %.sh : %.lsh
302         @$(RM) $@
303         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
304         @chmod 444 $@
305
306 %.itxi : %.lsh
307         @$(RM) $@
308         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
309         @chmod 444 $@
310
311 %.ihtml : %.lsh
312         @$(RM) $@
313         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
314         @chmod 444 $@
315
316 %.itex : %.lsh
317         @$(RM) $@
318         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
319         @chmod 444 $@
320
321 %.c : %.lc
322         @$(RM) $@
323         $(UNLIT) $< $@
324         @chmod 444 $@
325
326 %.itxi : %.lc
327         @$(RM) $@
328         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
329         @chmod 444 $@
330
331 %.ihtml : %.lc
332         @$(RM) $@
333         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
334         @chmod 444 $@
335
336 %.itex : %.lc
337         @$(RM) $@
338         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
339         @chmod 444 $@
340
341 %.h : %.lh
342         @$(RM) $@
343         $(UNLIT) $< $@
344         @chmod 444 $@
345
346 %.itxi : %.lh
347         @$(RM) $@
348         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
349         @chmod 444 $@
350
351 %.ihtml : %.lh
352         @$(RM) $@
353         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
354         @chmod 444 $@
355
356 %.itex : %.lh
357         @$(RM) $@
358         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
359         @chmod 444 $@
360
361 %.flex : %.lflex
362         @$(RM) $@
363         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
364         @chmod 444 $@
365
366 %.itxi : %.lflex
367         @$(RM) $@
368         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
369         @chmod 444 $@
370
371 %.ihtml : %.lflex
372         @$(RM) $@
373         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
374         @chmod 444 $@
375
376 %.itex : %.lflex
377         @$(RM) $@
378         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
379         @chmod 444 $@
380