1 #################################################################################
5 # Suffix rules for fptools
7 #################################################################################
10 # This file contain the default suffix rules for all the fptools projects.
14 # No need to define .SUFFIXES because we don't use any suffix rules
15 # Instead we use gmake's pattern rules exlusively
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
25 # This line prevents GNU make from deleting any intermediate targets:
29 #-----------------------------------------------------------------------------
30 # Haskell Suffix Rules
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.
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
43 ifneq "$(BootingFromHc)" "YES"
45 $(odir_)%.$(way_)o : %.hs
47 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
50 $(odir_)%.$(way_)o : %.lhs
52 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
55 $(odir_)%.$(way_)hc : %.lhs
57 $(HC) $(HC_OPTS) -C $< -o $@
59 $(odir_)%.$(way_)hc : %.hs
61 $(HC) $(HC_OPTS) -C $< -o $@
63 $(odir_)%.$(way_)o : %.$(way_)hc
65 $(HC) $(HC_OPTS) -c $< -o $@
68 $(odir_)%.$(way_)o : %.hc
70 $(HC) $(HC_OPTS) -c $< -o $@
73 $(odir_)%.$(way_)s : %.$(way_)hc
75 $(HC) $(HC_OPTS) -S $< -o $@
78 $(odir_)%.$(way_)hc : %.lhc
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).
92 %.$(way_)hi : %.$(way_)o
93 @if [ ! -f $@ ] ; then \
94 echo Panic! $< exists, but $@ does not.; \
99 $(odir_)%.$(way_)hi : %.$(way_)hc
100 @if [ ! -f $@ ] ; then \
101 echo Panic! $< exists, but $@ does not.; \
108 # -----------------------------------------------------------------------------
109 # suffix rules for building a .o from a .hc file in bootstrap mode.
111 ifeq "$(BootingFromUnregisterisedHc)" "YES"
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/'`
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/'`
125 $(odir_)%.s : %.raw_s
126 $(GHC_MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
131 endif # not BootingFromUnregisterisedHc
133 endif # BootingFromHc
135 #-----------------------------------------------------------------------------
139 $(HAPPY) $(HAPPY_OPTS) $<
142 $(HAPPY) $(HAPPY_OPTS) $<
144 #-----------------------------------------------------------------------------
149 $(ALEX) $(ALEX_OPTS) $<
151 #-----------------------------------------------------------------------------
152 # hsc2hs Suffix Rules
154 ifneq "$(BootingFromHc)" "YES"
155 %_hsc.c %_hsc.h %.hs : %.hsc
156 $(HSC2HS) $(HSC2HS_OPTS) $<
157 @touch $(patsubst %.hsc,%_hsc.c,$<)
160 #-----------------------------------------------------------------------------
161 # Green-card Suffix Rules
164 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
165 $(GREENCARD) $(GC_OPTS) $<
168 $(GREENCARD) $(GC_OPTS) $< -o $@
171 $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
173 #-----------------------------------------------------------------------------
174 # C-related suffix rules
176 # UseGhcForCc is only relevant when not booting from HC files.
177 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
179 $(odir_)%.$(way_)o : %.c
181 $(HC) $(GHC_CC_OPTS) -c $< -o $@
183 $(odir_)%.$(way_)o : %.$(way_)s
185 $(HC) $(GHC_CC_OPTS) -c $< -o $@
187 $(odir_)%.$(way_)o : %.S
189 $(HC) $(GHC_CC_OPTS) -c $< -o $@
191 $(odir_)%.$(way_)s : %.c
193 $(HC) $(GHC_CC_OPTS) -S $< -o $@
197 $(odir_)%.$(way_)o : %.c
199 $(CC) $(CC_OPTS) -c $< -o $@
201 $(odir_)%.$(way_)o : %.$(way_)s
203 $(AS) $(AS_OPTS) -o $@ $<
205 $(odir_)%.$(way_)o : %.S
207 $(CC) $(CC_OPTS) -c $< -o $@
209 $(odir_)%.$(way_)s : %.c
211 $(CC) $(CC_OPTS) -S $< -o $@
215 # stubs are automatically generated and compiled by GHC
219 # -----------------------------------------------------------------------------
224 $(FLEX) -t $(FLEX_OPTS) $< > $@
227 $(FLEX) -t $(FLEX_OPTS) $< > $@
229 #-----------------------------------------------------------------------------
230 # Runtest rules for calling $(HC) on a single-file Haskell program
233 $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
235 #-----------------------------------------------------------------------------
236 # DocBook XML suffix rules
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) .
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 $@)
255 # Note: Numeric labeling seems to be uncommon for HTML Help
256 %-htmlhelp/index.html : %.xml
258 $(XSLTPROC) --stringparam base.dir $(dir $@) \
259 --stringparam manifest.in.base.dir 1 \
260 --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
262 $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
264 # TODO: Detect hhc via autoconf
266 # Two obstables here:
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.
271 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
272 # anyway, therefore we pacify make by "|| true". Ugly...
274 %.chm : %-htmlhelp/index.html
275 ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
278 $(XSLTPROC) --output $@ \
279 $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
280 $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
283 ifneq "$(PDFXMLTEX)" ""
286 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
293 $(FOP) $(FOP_OPTS) -fo $< -ps $@
296 $(FOP) $(FOP_OPTS) -fo $< -pdf $@
302 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
308 #-----------------------------------------------------------------------------
309 # Doc processing suffix rules
311 # ToDo: make these more robust
318 @$(RM) $*.tex $*.verb-t.tex
320 expand $*.tib-t.tex | $(VERBATIM) > $*.tex
329 fig2dev -L latex $< $@
331 #-----------------------------------------------------------------------------
332 # Literate suffix rules
336 $(UNLIT) $(UNLIT_OPTS) $< $@
341 $(UNLIT) $(UNLIT_OPTS) $< $@
346 $(UNLIT) $(UNLIT_OPTS) $< $@
349 #-----------------------------------------------------------------------------
350 # Win32 resource files
352 # The default is to use the GNU resource compiler.
355 %.$(way_)o : %.$(way_)rc
359 #-----------------------------------------------------------------------------
360 # Preprocessor suffix rule
362 # Note use of -P option to prevent #line pragmas being left in the CPP
367 $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
368 grep -v '^#pragma GCC' > $@