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