[project @ 2004-08-18 16:23:14 by panne]
[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 # Alex Suffix Rules
144 #
145
146 %.hs : %.x
147         $(ALEX) $(ALEX_OPTS) $<
148
149 #-----------------------------------------------------------------------------
150 # hsc2hs Suffix Rules
151 #
152 ifneq "$(BootingFromHc)" "YES"
153 %_hsc.c %_hsc.h %.hs : %.hsc
154         $(HSC2HS) $(HSC2HS_OPTS) $<
155         @touch $(patsubst %.hsc,%_hsc.c,$<)
156 endif
157
158 #-----------------------------------------------------------------------------
159 # Lx Suffix Rules
160 #
161
162 %.hs : %.lx
163         $(LX) $(LX_OPTS) $<
164
165 #-----------------------------------------------------------------------------
166 # Green-card Suffix Rules
167 #
168
169 .PRECIOUS: %.gc
170
171 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
172         $(GREENCARD) $(GC_OPTS) $<
173
174 %.lhs : %.gc
175         $(GREENCARD) $(GC_OPTS) $< -o $@
176
177 %.gc : %.pgc
178         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
179
180 #-----------------------------------------------------------------------------
181 # C-related suffix rules
182
183 # UseGhcForCc is only relevant when not booting from HC files.
184 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
185
186 $(odir_)%.$(way_)o : %.c
187         @$(RM) $@
188         $(HC) $(GHC_CC_OPTS) -c $< -o $@
189
190 $(odir_)%.$(way_)o : %.$(way_)s
191         @$(RM) $@
192         $(HC) $(GHC_CC_OPTS) -c $< -o $@
193
194 $(odir_)%.$(way_)o : %.S
195         @$(RM) $@
196         $(HC) $(GHC_CC_OPTS) -c $< -o $@
197
198 $(odir_)%.$(way_)s : %.c
199         @$(RM) $@
200         $(HC) $(GHC_CC_OPTS) -S $< -o $@
201
202 else
203
204 $(odir_)%.$(way_)o : %.c
205         @$(RM) $@
206         $(CC) $(CC_OPTS) -c $< -o $@
207
208 $(odir_)%.$(way_)o : %.$(way_)s
209         @$(RM) $@
210         $(AS) $(AS_OPTS) -o $@ $<
211
212 $(odir_)%.$(way_)o : %.S
213         @$(RM) $@
214         $(CC) $(CC_OPTS) -c $< -o $@
215
216 $(odir_)%.$(way_)s : %.c
217         @$(RM) $@
218         $(CC) $(CC_OPTS) -S $< -o $@
219
220 endif
221
222 # stubs are automatically generated and compiled by GHC
223 %_stub.$(way_)o: %.o
224         @:
225
226 # -----------------------------------------------------------------------------
227 # Flex/lex
228
229 %.c : %.flex
230         @$(RM) $@
231         $(FLEX) -t $(FLEX_OPTS) $< > $@
232 %.c : %.lex
233         @$(RM) $@
234         $(FLEX) -t $(FLEX_OPTS) $< > $@
235
236 #-----------------------------------------------------------------------------
237 # Runtest rules for calling $(HC) on a single-file Haskell program
238
239 %.runtest : %.hs
240         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
241
242 #-----------------------------------------------------------------------------
243 # DocBook XML suffix rules
244 #
245
246 %.html : %.xml
247         $(XSLTPROC) --output $@ \
248                     --stringparam toc.section.depth 3 \
249                     --stringparam section.autolabel 1 \
250                     --stringparam section.label.includes.component.label 1 \
251                     --stringparam html.stylesheet fptools.css \
252                     $(XSLTPROC_OPTS) $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
253         cp $(FPTOOLS_CSS) .
254
255 %-html/index.html : %.xml
256         $(RM) -rf $(dir $@)
257         $(XSLTPROC) --stringparam base.dir $(dir $@) \
258                     --stringparam use.id.as.filename 1 \
259                     --stringparam toc.section.depth 3 \
260                     --stringparam section.autolabel 1 \
261                     --stringparam section.label.includes.component.label 1 \
262                     --stringparam html.stylesheet fptools.css \
263                     $(XSLTPROC_OPTS) $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
264         cp $(FPTOOLS_CSS) $(dir $@)
265
266 %-htmlhelp/index.html : %.xml
267         $(RM) -rf $(dir $@)
268         $(XSLTPROC) --stringparam base.dir $(dir $@) \
269                     --stringparam manifest.in.base.dir 1 \
270                     $(XSLTPROC_OPTS) $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
271
272 %.fo : %.xml
273         $(XSLTPROC) --output $@ \
274                     $(XSLTPROC_OPTS) $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
275
276 ifeq "$(FOP)" ""
277 ifneq "$(PDFXMLTEX)" ""
278 %.pdf : %.fo
279         $(PDFXMLTEX) $<
280         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
281           $(PDFXMLTEX) $< ; \
282           $(PDFXMLTEX) $< ; \
283         fi
284 endif
285 else
286 %.ps : %.fo
287         $(FOP) $(FOP_OPTS) -fo $< -ps $@
288
289 %.pdf : %.fo
290         $(FOP) $(FOP_OPTS) -fo $< -pdf $@
291 endif
292
293 ifneq "$(XMLTEX)" ""
294 %.dvi : %.fo
295         $(XMLTEX) $<
296         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
297           $(XMLTEX) $< ; \
298           $(XMLTEX) $< ; \
299         fi
300 endif
301
302 #-----------------------------------------------------------------------------
303 # Doc processing suffix rules
304 #
305 # ToDo: make these more robust
306 #
307 %.ps : %.dvi
308         @$(RM) $@
309         $(DVIPS) $< -o $@
310
311 %.tex : %.tib
312         @$(RM) $*.tex $*.verb-t.tex
313         $(TIB) $*.tib
314         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
315         @$(RM) $*.tib-t.tex
316
317 %.ps : %.fig
318         @$(RM) $@
319         fig2dev -L ps $< $@
320
321 %.tex : %.fig
322         @$(RM) $@
323         fig2dev -L latex $< $@
324
325 #-----------------------------------------------------------------------------
326 # SGML suffix rules
327 #
328 %.dvi : %.sgml
329         @$(RM) $@
330         $(SGML2DVI) $(SGML2DVI_OPTS) $<
331
332 %.ps : %.sgml
333         @$(RM) $@
334         $(SGML2PS) $(SGML2PS_OPTS) $<
335
336 %.html : %.sgml
337         @$(RM) $@
338 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
339 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
340 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
341         $(SGML2HTML) $(SGML2HTML_OPTS) $<
342 # touch the .html file so that it is seen to be built
343         @touch $@
344
345 %.html : %.tex
346         @$(RM) $@
347         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
348         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
349         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
350 # Run HeVeA twice to resolve labels
351
352 %.rtf : %.sgml
353         @$(RM) $@
354         $(SGML2RTF) $(SGML2RTF_OPTS) $<
355
356 %.pdf : %.sgml
357         @$(RM) $@
358         $(SGML2PDF) $(SGML2PDF_OPTS) $<
359
360 #-----------------------------------------------------------------------------
361 # Literate suffix rules
362
363 %.prl : %.lprl
364         @$(RM) $@
365         $(UNLIT) $(UNLIT_OPTS) $< $@
366         @chmod 444 $@
367
368 %.c : %.lc
369         @$(RM) $@
370         $(UNLIT) $(UNLIT_OPTS) $< $@
371         @chmod 444 $@
372
373 %.h : %.lh
374         @$(RM) $@
375         $(UNLIT) $(UNLIT_OPTS) $< $@
376         @chmod 444 $@
377
378 #-----------------------------------------------------------------------------
379 # Win32 resource files
380 #
381 # The default is to use the GNU resource compiler.
382 #
383
384 %.$(way_)o : %.$(way_)rc
385         @$(RM) $@
386         windres $< $@
387
388 #-----------------------------------------------------------------------------
389 # Preprocessor suffix rule
390
391 # Note use of -P option to prevent #line pragmas being left in the CPP
392 # output.
393
394 % : %.pp
395         @$(RM) $@
396         $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< > $@