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 # 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
61 $(odir_)%.$(way_)o-boot : %.lhs-boot
62 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
64 $(odir_)%.$(way_)hc : %.lhs
66 $(HC) $(HC_OPTS) -C $< -o $@
68 $(odir_)%.$(way_)hc : %.hs
70 $(HC) $(HC_OPTS) -C $< -o $@
72 $(odir_)%.$(way_)o : %.$(way_)hc
74 $(HC) $(HC_OPTS) -c $< -o $@
77 $(odir_)%.$(way_)o : %.hc
79 $(HC) $(HC_OPTS) -c $< -o $@
82 $(odir_)%.$(way_)s : %.$(way_)hc
84 $(HC) $(HC_OPTS) -S $< -o $@
87 $(odir_)%.$(way_)hc : %.lhc
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).
101 %.$(way_)hi : %.$(way_)o
102 @if [ ! -f $@ ] ; then \
103 echo Panic! $< exists, but $@ does not.; \
108 %.$(way_)hi-boot : %.$(way_)o-boot
109 @if [ ! -f $@ ] ; then \
110 echo Panic! $< exists, but $@ does not.; \
115 $(odir_)%.$(way_)hi : %.$(way_)hc
116 @if [ ! -f $@ ] ; then \
117 echo Panic! $< exists, but $@ does not.; \
124 # -----------------------------------------------------------------------------
125 # suffix rules for building a .o from a .hc file in bootstrap mode.
127 ifeq "$(BootingFromUnregisterisedHc)" "YES"
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/'`
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/'`
141 $(odir_)%.s : %.raw_s
142 $(GHC_MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
147 endif # not BootingFromUnregisterisedHc
149 endif # BootingFromHc
151 #-----------------------------------------------------------------------------
155 $(HAPPY) $(HAPPY_OPTS) $<
158 $(HAPPY) $(HAPPY_OPTS) $<
160 #-----------------------------------------------------------------------------
165 $(ALEX) $(ALEX_OPTS) $<
167 #-----------------------------------------------------------------------------
168 # hsc2hs Suffix Rules
170 ifneq "$(BootingFromHc)" "YES"
171 %_hsc.c %_hsc.h %.hs : %.hsc
172 $(HSC2HS) $(HSC2HS_OPTS) $<
173 @touch $(patsubst %.hsc,%_hsc.c,$<)
176 #-----------------------------------------------------------------------------
177 # Green-card Suffix Rules
180 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
181 $(GREENCARD) $(GC_OPTS) $<
184 $(GREENCARD) $(GC_OPTS) $< -o $@
187 $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
189 #-----------------------------------------------------------------------------
190 # C-related suffix rules
192 # UseGhcForCc is only relevant when not booting from HC files.
193 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
195 $(odir_)%.$(way_)o : %.c
197 $(HC) $(GHC_CC_OPTS) -c $< -o $@
199 $(odir_)%.$(way_)o : %.$(way_)s
201 $(HC) $(GHC_CC_OPTS) -c $< -o $@
203 $(odir_)%.$(way_)o : %.S
205 $(HC) $(GHC_CC_OPTS) -c $< -o $@
207 $(odir_)%.$(way_)s : %.c
209 $(HC) $(GHC_CC_OPTS) -S $< -o $@
213 $(odir_)%.$(way_)o : %.c
215 $(CC) $(CC_OPTS) -c $< -o $@
217 $(odir_)%.$(way_)o : %.$(way_)s
219 $(AS) $(AS_OPTS) -o $@ $<
221 $(odir_)%.$(way_)o : %.S
223 $(CC) $(CC_OPTS) -c $< -o $@
225 $(odir_)%.$(way_)s : %.c
227 $(CC) $(CC_OPTS) -S $< -o $@
231 # stubs are automatically generated and compiled by GHC
235 # -----------------------------------------------------------------------------
240 $(FLEX) -t $(FLEX_OPTS) $< > $@
243 $(FLEX) -t $(FLEX_OPTS) $< > $@
245 #-----------------------------------------------------------------------------
246 # Runtest rules for calling $(HC) on a single-file Haskell program
249 $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
251 #-----------------------------------------------------------------------------
252 # DocBook XML suffix rules
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) .
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 $@)
271 # Note: Numeric labeling seems to be uncommon for HTML Help
272 %-htmlhelp/index.html : %.xml
274 $(XSLTPROC) --stringparam base.dir $(dir $@) \
275 --stringparam manifest.in.base.dir 1 \
276 --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
278 $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
280 %-htmlhelp2/collection.HxC : %.xml
282 $(XSLTPROC) --stringparam base.dir $(dir $@) \
283 --stringparam use.id.as.filename 1 \
284 --stringparam manifest.in.base.dir 1 \
286 $(DIR_DOCBOOK_XSL)/htmlhelp2/htmlhelp2.xsl $<
288 # TODO: Detect hhc & Hxcomp via autoconf
290 # Two obstacles here:
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.
295 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
296 # anyway, therefore we pacify make by "|| true". Ugly...
298 %.chm : %-htmlhelp/index.html
299 ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
301 %.HxS : %-htmlhelp2/collection.HxC
302 ( cd $(dir $<) && if Hxcomp -p collection.HxC -o ../$@ ; then false ; else true ; fi )
305 $(XSLTPROC) --output $@ \
306 --stringparam draft.mode no \
307 $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
308 $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
311 ifneq "$(PDFXMLTEX)" ""
314 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
321 $(FOP) $(FOP_OPTS) -fo $< -ps $@
324 $(FOP) $(FOP_OPTS) -fo $< -pdf $@
330 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
336 #-----------------------------------------------------------------------------
337 # Doc processing suffix rules
339 # ToDo: make these more robust
346 @$(RM) $*.tex $*.verb-t.tex
348 expand $*.tib-t.tex | $(VERBATIM) > $*.tex
357 fig2dev -L latex $< $@
359 #-----------------------------------------------------------------------------
360 # Literate suffix rules
364 $(UNLIT) $(UNLIT_OPTS) $< $@
369 $(UNLIT) $(UNLIT_OPTS) $< $@
374 $(UNLIT) $(UNLIT_OPTS) $< $@
377 #-----------------------------------------------------------------------------
378 # Win32 resource files
380 # The default is to use the GNU resource compiler.
383 %.$(way_)o : %.$(way_)rc
387 #-----------------------------------------------------------------------------
388 # Preprocessor suffix rule
390 # Note use of -P option to prevent #line pragmas being left in the CPP
395 $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
396 grep -v '^#pragma GCC' > $@