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