[project @ 2003-07-24 11:03:07 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 # The $(odir) support is for building GHC, where we need to build three
29 # different versions from the same sources.  See ghc/compiler/Makefile.
30 ifneq "$(odir)" ""
31 odir_ = $(odir)/
32 else
33 odir_ =
34 endif
35
36 # Turn off all the Haskell suffix rules if we're booting from .hc
37 # files.  The file bootstrap.mk contains alternative suffix rules in
38 # this case.
39 ifneq "$(BootingFromHc)" "YES"
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 else # BootingFromHc
103
104 # -----------------------------------------------------------------------------
105 # suffix rules for building a .o from a .hc file in bootstrap mode.
106
107 ifeq "$(BootingFromUnregisterisedHc)" "YES"
108
109 # without mangling
110
111 $(odir_)%.o : %.hc
112         $(CC) -x c $< -o $@ -c -O $(HC_BOOT_CC_OPTS) -I.  `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
113
114 else
115
116 # with mangling
117
118 $(odir_)%.raw_s : %.hc
119         $(CC) -x c $< -o $@ -S -O $(HC_BOOT_CC_OPTS) -I.  `echo $(patsubst -monly-%-regs, -DSTOLEN_X86_REGS=%, $(filter -monly-%-regs, $($*_HC_OPTS))) | sed 's/^$$/-DSTOLEN_X86_REGS=4/'`
120
121 $(odir_)%.s : %.raw_s
122         $(GHC_MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
123
124 $(odir_)%.o : %.s
125         $(CC) -c -o $@ $<
126
127 endif # not BootingFromUnregisterisedHc
128
129 endif # BootingFromHc
130
131 #-----------------------------------------------------------------------------
132 # Happy Suffix Rules
133 #
134 .SECONDARY: %.hs
135
136 %.hs : %.ly
137         $(HAPPY) $(HAPPY_OPTS) $<
138
139 %.hs : %.y
140         $(HAPPY) $(HAPPY_OPTS) $<
141
142 #-----------------------------------------------------------------------------
143 # hsc2hs Suffix Rules
144 #
145 ifneq "$(BootingFromHc)" "YES"
146 %_hsc.c %_hsc.h %.hs : %.hsc
147         $(HSC2HS) $(HSC2HS_OPTS) $<
148         @touch $(patsubst %.hsc,%_hsc.c,$<)
149 endif
150
151 #-----------------------------------------------------------------------------
152 # Lx Suffix Rules
153 #
154
155 %.hs : %.lx
156         $(LX) $(LX_OPTS) $<
157
158 #-----------------------------------------------------------------------------
159 # Green-card Suffix Rules
160 #
161
162 .PRECIOUS: %.gc
163
164 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
165         $(GREENCARD) $(GC_OPTS) $<
166
167 %.lhs : %.gc
168         $(GREENCARD) $(GC_OPTS) $< -o $@
169
170 %.gc : %.pgc
171         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
172
173 #-----------------------------------------------------------------------------
174 # C-related suffix rules
175
176 # UseGhcForCc is only relevant when not booting from HC files.
177 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
178
179 $(odir_)%.$(way_)o : %.c
180         @$(RM) $@
181         $(HC) $(GHC_CC_OPTS) -c $< -o $@
182
183 $(odir_)%.$(way_)o : %.$(way_)s
184         @$(RM) $@
185         $(HC) $(GHC_CC_OPTS) -c $< -o $@
186
187 $(odir_)%.$(way_)o : %.S
188         @$(RM) $@
189         $(HC) $(GHC_CC_OPTS) -c $< -o $@
190
191 $(odir_)%.$(way_)s : %.c
192         @$(RM) $@
193         $(HC) $(GHC_CC_OPTS) -S $< -o $@
194
195 else
196
197 $(odir_)%.$(way_)o : %.c
198         @$(RM) $@
199         $(CC) $(CC_OPTS) -c $< -o $@
200
201 $(odir_)%.$(way_)o : %.$(way_)s
202         @$(RM) $@
203         $(AS) $(AS_OPTS) -o $@ $<
204
205 $(odir_)%.$(way_)o : %.S
206         @$(RM) $@
207         $(CC) $(CC_OPTS) -c $< -o $@
208
209 $(odir_)%.$(way_)s : %.c
210         @$(RM) $@
211         $(CC) $(CC_OPTS) -S $< -o $@
212
213 endif
214
215 # stubs are automatically generated and compiled by GHC
216 %_stub.$(way_)o: %.o
217         @:
218
219 # -----------------------------------------------------------------------------
220 # Flex/lex
221
222 %.c : %.flex
223         @$(RM) $@
224         $(FLEX) -t $(FLEX_OPTS) $< > $@
225 %.c : %.lex
226         @$(RM) $@
227         $(FLEX) -t $(FLEX_OPTS) $< > $@
228
229 #-----------------------------------------------------------------------------
230 # Yacc stuff
231
232 %.tab.c %.tab.h : %.y
233         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
234         $(YACC) $(YACC_OPTS) $<
235         $(MV) y.tab.c $*.tab.c
236         @chmod 444 $*.tab.c
237         $(MV) y.tab.h $*.tab.h
238         @chmod 444 $*.tab.h
239
240
241 #-----------------------------------------------------------------------------
242 # Runtest rules for calling $(HC) on a single-file Haskell program
243
244 %.runtest : %.hs
245         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
246
247 #-----------------------------------------------------------------------------
248 # Doc processing suffix rules
249 #
250 # ToDo: make these more robust
251 #
252 %.ps : %.dvi
253         @$(RM) $@
254         dvips $< -o $@
255
256 %.tex : %.tib
257         @$(RM) $*.tex $*.verb-t.tex
258         $(TIB) $*.tib
259         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
260         @$(RM) $*.tib-t.tex
261
262 %.ps : %.fig
263         @$(RM) $@
264         fig2dev -L ps $< $@
265
266 %.tex : %.fig
267         @$(RM) $@
268         fig2dev -L latex $< $@
269
270 #-----------------------------------------------------------------------------
271 # SGML suffix rules
272 #
273 %.dvi : %.sgml
274         @$(RM) $@
275         $(SGML2DVI) $(SGML2DVI_OPTS) $<
276
277 %.ps : %.sgml
278         @$(RM) $@
279         $(SGML2PS) $(SGML2PS_OPTS) $<
280
281 %.html : %.sgml
282         @$(RM) $@
283 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
284 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
285 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
286         $(SGML2HTML) $(SGML2HTML_OPTS) $<
287 # touch the .html file so that it is seen to be built
288         @touch $@
289
290 %.html : %.tex
291         @$(RM) $@
292         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
293         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
294         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
295 # Run HeVeA twice to resolve labels
296
297 %.rtf : %.sgml
298         @$(RM) $@
299         $(SGML2RTF) $(SGML2RTF_OPTS) $<
300
301 %.pdf : %.sgml
302         @$(RM) $@
303         $(SGML2PDF) $(SGML2PDF_OPTS) $<
304
305 #-----------------------------------------------------------------------------
306 # Literate suffix rules
307
308 %.prl : %.lprl
309         @$(RM) $@
310         $(UNLIT) $(UNLIT_OPTS) $< $@
311         @chmod 444 $@
312
313 %.c : %.lc
314         @$(RM) $@
315         $(UNLIT) $(UNLIT_OPTS) $< $@
316         @chmod 444 $@
317
318 %.h : %.lh
319         @$(RM) $@
320         $(UNLIT) $(UNLIT_OPTS) $< $@
321         @chmod 444 $@
322
323 #-----------------------------------------------------------------------------
324 # Win32 resource files
325 #
326 # The default is to use the GNU resource compiler.
327 #
328
329 %.$(way_)o : %.$(way_)rc
330         @$(RM) $@
331         windres $< $@
332
333 #-----------------------------------------------------------------------------
334 # Preprocessor suffix rule
335
336 % : %.pp
337         @$(RM) $@
338         $(CPP) $(RAWCPP_FLAGS) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@