[project @ 2003-07-23 15:12:55 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 # UseGhcForCc is only relevant when not booting from HC files.
150 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
151
152 $(odir_)%.$(way_)o : %.c
153         @$(RM) $@
154         $(HC) $(GHC_CC_OPTS) -c $< -o $@
155
156 $(odir_)%.$(way_)o : %.$(way_)s
157         @$(RM) $@
158         $(HC) $(GHC_CC_OPTS) -c $< -o $@
159
160 $(odir_)%.$(way_)o : %.S
161         @$(RM) $@
162         $(HC) $(GHC_CC_OPTS) -c $< -o $@
163
164 $(odir_)%.$(way_)s : %.c
165         @$(RM) $@
166         $(HC) $(GHC_CC_OPTS) -S $< -o $@
167
168 else
169
170 $(odir_)%.$(way_)o : %.c
171         @$(RM) $@
172         $(CC) $(CC_OPTS) -c $< -o $@
173
174 $(odir_)%.$(way_)o : %.$(way_)s
175         @$(RM) $@
176         $(AS) $(AS_OPTS) -o $@ $<
177
178 $(odir_)%.$(way_)o : %.S
179         @$(RM) $@
180         $(CC) $(CC_OPTS) -c $< -o $@
181
182 $(odir_)%.$(way_)s : %.c
183         @$(RM) $@
184         $(CC) $(CC_OPTS) -S $< -o $@
185
186 endif
187
188 # stubs are automatically generated and compiled by GHC
189 %_stub.$(way_)o: %.o
190         @:
191
192 # -----------------------------------------------------------------------------
193 # Flex/lex
194
195 %.c : %.flex
196         @$(RM) $@
197         $(FLEX) -t $(FLEX_OPTS) $< > $@
198 %.c : %.lex
199         @$(RM) $@
200         $(FLEX) -t $(FLEX_OPTS) $< > $@
201
202 #-----------------------------------------------------------------------------
203 # Yacc stuff
204
205 %.tab.c %.tab.h : %.y
206         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
207         $(YACC) $(YACC_OPTS) $<
208         $(MV) y.tab.c $*.tab.c
209         @chmod 444 $*.tab.c
210         $(MV) y.tab.h $*.tab.h
211         @chmod 444 $*.tab.h
212
213
214 #-----------------------------------------------------------------------------
215 # Runtest rules for calling $(HC) on a single-file Haskell program
216
217 %.runtest : %.hs
218         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
219
220 #-----------------------------------------------------------------------------
221 # Doc processing suffix rules
222 #
223 # ToDo: make these more robust
224 #
225 %.ps : %.dvi
226         @$(RM) $@
227         dvips $< -o $@
228
229 %.tex : %.tib
230         @$(RM) $*.tex $*.verb-t.tex
231         $(TIB) $*.tib
232         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
233         @$(RM) $*.tib-t.tex
234
235 %.ps : %.fig
236         @$(RM) $@
237         fig2dev -L ps $< $@
238
239 %.tex : %.fig
240         @$(RM) $@
241         fig2dev -L latex $< $@
242
243 #-----------------------------------------------------------------------------
244 # SGML suffix rules
245 #
246 %.dvi : %.sgml
247         @$(RM) $@
248         $(SGML2DVI) $(SGML2DVI_OPTS) $<
249
250 %.ps : %.sgml
251         @$(RM) $@
252         $(SGML2PS) $(SGML2PS_OPTS) $<
253
254 %.html : %.sgml
255         @$(RM) $@
256 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
257 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
258 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
259         $(SGML2HTML) $(SGML2HTML_OPTS) $<
260 # touch the .html file so that it is seen to be built
261         @touch $@
262
263 %.html : %.tex
264         @$(RM) $@
265         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
266         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
267         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
268 # Run HeVeA twice to resolve labels
269
270 %.rtf : %.sgml
271         @$(RM) $@
272         $(SGML2RTF) $(SGML2RTF_OPTS) $<
273
274 %.pdf : %.sgml
275         @$(RM) $@
276         $(SGML2PDF) $(SGML2PDF_OPTS) $<
277
278 #-----------------------------------------------------------------------------
279 # Literate suffix rules
280
281 %.prl : %.lprl
282         @$(RM) $@
283         $(UNLIT) $(UNLIT_OPTS) $< $@
284         @chmod 444 $@
285
286 %.c : %.lc
287         @$(RM) $@
288         $(UNLIT) $(UNLIT_OPTS) $< $@
289         @chmod 444 $@
290
291 %.h : %.lh
292         @$(RM) $@
293         $(UNLIT) $(UNLIT_OPTS) $< $@
294         @chmod 444 $@
295
296 #-----------------------------------------------------------------------------
297 # Win32 resource files
298 #
299 # The default is to use the GNU resource compiler.
300 #
301
302 %.$(way_)o : %.$(way_)rc
303         @$(RM) $@
304         windres $< $@
305
306 #-----------------------------------------------------------------------------
307 # Preprocessor suffix rule
308
309 % : %.pp
310         @$(RM) $@
311         $(CPP) $(RAWCPP_FLAGS) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@