[project @ 2005-02-26 11:03:13 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 # 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 # TODO: Detect hhc via autoconf
281 #
282 # Two obstacles here:
283 #
284 # * The reason for the strange "if" below is that hhc returns 0 on error and 1
285 #   on success, the opposite of what shells and make expect.
286 #
287 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
288 #   anyway, therefore we pacify make by "|| true". Ugly...
289 #
290 %.chm : %-htmlhelp/index.html
291         ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
292
293 %.fo : %.xml
294         $(XSLTPROC) --output $@ \
295                     --stringparam draft.mode no \
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' > $@