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