[project @ 1997-03-14 07:52:06 by simonpj]
[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  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         $(RM) $@
42         $(HASKELL_PRE_COMPILE)
43         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
44         $(HASKELL_POST_COMPILE)
45                          
46 %.$(way_)o : %.lhs       
47         $(RM) $@
48         $(HASKELL_PRE_COMPILE)
49         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
50         $(HASKELL_POST_COMPILE)
51                          
52 %.$(way_)hc : %.lhs      
53         $(RM) $@
54         $(HC) $(HC_OPTS) -C $< -o $@
55                          
56 %.$(way_)o : %.$(way_)hc 
57         $(RM) $@
58         $(HASKELL_PRE_COMPILE)
59         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
60         $(HASKELL_POST_COMPILE)
61
62 %.$(way_)hc : %.lhc
63         @$(RM) $@
64         $(UNLIT) $< $@
65         @chmod 444 $@
66
67
68 # Here's an interesting rule!
69 # The .hi file depends on the .o file,
70 # so if the .hi file is dated earlier than the .o file (commonly the case,
71 # when interfaces are stable) this rule just makes sure that the .o file,
72 # is up to date.  Then it does nothing to generate the .hi file from the 
73 # .o file, because the act of making sure the .o file is up to date also
74 # updates the .hi file (if necessary).
75
76 %.$(way_)hi : %.$(way_)o
77         @if [ ! -f $@ ] ; then \
78             echo Panic! $< exists, but $@ does not. \
79             exit 1; \
80         else exit 0 ; \
81         fi                                                      
82
83 %.$(way_)hi : %.$(way_)hc
84         @if [ ! -f $@ ] ; then \
85             echo Panic! $< exists, but $@ does not. \
86             exit 1; \
87         else exit 0 ; \
88         fi
89
90 #-----------------------------------------------------------------------------
91 # Happy Suffix Rules
92 #
93 .PRECIOUS: %.hs
94
95 %.hs : %.ly
96         $(HAPPY) $(HAPPY_OPTS) -g $<
97
98 #-----------------------------------------------------------------------------
99 # Lx Suffix Rules
100 #
101 .PRECIOUS: %.hs
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
125 #-----------------------------------------------------------------------------
126 # Yacc stuff
127
128 %.tab.c %.tab.h : %.y
129         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
130         $(YACC) $(YACC_OPTS) $<
131         $(MV) y.tab.c $*.tab.c
132         @chmod 444 $*.tab.c
133         $(MV) y.tab.h $*.tab.h
134         @chmod 444 $*.tab.h
135
136
137 #-----------------------------------------------------------------------------
138 # Runtest rules for calling $(HC) on a single-file Haskell program
139
140 %.hs : %.runtest
141         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_FLAGS) -o2 $*.stderr $<
142
143
144 #-----------------------------------------------------------------------------
145 # Doc processing suffix rules
146
147 %.dvi : %.tex
148         @$(RM) $@
149         $(LTX) $<
150
151 %.ps : %.dvi
152         @$(RM) $@
153         dvips $< -o $@
154
155 %.tex : %.verb
156         @$(RM) $*.tex
157         expand $*.verb | $(VERBATIM) > $*.tex
158
159 %.tex : %.tib
160         @$(RM) $*.tex $*.verb-t.tex
161         $(TIB) $*.tib
162         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
163         @$(RM) $*.tib-t.tex
164
165 %.ps : %.fig
166         @$(RM) $@
167         fig2dev -L ps $< $@
168
169 %.tex : %.fig
170         @$(RM) $@
171         fig2dev -L latex $< $@
172
173 #-----------------------------------------------------------------------------
174 # Literate suffix rules
175
176 # ToDo: somehow macroize this lot. (if only!)
177
178 %.itxi : %.lit
179         @$(RM) $@
180         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
181         @chmod 444 $@
182
183 %.txt : %.lit
184         @$(RM) $@
185         $(LIT2TEXT) -c $(LIT2TEXT_OPTS) -o $@ $<
186         @chmod 444 $@
187
188 %.ihtml : %.lit
189         @$(RM) $@
190         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
191         @chmod 444 $@
192
193 %.itex : %.lit
194         @$(RM) $@
195         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
196         @chmod 444 $@
197
198 #
199 # Produce stand-alone TEX documents
200 #
201 %.tex : %.itex
202         @$(RM) $@
203         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
204         @chmod 444 $@
205
206 %.tex : %.lhs
207         @$(RM) $@
208         $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
209         @chmod 444 $@
210
211 %.texi : %.lhs
212         @$(RM) $@
213         $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
214         @chmod 444 $@
215
216 %.html : %.lhs
217         @$(RM) $@ 
218         $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
219         $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
220         @touch $@
221
222 %.hs : %.lhs
223         @$(RM) $@
224         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
225         @chmod 444 $@
226
227 %.itxi : %.lhs
228         @$(RM) $@
229         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
230         @chmod 444 $@
231
232 %.ihtml : %.lhs
233         @$(RM) $@
234         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
235         @chmod 444 $@
236
237 %.itex : %.lhs
238         @$(RM) $@
239         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
240         @chmod 444 $@
241
242 %.tex : %.lhs
243         $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
244         $(HC) $(HC_OPTS) -c $< -o $@
245
246
247 %.itxi : %.lhc
248         @$(RM) $@
249         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
250         @chmod 444 $@
251
252 %.ihtml : %.lhc
253         @$(RM) $@
254         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
255         @chmod 444 $@
256
257 %.itex : %.lhc
258         @$(RM) $@
259         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
260         @chmod 444 $@
261
262 #
263 # Temporary, until either unlit is lifted out of ghc/
264 # or literate is properly set up locally -- SOF
265 #
266 %.prl : %.lprl
267         @$(RM) $@
268         $(UNLIT) $(UNLIT_OPTS) $< $@
269         @chmod 444 $@
270
271 %.itxi : %.lprl
272         @$(RM) $@
273         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
274         @chmod 444 $@
275
276 %.ihtml : %.lprl
277         @$(RM) $@
278         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
279         @chmod 444 $@
280
281 %.itex : %.lprl
282         @$(RM) $@
283         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
284         @chmod 444 $@
285
286 %.sh : %.lsh
287         @$(RM) $@
288         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
289         @chmod 444 $@
290
291 %.itxi : %.lsh
292         @$(RM) $@
293         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
294         @chmod 444 $@
295
296 %.ihtml : %.lsh
297         @$(RM) $@
298         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
299         @chmod 444 $@
300
301 %.itex : %.lsh
302         @$(RM) $@
303         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
304         @chmod 444 $@
305
306 %.c : %.lc
307         @$(RM) $@
308         $(UNLIT) $< $@
309         @chmod 444 $@
310
311 %.itxi : %.lc
312         @$(RM) $@
313         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
314         @chmod 444 $@
315
316 %.ihtml : %.lc
317         @$(RM) $@
318         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
319         @chmod 444 $@
320
321 %.itex : %.lc
322         @$(RM) $@
323         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
324         @chmod 444 $@
325
326 %.h : %.lh
327         @$(RM) $@
328         $(UNLIT) $< $@
329         @chmod 444 $@
330
331 %.itxi : %.lh
332         @$(RM) $@
333         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
334         @chmod 444 $@
335
336 %.ihtml : %.lh
337         @$(RM) $@
338         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
339         @chmod 444 $@
340
341 %.itex : %.lh
342         @$(RM) $@
343         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
344         @chmod 444 $@
345
346 %.flex : %.lflex
347         @$(RM) $@
348         $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
349         @chmod 444 $@
350
351 %.itxi : %.lflex
352         @$(RM) $@
353         $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
354         @chmod 444 $@
355
356 %.ihtml : %.lflex
357         @$(RM) $@
358         $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
359         @chmod 444 $@
360
361 %.itex : %.lflex
362         @$(RM) $@
363         $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
364         @chmod 444 $@
365