[project @ 1997-08-22 16:13:00 by reid]
[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 exit 0; fi; \
35  find $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food;
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 #-----------------------------------------------------------------------------
155 # Doc processing suffix rules
156
157 %.dvi : %.tex
158         @$(RM) $@
159         $(LTX) $<
160
161 %.ps : %.dvi
162         @$(RM) $@
163         dvips $< -o $@
164
165 %.tex : %.verb
166         @$(RM) $*.tex
167         expand $*.verb | $(VERBATIM) > $*.tex
168
169 %.tex : %.tib
170         @$(RM) $*.tex $*.verb-t.tex
171         $(TIB) $*.tib
172         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
173         @$(RM) $*.tib-t.tex
174
175 %.ps : %.fig
176         @$(RM) $@
177         fig2dev -L ps $< $@
178
179 %.tex : %.fig
180         @$(RM) $@
181         fig2dev -L latex $< $@
182
183 #-----------------------------------------------------------------------------
184 # Literate suffix rules
185
186 # ToDo: somehow macroize this lot. (if only!)
187
188 %.itxi : %.lit
189         @$(RM) $@
190         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
191         @chmod 444 $@
192
193 %.txt : %.lit
194         @$(RM) $@
195         $(LIT2TEXT) $(LIT2TEXT_OPTS) -o $@ $<
196         @chmod 444 $@
197
198 %.ihtml : %.lit
199         @$(RM) $@
200         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
201         @chmod 444 $@
202
203 %.itex : %.lit
204         @$(RM) $@
205         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
206         @chmod 444 $@
207
208 #
209 # Produce stand-alone TEX documents
210 #
211 %.tex : %.itex
212         @$(RM) $@
213         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
214         @chmod 444 $@
215
216 %.tex : %.lhs
217         @$(RM) $@
218         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
219         @chmod 444 $@
220
221 %.texi : %.lhs
222         @$(RM) $@
223         $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
224         @chmod 444 $@
225
226 %.html : %.lhs
227         @$(RM) $@ 
228         $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
229         $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
230         @touch $@
231
232 %.info:: %.texi
233         @$(RM) $@
234         $(MAKEINFO) $(MAKEINFO_OPTS) $< && $(POSTMAKEINFO) $@
235
236 %.hs : %.lhs
237         @$(RM) $@
238         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
239         @chmod 444 $@
240
241 %.itxi : %.lhs
242         @$(RM) $@
243         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
244         @chmod 444 $@
245
246 %.ihtml : %.lhs
247         @$(RM) $@
248         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
249         @chmod 444 $@
250
251 %.itex : %.lhs
252         @$(RM) $@
253         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
254         @chmod 444 $@
255
256 %.tex : %.lhs
257         $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
258         $(HC) $(HC_OPTS) -c $< -o $@
259
260
261 %.itxi : %.lhc
262         @$(RM) $@
263         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
264         @chmod 444 $@
265
266 %.ihtml : %.lhc
267         @$(RM) $@
268         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
269         @chmod 444 $@
270
271 %.itex : %.lhc
272         @$(RM) $@
273         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
274         @chmod 444 $@
275
276 #
277 # Temporary, until either unlit is lifted out of ghc/
278 # or literate is properly set up locally -- SOF
279 #
280 %.prl : %.lprl
281         @$(RM) $@
282         $(UNLIT) $(UNLIT_OPTS) $< $@
283         @chmod 444 $@
284
285 %.itxi : %.lprl
286         @$(RM) $@
287         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
288         @chmod 444 $@
289
290 %.ihtml : %.lprl
291         @$(RM) $@
292         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
293         @chmod 444 $@
294
295 %.itex : %.lprl
296         @$(RM) $@
297         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
298         @chmod 444 $@
299
300 %.sh : %.lsh
301         @$(RM) $@
302         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
303         @chmod 444 $@
304
305 %.itxi : %.lsh
306         @$(RM) $@
307         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
308         @chmod 444 $@
309
310 %.ihtml : %.lsh
311         @$(RM) $@
312         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
313         @chmod 444 $@
314
315 %.itex : %.lsh
316         @$(RM) $@
317         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
318         @chmod 444 $@
319
320 %.c : %.lc
321         @$(RM) $@
322         $(UNLIT) $< $@
323         @chmod 444 $@
324
325 %.itxi : %.lc
326         @$(RM) $@
327         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
328         @chmod 444 $@
329
330 %.ihtml : %.lc
331         @$(RM) $@
332         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
333         @chmod 444 $@
334
335 %.itex : %.lc
336         @$(RM) $@
337         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
338         @chmod 444 $@
339
340 %.h : %.lh
341         @$(RM) $@
342         $(UNLIT) $< $@
343         @chmod 444 $@
344
345 %.itxi : %.lh
346         @$(RM) $@
347         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
348         @chmod 444 $@
349
350 %.ihtml : %.lh
351         @$(RM) $@
352         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
353         @chmod 444 $@
354
355 %.itex : %.lh
356         @$(RM) $@
357         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
358         @chmod 444 $@
359
360 %.flex : %.lflex
361         @$(RM) $@
362         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
363         @chmod 444 $@
364
365 %.itxi : %.lflex
366         @$(RM) $@
367         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
368         @chmod 444 $@
369
370 %.ihtml : %.lflex
371         @$(RM) $@
372         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
373         @chmod 444 $@
374
375 %.itex : %.lflex
376         @$(RM) $@
377         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
378         @chmod 444 $@
379