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