[project @ 1997-06-10 18:40:34 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 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 # C-related suffix rules
108
109 %.$(way_)o : %.$(way_)s
110         @$(RM) $@
111         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
112
113 %.$(way_)o : %.c
114         @$(RM) $@
115         $(CC) $(CC_OPTS) -c $< -o $@
116
117 #%.$(way_)s : %.c
118 #       @$(RM) $@
119 #       $(CC) $(CC_OPTS) -S $< -o $@
120
121 %.c : %.flex
122         @$(RM) $@
123         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
124 %.c : %.lex
125         @$(RM) $@
126         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
127
128 #-----------------------------------------------------------------------------
129 # Yacc stuff
130
131 %.tab.c %.tab.h : %.y
132         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
133         $(YACC) $(YACC_OPTS) $<
134         $(MV) y.tab.c $*.tab.c
135         @chmod 444 $*.tab.c
136         $(MV) y.tab.h $*.tab.h
137         @chmod 444 $*.tab.h
138
139
140 #-----------------------------------------------------------------------------
141 # Runtest rules for calling $(HC) on a single-file Haskell program
142
143 %.hs : %.runtest
144         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_FLAGS) -o2 $*.stderr $<
145
146
147 #-----------------------------------------------------------------------------
148 # Doc processing suffix rules
149
150 %.dvi : %.tex
151         @$(RM) $@
152         $(LTX) $<
153
154 %.ps : %.dvi
155         @$(RM) $@
156         dvips $< -o $@
157
158 %.tex : %.verb
159         @$(RM) $*.tex
160         expand $*.verb | $(VERBATIM) > $*.tex
161
162 %.tex : %.tib
163         @$(RM) $*.tex $*.verb-t.tex
164         $(TIB) $*.tib
165         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
166         @$(RM) $*.tib-t.tex
167
168 %.ps : %.fig
169         @$(RM) $@
170         fig2dev -L ps $< $@
171
172 %.tex : %.fig
173         @$(RM) $@
174         fig2dev -L latex $< $@
175
176 #-----------------------------------------------------------------------------
177 # Literate suffix rules
178
179 # ToDo: somehow macroize this lot. (if only!)
180
181 %.itxi : %.lit
182         @$(RM) $@
183         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
184         @chmod 444 $@
185
186 %.txt : %.lit
187         @$(RM) $@
188         $(LIT2TEXT) $(LIT2TEXT_OPTS) -o $@ $<
189         @chmod 444 $@
190
191 %.ihtml : %.lit
192         @$(RM) $@
193         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
194         @chmod 444 $@
195
196 %.itex : %.lit
197         @$(RM) $@
198         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
199         @chmod 444 $@
200
201 #
202 # Produce stand-alone TEX documents
203 #
204 %.tex : %.itex
205         @$(RM) $@
206         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
207         @chmod 444 $@
208
209 %.tex : %.lhs
210         @$(RM) $@
211         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
212         @chmod 444 $@
213
214 %.texi : %.lhs
215         @$(RM) $@
216         $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
217         @chmod 444 $@
218
219 %.html : %.lhs
220         @$(RM) $@ 
221         $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
222         $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
223         @touch $@
224
225 %.info:: %.texi
226         @$(RM) $@
227         $(MAKEINFO) $(MAKEINFO_OPTS) $< && $(POSTMAKEINFO) $@
228
229 %.hs : %.lhs
230         @$(RM) $@
231         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
232         @chmod 444 $@
233
234 %.itxi : %.lhs
235         @$(RM) $@
236         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
237         @chmod 444 $@
238
239 %.ihtml : %.lhs
240         @$(RM) $@
241         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
242         @chmod 444 $@
243
244 %.itex : %.lhs
245         @$(RM) $@
246         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
247         @chmod 444 $@
248
249 %.tex : %.lhs
250         $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
251         $(HC) $(HC_OPTS) -c $< -o $@
252
253
254 %.itxi : %.lhc
255         @$(RM) $@
256         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
257         @chmod 444 $@
258
259 %.ihtml : %.lhc
260         @$(RM) $@
261         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
262         @chmod 444 $@
263
264 %.itex : %.lhc
265         @$(RM) $@
266         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
267         @chmod 444 $@
268
269 #
270 # Temporary, until either unlit is lifted out of ghc/
271 # or literate is properly set up locally -- SOF
272 #
273 %.prl : %.lprl
274         @$(RM) $@
275         $(UNLIT) $(UNLIT_OPTS) $< $@
276         @chmod 444 $@
277
278 %.itxi : %.lprl
279         @$(RM) $@
280         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
281         @chmod 444 $@
282
283 %.ihtml : %.lprl
284         @$(RM) $@
285         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
286         @chmod 444 $@
287
288 %.itex : %.lprl
289         @$(RM) $@
290         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
291         @chmod 444 $@
292
293 %.sh : %.lsh
294         @$(RM) $@
295         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
296         @chmod 444 $@
297
298 %.itxi : %.lsh
299         @$(RM) $@
300         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
301         @chmod 444 $@
302
303 %.ihtml : %.lsh
304         @$(RM) $@
305         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
306         @chmod 444 $@
307
308 %.itex : %.lsh
309         @$(RM) $@
310         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
311         @chmod 444 $@
312
313 %.c : %.lc
314         @$(RM) $@
315         $(UNLIT) $< $@
316         @chmod 444 $@
317
318 %.itxi : %.lc
319         @$(RM) $@
320         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
321         @chmod 444 $@
322
323 %.ihtml : %.lc
324         @$(RM) $@
325         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
326         @chmod 444 $@
327
328 %.itex : %.lc
329         @$(RM) $@
330         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
331         @chmod 444 $@
332
333 %.h : %.lh
334         @$(RM) $@
335         $(UNLIT) $< $@
336         @chmod 444 $@
337
338 %.itxi : %.lh
339         @$(RM) $@
340         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
341         @chmod 444 $@
342
343 %.ihtml : %.lh
344         @$(RM) $@
345         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
346         @chmod 444 $@
347
348 %.itex : %.lh
349         @$(RM) $@
350         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
351         @chmod 444 $@
352
353 %.flex : %.lflex
354         @$(RM) $@
355         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
356         @chmod 444 $@
357
358 %.itxi : %.lflex
359         @$(RM) $@
360         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
361         @chmod 444 $@
362
363 %.ihtml : %.lflex
364         @$(RM) $@
365         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
366         @chmod 444 $@
367
368 %.itex : %.lflex
369         @$(RM) $@
370         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
371         @chmod 444 $@
372