[project @ 2005-01-11 11:32:44 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 # 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 $(odir_)%.$(way_)hc : %.lhs      
56         $(RM) $@
57         $(HC) $(HC_OPTS) -C $< -o $@
58
59 $(odir_)%.$(way_)hc : %.hs       
60         $(RM) $@
61         $(HC) $(HC_OPTS) -C $< -o $@
62
63 $(odir_)%.$(way_)o : %.$(way_)hc
64         $(HC_PRE_OPTS)
65         $(HC) $(HC_OPTS) -c $< -o $@
66         $(HC_POST_OPTS)
67
68 $(odir_)%.$(way_)o : %.hc
69         $(HC_PRE_OPTS)
70         $(HC) $(HC_OPTS) -c $< -o $@
71         $(HC_POST_OPTS)
72
73 $(odir_)%.$(way_)s : %.$(way_)hc 
74         $(HC_PRE_OPTS)
75         $(HC) $(HC_OPTS) -S $< -o $@
76         $(HC_POST_OPTS)
77
78 $(odir_)%.$(way_)hc : %.lhc
79         @$(RM) $@
80         $(UNLIT) $< $@
81         @chmod 444 $@
82
83
84 # Here's an interesting rule!
85 # The .hi file depends on the .o file,
86 # so if the .hi file is dated earlier than the .o file (commonly the case,
87 # when interfaces are stable) this rule just makes sure that the .o file,
88 # is up to date.  Then it does nothing to generate the .hi file from the 
89 # .o file, because the act of making sure the .o file is up to date also
90 # updates the .hi file (if necessary).
91
92 %.$(way_)hi : %.$(way_)o
93         @if [ ! -f $@ ] ; then \
94             echo Panic! $< exists, but $@ does not.; \
95             exit 1; \
96         else exit 0 ; \
97         fi                                                      
98
99 $(odir_)%.$(way_)hi : %.$(way_)hc
100         @if [ ! -f $@ ] ; then \
101             echo Panic! $< exists, but $@ does not.; \
102             exit 1; \
103         else exit 0 ; \
104         fi
105
106 else # BootingFromHc
107
108 # -----------------------------------------------------------------------------
109 # suffix rules for building a .o from a .hc file in bootstrap mode.
110
111 ifeq "$(BootingFromUnregisterisedHc)" "YES"
112
113 # without mangling
114
115 $(odir_)%.o : %.hc
116         $(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/'`
117
118 else
119
120 # with mangling
121
122 $(odir_)%.raw_s : %.hc
123         $(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/'`
124
125 $(odir_)%.s : %.raw_s
126         $(GHC_MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
127
128 $(odir_)%.o : %.s
129         $(CC) -c -o $@ $<
130
131 endif # not BootingFromUnregisterisedHc
132
133 endif # BootingFromHc
134
135 #-----------------------------------------------------------------------------
136 # Happy Suffix Rules
137 #
138 %.hs : %.ly
139         $(HAPPY) $(HAPPY_OPTS) $<
140
141 %.hs : %.y
142         $(HAPPY) $(HAPPY_OPTS) $<
143
144 #-----------------------------------------------------------------------------
145 # Alex Suffix Rules
146 #
147
148 %.hs : %.x
149         $(ALEX) $(ALEX_OPTS) $<
150
151 #-----------------------------------------------------------------------------
152 # hsc2hs Suffix Rules
153 #
154 ifneq "$(BootingFromHc)" "YES"
155 %_hsc.c %_hsc.h %.hs : %.hsc
156         $(HSC2HS) $(HSC2HS_OPTS) $<
157         @touch $(patsubst %.hsc,%_hsc.c,$<)
158 endif
159
160 #-----------------------------------------------------------------------------
161 # Green-card Suffix Rules
162 #
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 # Runtest rules for calling $(HC) on a single-file Haskell program
231
232 %.runtest : %.hs
233         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
234
235 #-----------------------------------------------------------------------------
236 # DocBook XML suffix rules
237 #
238
239 %.html : %.xml
240         $(XSLTPROC) --output $@ \
241                     --stringparam html.stylesheet $(FPTOOLS_CSS) \
242                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
243                     $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
244         cp $(FPTOOLS_CSS_ABS) .
245
246 %/index.html : %.xml
247         $(RM) -rf $(dir $@)
248         $(XSLTPROC) --stringparam base.dir $(dir $@) \
249                     --stringparam use.id.as.filename 1 \
250                     --stringparam html.stylesheet $(FPTOOLS_CSS) \
251                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
252                     $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
253         cp $(FPTOOLS_CSS_ABS) $(dir $@)
254
255 # Note: Numeric labeling seems to be uncommon for HTML Help
256 %-htmlhelp/index.html : %.xml
257         $(RM) -rf $(dir $@)
258         $(XSLTPROC) --stringparam base.dir $(dir $@) \
259                     --stringparam manifest.in.base.dir 1 \
260                     --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
261                     $(XSLTPROC_OPTS) \
262                     $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
263
264 # TODO: Detect hhc via autoconf
265 #
266 # Two obstables here:
267 #
268 # * The reason for the strange "if" below is that hhc returns 0 on error and 1
269 #   on success, the opposite of what shells and make expect.
270 #
271 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
272 #   anyway, therefore we pacify make by "|| true". Ugly...
273 #
274 %.chm : %-htmlhelp/index.html
275         ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
276
277 %.fo : %.xml
278         $(XSLTPROC) --output $@ \
279                     $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
280                     $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
281
282 ifeq "$(FOP)" ""
283 ifneq "$(PDFXMLTEX)" ""
284 %.pdf : %.fo
285         $(PDFXMLTEX) $<
286         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
287           $(PDFXMLTEX) $< ; \
288           $(PDFXMLTEX) $< ; \
289         fi
290 endif
291 else
292 %.ps : %.fo
293         $(FOP) $(FOP_OPTS) -fo $< -ps $@
294
295 %.pdf : %.fo
296         $(FOP) $(FOP_OPTS) -fo $< -pdf $@
297 endif
298
299 ifneq "$(XMLTEX)" ""
300 %.dvi : %.fo
301         $(XMLTEX) $<
302         if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
303           $(XMLTEX) $< ; \
304           $(XMLTEX) $< ; \
305         fi
306 endif
307
308 #-----------------------------------------------------------------------------
309 # Doc processing suffix rules
310 #
311 # ToDo: make these more robust
312 #
313 %.ps : %.dvi
314         @$(RM) $@
315         $(DVIPS) $< -o $@
316
317 %.tex : %.tib
318         @$(RM) $*.tex $*.verb-t.tex
319         $(TIB) $*.tib
320         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
321         @$(RM) $*.tib-t.tex
322
323 %.ps : %.fig
324         @$(RM) $@
325         fig2dev -L ps $< $@
326
327 %.tex : %.fig
328         @$(RM) $@
329         fig2dev -L latex $< $@
330
331 #-----------------------------------------------------------------------------
332 # Literate suffix rules
333
334 %.prl : %.lprl
335         @$(RM) $@
336         $(UNLIT) $(UNLIT_OPTS) $< $@
337         @chmod 444 $@
338
339 %.c : %.lc
340         @$(RM) $@
341         $(UNLIT) $(UNLIT_OPTS) $< $@
342         @chmod 444 $@
343
344 %.h : %.lh
345         @$(RM) $@
346         $(UNLIT) $(UNLIT_OPTS) $< $@
347         @chmod 444 $@
348
349 #-----------------------------------------------------------------------------
350 # Win32 resource files
351 #
352 # The default is to use the GNU resource compiler.
353 #
354
355 %.$(way_)o : %.$(way_)rc
356         @$(RM) $@
357         windres $< $@
358
359 #-----------------------------------------------------------------------------
360 # Preprocessor suffix rule
361
362 # Note use of -P option to prevent #line pragmas being left in the CPP
363 # output.
364
365 % : %.pp
366         @$(RM) $@
367         $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
368         grep -v '^#pragma GCC' > $@