[project @ 1997-12-16 11:01:13 by simonm]
[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 %.runtest : %.hs
151         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
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 # SGML suffix rules
186 #
187 # make sure these don't conflict with the literate rules!
188
189 %.sgml : %.vsgml
190         @$(RM) $@
191         expand $*.verb | $(SGMLVERB) > $@
192
193 %.dvi : %.sgml
194         @$(RM) $@
195         $(SGML2LATEX) -m --output=dvi $<
196
197 %.html : %.sgml
198         @$(RM) $@
199         $(SGML2HTML) $<
200
201 %.info : %.sgml
202         @$(RM) $@
203         $(SGML2INFO) $<
204
205 %.txt : %.sgml
206         @$(RM) $@
207         $(SGML2TXT) $<
208
209 #-----------------------------------------------------------------------------
210 # Literate suffix rules
211
212 # ToDo: somehow macroize this lot. (if only!)
213
214 %.itxi : %.lit
215         @$(RM) $@
216         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
217         @chmod 444 $@
218
219 %.txt : %.lit
220         @$(RM) $@
221         $(LIT2TEXT) $(LIT2TEXT_OPTS) -o $@ $<
222         @chmod 444 $@
223
224 %.ihtml : %.lit
225         @$(RM) $@
226         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
227         @chmod 444 $@
228
229 %.itex : %.lit
230         @$(RM) $@
231         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
232         @chmod 444 $@
233
234 #
235 # Produce stand-alone TEX documents
236 #
237 %.tex : %.itex
238         @$(RM) $@
239         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
240         @chmod 444 $@
241
242 %.tex : %.lhs
243         @$(RM) $@
244         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
245         @chmod 444 $@
246
247 %.texi : %.lhs
248         @$(RM) $@
249         $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
250         @chmod 444 $@
251
252 %.html : %.lhs
253         @$(RM) $@ 
254         $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
255         $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
256         @touch $@
257
258 %.info:: %.texi
259         @$(RM) $@
260         $(MAKEINFO) $(MAKEINFO_OPTS) $< && $(POSTMAKEINFO) $@
261
262 %.hs : %.lhs
263         @$(RM) $@
264         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
265         @chmod 444 $@
266
267 %.itxi : %.lhs
268         @$(RM) $@
269         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
270         @chmod 444 $@
271
272 %.ihtml : %.lhs
273         @$(RM) $@
274         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
275         @chmod 444 $@
276
277 %.itex : %.lhs
278         @$(RM) $@
279         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
280         @chmod 444 $@
281
282 %.tex : %.lhs
283         $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
284         $(HC) $(HC_OPTS) -c $< -o $@
285
286
287 %.itxi : %.lhc
288         @$(RM) $@
289         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
290         @chmod 444 $@
291
292 %.ihtml : %.lhc
293         @$(RM) $@
294         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
295         @chmod 444 $@
296
297 %.itex : %.lhc
298         @$(RM) $@
299         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
300         @chmod 444 $@
301
302 #
303 # Temporary, until either unlit is lifted out of ghc/
304 # or literate is properly set up locally -- SOF
305 #
306 %.prl : %.lprl
307         @$(RM) $@
308         $(UNLIT) $(UNLIT_OPTS) $< $@
309         @chmod 444 $@
310
311 %.itxi : %.lprl
312         @$(RM) $@
313         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
314         @chmod 444 $@
315
316 %.ihtml : %.lprl
317         @$(RM) $@
318         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
319         @chmod 444 $@
320
321 %.itex : %.lprl
322         @$(RM) $@
323         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
324         @chmod 444 $@
325
326 %.sh : %.lsh
327         @$(RM) $@
328         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
329         @chmod 444 $@
330
331 %.itxi : %.lsh
332         @$(RM) $@
333         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
334         @chmod 444 $@
335
336 %.ihtml : %.lsh
337         @$(RM) $@
338         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
339         @chmod 444 $@
340
341 %.itex : %.lsh
342         @$(RM) $@
343         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
344         @chmod 444 $@
345
346 %.c : %.lc
347         @$(RM) $@
348         $(UNLIT) $< $@
349         @chmod 444 $@
350
351 %.itxi : %.lc
352         @$(RM) $@
353         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
354         @chmod 444 $@
355
356 %.ihtml : %.lc
357         @$(RM) $@
358         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
359         @chmod 444 $@
360
361 %.itex : %.lc
362         @$(RM) $@
363         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
364         @chmod 444 $@
365
366 %.h : %.lh
367         @$(RM) $@
368         $(UNLIT) $< $@
369         @chmod 444 $@
370
371 %.itxi : %.lh
372         @$(RM) $@
373         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
374         @chmod 444 $@
375
376 %.ihtml : %.lh
377         @$(RM) $@
378         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
379         @chmod 444 $@
380
381 %.itex : %.lh
382         @$(RM) $@
383         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
384         @chmod 444 $@
385
386 %.flex : %.lflex
387         @$(RM) $@
388         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
389         @chmod 444 $@
390
391 %.itxi : %.lflex
392         @$(RM) $@
393         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
394         @chmod 444 $@
395
396 %.ihtml : %.lflex
397         @$(RM) $@
398         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
399         @chmod 444 $@
400
401 %.itex : %.lflex
402         @$(RM) $@
403         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
404         @chmod 444 $@
405