[project @ 2002-09-30 10:22:37 by simonmar]
[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 # This declaration tells GNU make to delete the target if it has
20 # changed and the command which created it exited with a non-zero exit
21 # code.
22
23 .DELETE_ON_ERROR:
24
25 # However, if $(way) is set then we have to define $(way_) and $(_way)
26 # from it in the obvious fashion.
27 # This must be done here (or earlier), but not in target.mk with the other
28 # way management, because the pattern rules in this file take a snapshot of
29 # the value of $(way_) and $(_way), and it's no good setting them later!
30
31 ifneq "$(way)" ""
32   way_ := $(way)_
33   _way := _$(way)
34 endif
35
36 #-----------------------------------------------------------------------------
37 # Haskell Suffix Rules
38
39 # Turn off all the Haskell suffix rules if we're booting from .hc
40 # files.  The file bootstrap.mk contains alternative suffix rules in
41 # this case.
42 ifneq "$(BootingFromHc)" "YES"
43
44 %.$(way_)o : %.hs
45         $(HC_PRE_OPTS)
46         $(HC) $(HC_OPTS) -c $< -o $@
47         $(HC_POST_OPTS)
48
49 %.$(way_)o : %.lhs       
50         $(HC_PRE_OPTS)
51         $(HC) $(HC_OPTS) -c $< -o $@
52         $(HC_POST_OPTS)
53
54 %.$(way_)hc : %.lhs      
55         $(RM) $@
56         $(HC) $(HC_OPTS) -C $< -o $@
57
58 %.$(way_)hc : %.hs       
59         $(RM) $@
60         $(HC) $(HC_OPTS) -C $< -o $@
61
62 %.$(way_)o : %.$(way_)hc 
63         $(HC_PRE_OPTS)
64         $(HC) $(HC_OPTS) -c $< -o $@
65         $(HC_POST_OPTS)
66
67 %.$(way_)o : %.hc 
68         $(HC_PRE_OPTS)
69         $(HC) $(HC_OPTS) -c $< -o $@
70         $(HC_POST_OPTS)
71
72 %.$(way_)s : %.$(way_)hc 
73         $(HC_PRE_OPTS)
74         $(HC) $(HC_OPTS) -S $< -o $@
75         $(HC_POST_OPTS)
76
77 %.$(way_)hc : %.lhc
78         @$(RM) $@
79         $(UNLIT) $< $@
80         @chmod 444 $@
81
82
83 # Here's an interesting rule!
84 # The .hi file depends on the .o file,
85 # so if the .hi file is dated earlier than the .o file (commonly the case,
86 # when interfaces are stable) this rule just makes sure that the .o file,
87 # is up to date.  Then it does nothing to generate the .hi file from the 
88 # .o file, because the act of making sure the .o file is up to date also
89 # updates the .hi file (if necessary).
90
91 %.$(way_)hi : %.$(way_)o
92         @if [ ! -f $@ ] ; then \
93             echo Panic! $< exists, but $@ does not.; \
94             exit 1; \
95         else exit 0 ; \
96         fi                                                      
97
98 %.$(way_)hi : %.$(way_)hc
99         @if [ ! -f $@ ] ; then \
100             echo Panic! $< exists, but $@ does not.; \
101             exit 1; \
102         else exit 0 ; \
103         fi
104
105 endif # BootingViaC
106
107 #-----------------------------------------------------------------------------
108 # Happy Suffix Rules
109 #
110 .SECONDARY: %.hs
111
112 %.hs : %.ly
113         $(HAPPY) $(HAPPY_OPTS) $<
114
115 %.hs : %.y
116         $(HAPPY) $(HAPPY_OPTS) $<
117
118 #-----------------------------------------------------------------------------
119 # hsc2hs Suffix Rules
120 #
121 ifneq "$(BootingFromHc)" "YES"
122 %_hsc.c %_hsc.h %.hs : %.hsc
123         $(HSC2HS) $(HSC2HS_OPTS) $<
124         @touch $(patsubst %.hsc,%_hsc.c,$<)
125 endif
126
127 #-----------------------------------------------------------------------------
128 # Lx Suffix Rules
129 #
130
131 %.hs : %.lx
132         $(LX) $(LX_OPTS) $<
133
134 #-----------------------------------------------------------------------------
135 # Green-card Suffix Rules
136 #
137
138 .PRECIOUS: %.gc
139
140 %.hs : %.gc
141         $(GREENCARD) $(GC_OPTS) $< -o $@
142
143 %.lhs : %.gc
144         $(GREENCARD) $(GC_OPTS) $< -o $@
145
146 %.gc : %.pgc
147         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
148
149 #-----------------------------------------------------------------------------
150 # C-related suffix rules
151
152 ifeq "$(UseGhcForCc)" "YES"
153
154 %.$(way_)o : %.$(way_)s
155         @$(RM) $@
156         $(HC) $(GHC_CC_OPTS) -c $< -o $@
157
158 %.$(way_)o : %.c
159         @$(RM) $@
160         $(HC) $(GHC_CC_OPTS) -c $< -o $@
161
162 %.$(way_)o : %.S
163         @$(RM) $@
164         $(HC) $(GHC_CC_OPTS) -c $< -o $@
165
166 %.$(way_)s : %.c
167         @$(RM) $@
168         $(HC) $(GHC_CC_OPTS) -S $< -o $@
169
170 else
171
172 %.$(way_)o : %.$(way_)s
173         @$(RM) $@
174         $(AS) $(AS_OPTS) -o $@ $<
175
176 %.$(way_)o : %.c
177         @$(RM) $@
178         $(CC) $(CC_OPTS) -c $< -o $@
179
180 %.$(way_)o : %.S
181         @$(RM) $@
182         $(CC) $(CC_OPTS) -c $< -o $@
183
184 %.$(way_)s : %.c
185         @$(RM) $@
186         $(CC) $(CC_OPTS) -S $< -o $@
187
188 endif
189
190 # stubs are automatically generated and compiled by GHC
191 %_stub.$(way_)o: %.o
192         @:
193
194 # -----------------------------------------------------------------------------
195 # Flex/lex
196
197 %.c : %.flex
198         @$(RM) $@
199         $(FLEX) -t $(FLEX_OPTS) $< > $@
200 %.c : %.lex
201         @$(RM) $@
202         $(FLEX) -t $(FLEX_OPTS) $< > $@
203
204 #-----------------------------------------------------------------------------
205 # Yacc stuff
206
207 %.tab.c %.tab.h : %.y
208         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
209         $(YACC) $(YACC_OPTS) $<
210         $(MV) y.tab.c $*.tab.c
211         @chmod 444 $*.tab.c
212         $(MV) y.tab.h $*.tab.h
213         @chmod 444 $*.tab.h
214
215
216 #-----------------------------------------------------------------------------
217 # Runtest rules for calling $(HC) on a single-file Haskell program
218
219 %.runtest : %.hs
220         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
221
222 #-----------------------------------------------------------------------------
223 # Doc processing suffix rules
224 #
225 # ToDo: make these more robust
226 #
227 %.ps : %.dvi
228         @$(RM) $@
229         dvips $< -o $@
230
231 %.tex : %.tib
232         @$(RM) $*.tex $*.verb-t.tex
233         $(TIB) $*.tib
234         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
235         @$(RM) $*.tib-t.tex
236
237 %.ps : %.fig
238         @$(RM) $@
239         fig2dev -L ps $< $@
240
241 %.tex : %.fig
242         @$(RM) $@
243         fig2dev -L latex $< $@
244
245 #-----------------------------------------------------------------------------
246 # SGML suffix rules
247 #
248 %.dvi : %.sgml
249         @$(RM) $@
250         $(SGML2DVI) $(SGML2DVI_OPTS) $<
251
252 %.ps : %.sgml
253         @$(RM) $@
254         $(SGML2PS) $(SGML2PS_OPTS) $<
255
256 %.html : %.sgml
257         @$(RM) $@
258 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
259 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
260 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
261         $(SGML2HTML) $(SGML2HTML_OPTS) $<
262 # touch the .html file so that it is seen to be built
263         @touch $@
264
265 %.html : %.tex
266         @$(RM) $@
267         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
268         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
269         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
270 # Run HeVeA twice to resolve labels
271
272 %.rtf : %.sgml
273         @$(RM) $@
274         $(SGML2RTF) $(SGML2RTF_OPTS) $<
275
276 %.pdf : %.sgml
277         @$(RM) $@
278         $(SGML2PDF) $(SGML2PDF_OPTS) $<
279
280 #-----------------------------------------------------------------------------
281 # Literate suffix rules
282
283 %.prl : %.lprl
284         @$(RM) $@
285         $(UNLIT) $(UNLIT_OPTS) $< $@
286         @chmod 444 $@
287
288 %.c : %.lc
289         @$(RM) $@
290         $(UNLIT) $(UNLIT_OPTS) $< $@
291         @chmod 444 $@
292
293 %.h : %.lh
294         @$(RM) $@
295         $(UNLIT) $(UNLIT_OPTS) $< $@
296         @chmod 444 $@
297
298 #-----------------------------------------------------------------------------
299 # Win32 resource files
300 #
301 # The default is to use the GNU resource compiler.
302 #
303
304 %.$(way_)o : %.$(way_)rc
305         @$(RM) $@
306         windres $< $@
307
308 #-----------------------------------------------------------------------------
309 # Preprocessor suffix rule
310
311 % : %.pp
312         rm -f $@
313         $(CPP) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@