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