[project @ 2005-01-27 12:47:05 by simonpj]
[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 # This line prevents GNU make from deleting any intermediate targets:
26
27 .SECONDARY:
28
29 #-----------------------------------------------------------------------------
30 # Haskell Suffix Rules
31
32 # The $(odir) support is for building GHC, where we need to build three
33 # different versions from the same sources.  See ghc/compiler/Makefile.
34 ifneq "$(odir)" ""
35 odir_ = $(odir)/
36 else
37 odir_ =
38 endif
39
40 # Turn off all the Haskell suffix rules if we're booting from .hc
41 # files.  The file bootstrap.mk contains alternative suffix rules in
42 # this case.
43 ifneq "$(BootingFromHc)" "YES"
44
45 $(odir_)%.$(way_)o : %.hs
46         $(HC_PRE_OPTS)
47         $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
48         $(HC_POST_OPTS)
49
50 $(odir_)%.$(way_)o-boot : %.hs-boot
51         $(HC_PRE_OPTS)
52         $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi-boot
53         $(HC_POST_OPTS)
54
55 $(odir_)%.$(way_)o : %.lhs       
56         $(HC_PRE_OPTS)
57         $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
58         $(HC_POST_OPTS)
59
60 $(odir_)%.$(way_)o-boot : %.lhs-boot
61         $(HC_PRE_OPTS)
62         $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi-boot
63         $(HC_POST_OPTS)
64
65 $(odir_)%.$(way_)hc : %.lhs      
66         $(RM) $@
67         $(HC) $(HC_OPTS) -C $< -o $@
68
69 $(odir_)%.$(way_)hc : %.hs       
70         $(RM) $@
71         $(HC) $(HC_OPTS) -C $< -o $@
72
73 $(odir_)%.$(way_)o : %.$(way_)hc
74         $(HC_PRE_OPTS)
75         $(HC) $(HC_OPTS) -c $< -o $@
76         $(HC_POST_OPTS)
77
78 $(odir_)%.$(way_)o : %.hc
79         $(HC_PRE_OPTS)
80         $(HC) $(HC_OPTS) -c $< -o $@
81         $(HC_POST_OPTS)
82
83 $(odir_)%.$(way_)s : %.$(way_)hc 
84         $(HC_PRE_OPTS)
85         $(HC) $(HC_OPTS) -S $< -o $@
86         $(HC_POST_OPTS)
87
88 $(odir_)%.$(way_)hc : %.lhc
89         @$(RM) $@
90         $(UNLIT) $< $@
91         @chmod 444 $@
92
93
94 # Here's an interesting rule!
95 # The .hi file depends on the .o file,
96 # so if the .hi file is dated earlier than the .o file (commonly the case,
97 # when interfaces are stable) this rule just makes sure that the .o file,
98 # is up to date.  Then it does nothing to generate the .hi file from the 
99 # .o file, because the act of making sure the .o file is up to date also
100 # updates the .hi file (if necessary).
101
102 %.$(way_)hi : %.$(way_)o
103         @if [ ! -f $@ ] ; then \
104             echo Panic! $< exists, but $@ does not.; \
105             exit 1; \
106         else exit 0 ; \
107         fi                                                      
108
109 %.$(way_)hi-boot : %.$(way_)o-boot
110         @if [ ! -f $@ ] ; then \
111             echo Panic! $< exists, but $@ does not.; \
112             exit 1; \
113         else exit 0 ; \
114         fi                                                      
115
116 $(odir_)%.$(way_)hi : %.$(way_)hc
117         @if [ ! -f $@ ] ; then \
118             echo Panic! $< exists, but $@ does not.; \
119             exit 1; \
120         else exit 0 ; \
121         fi
122
123 else # BootingFromHc
124
125 # -----------------------------------------------------------------------------
126 # suffix rules for building a .o from a .hc file in bootstrap mode.
127
128 ifeq "$(BootingFromUnregisterisedHc)" "YES"
129
130 # without mangling
131
132 $(odir_)%.o : %.hc
133         $(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/'`
134
135 else
136
137 # with mangling
138
139 $(odir_)%.raw_s : %.hc
140         $(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/'`
141
142 $(odir_)%.s : %.raw_s
143         $(GHC_MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
144
145 $(odir_)%.o : %.s
146         $(CC) -c -o $@ $<
147
148 endif # not BootingFromUnregisterisedHc
149
150 endif # BootingFromHc
151
152 #-----------------------------------------------------------------------------
153 # Happy Suffix Rules
154 #
155 %.hs : %.ly
156         $(HAPPY) $(HAPPY_OPTS) $<
157
158 %.hs : %.y
159         $(HAPPY) $(HAPPY_OPTS) $<
160
161 #-----------------------------------------------------------------------------
162 # Alex Suffix Rules
163 #
164
165 %.hs : %.x
166         $(ALEX) $(ALEX_OPTS) $<
167
168 #-----------------------------------------------------------------------------
169 # hsc2hs Suffix Rules
170 #
171 ifneq "$(BootingFromHc)" "YES"
172 %_hsc.c %_hsc.h %.hs : %.hsc
173         $(HSC2HS) $(HSC2HS_OPTS) $<
174         @touch $(patsubst %.hsc,%_hsc.c,$<)
175 endif
176
177 #-----------------------------------------------------------------------------
178 # Green-card Suffix Rules
179 #
180
181 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
182         $(GREENCARD) $(GC_OPTS) $<
183
184 %.lhs : %.gc
185         $(GREENCARD) $(GC_OPTS) $< -o $@
186
187 %.gc : %.pgc
188         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
189
190 #-----------------------------------------------------------------------------
191 # C-related suffix rules
192
193 # UseGhcForCc is only relevant when not booting from HC files.
194 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
195
196 $(odir_)%.$(way_)o : %.c
197         @$(RM) $@
198         $(HC) $(GHC_CC_OPTS) -c $< -o $@
199
200 $(odir_)%.$(way_)o : %.$(way_)s
201         @$(RM) $@
202         $(HC) $(GHC_CC_OPTS) -c $< -o $@
203
204 $(odir_)%.$(way_)o : %.S
205         @$(RM) $@
206         $(HC) $(GHC_CC_OPTS) -c $< -o $@
207
208 $(odir_)%.$(way_)s : %.c
209         @$(RM) $@
210         $(HC) $(GHC_CC_OPTS) -S $< -o $@
211
212 else
213
214 $(odir_)%.$(way_)o : %.c
215         @$(RM) $@
216         $(CC) $(CC_OPTS) -c $< -o $@
217
218 $(odir_)%.$(way_)o : %.$(way_)s
219         @$(RM) $@
220         $(AS) $(AS_OPTS) -o $@ $<
221
222 $(odir_)%.$(way_)o : %.S
223         @$(RM) $@
224         $(CC) $(CC_OPTS) -c $< -o $@
225
226 $(odir_)%.$(way_)s : %.c
227         @$(RM) $@
228         $(CC) $(CC_OPTS) -S $< -o $@
229
230 endif
231
232 # stubs are automatically generated and compiled by GHC
233 %_stub.$(way_)o: %.o
234         @:
235
236 # -----------------------------------------------------------------------------
237 # Flex/lex
238
239 %.c : %.flex
240         @$(RM) $@
241         $(FLEX) -t $(FLEX_OPTS) $< > $@
242 %.c : %.lex
243         @$(RM) $@
244         $(FLEX) -t $(FLEX_OPTS) $< > $@
245
246 #-----------------------------------------------------------------------------
247 # Runtest rules for calling $(HC) on a single-file Haskell program
248
249 %.runtest : %.hs
250         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
251
252 #-----------------------------------------------------------------------------
253 # DocBook XML suffix rules
254 #
255
256 %.html : %.xml
257         $(XSLTPROC) --output $@ \
258                     --stringparam html.stylesheet $(FPTOOLS_CSS) \
259                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
260                     $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
261         cp $(FPTOOLS_CSS_ABS) .
262
263 %/index.html : %.xml
264         $(RM) -rf $(dir $@)
265         $(XSLTPROC) --stringparam base.dir $(dir $@) \
266                     --stringparam use.id.as.filename 1 \
267                     --stringparam html.stylesheet $(FPTOOLS_CSS) \
268                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
269                     $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
270         cp $(FPTOOLS_CSS_ABS) $(dir $@)
271
272 # Note: Numeric labeling seems to be uncommon for HTML Help
273 %-htmlhelp/index.html : %.xml
274         $(RM) -rf $(dir $@)
275         $(XSLTPROC) --stringparam base.dir $(dir $@) \
276                     --stringparam manifest.in.base.dir 1 \
277                     --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
278                     $(XSLTPROC_OPTS) \
279                     $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
280
281 # TODO: Detect hhc via autoconf
282 #
283 # Two obstables here:
284 #
285 # * The reason for the strange "if" below is that hhc returns 0 on error and 1
286 #   on success, the opposite of what shells and make expect.
287 #
288 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
289 #   anyway, therefore we pacify make by "|| true". Ugly...
290 #
291 %.chm : %-htmlhelp/index.html
292         ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
293
294 %.fo : %.xml
295         $(XSLTPROC) --output $@ \
296                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
297                     $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
298
299 ifeq "$(FOP)" ""
300 ifneq "$(PDFXMLTEX)" ""
301 %.pdf : %.fo
302         $(PDFXMLTEX) $<
303         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
304           $(PDFXMLTEX) $< ; \
305           $(PDFXMLTEX) $< ; \
306         fi
307 endif
308 else
309 %.ps : %.fo
310         $(FOP) $(FOP_OPTS) -fo $< -ps $@
311
312 %.pdf : %.fo
313         $(FOP) $(FOP_OPTS) -fo $< -pdf $@
314 endif
315
316 ifneq "$(XMLTEX)" ""
317 %.dvi : %.fo
318         $(XMLTEX) $<
319         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
320           $(XMLTEX) $< ; \
321           $(XMLTEX) $< ; \
322         fi
323 endif
324
325 #-----------------------------------------------------------------------------
326 # Doc processing suffix rules
327 #
328 # ToDo: make these more robust
329 #
330 %.ps : %.dvi
331         @$(RM) $@
332         $(DVIPS) $< -o $@
333
334 %.tex : %.tib
335         @$(RM) $*.tex $*.verb-t.tex
336         $(TIB) $*.tib
337         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
338         @$(RM) $*.tib-t.tex
339
340 %.ps : %.fig
341         @$(RM) $@
342         fig2dev -L ps $< $@
343
344 %.tex : %.fig
345         @$(RM) $@
346         fig2dev -L latex $< $@
347
348 #-----------------------------------------------------------------------------
349 # Literate suffix rules
350
351 %.prl : %.lprl
352         @$(RM) $@
353         $(UNLIT) $(UNLIT_OPTS) $< $@
354         @chmod 444 $@
355
356 %.c : %.lc
357         @$(RM) $@
358         $(UNLIT) $(UNLIT_OPTS) $< $@
359         @chmod 444 $@
360
361 %.h : %.lh
362         @$(RM) $@
363         $(UNLIT) $(UNLIT_OPTS) $< $@
364         @chmod 444 $@
365
366 #-----------------------------------------------------------------------------
367 # Win32 resource files
368 #
369 # The default is to use the GNU resource compiler.
370 #
371
372 %.$(way_)o : %.$(way_)rc
373         @$(RM) $@
374         windres $< $@
375
376 #-----------------------------------------------------------------------------
377 # Preprocessor suffix rule
378
379 # Note use of -P option to prevent #line pragmas being left in the CPP
380 # output.
381
382 % : %.pp
383         @$(RM) $@
384         $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
385         grep -v '^#pragma GCC' > $@