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 #-----------------------------------------------------------------------------
26 # Haskell Suffix Rules
28 # The $(odir) support is for building GHC, where we need to build three
29 # different versions from the same sources. See compiler/Makefile.
36 # Turn off all the Haskell suffix rules if we're booting from .hc
37 # files. The file bootstrap.mk contains alternative suffix rules in
39 ifneq "$(BootingFromHc)" "YES"
41 $(odir_)%.$(way_)o : %.hs
43 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
46 $(odir_)%.$(way_)o : %.lhs
48 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi
51 # Now the rules for hs-boot files.
52 # Note that they do *not* do teh HS_PRE_OPTS / HS_POST_OPTS stuff,
53 # (which concerns splitting) because they don't generate .o files
54 $(odir_)%.$(way_)o-boot : %.hs-boot
55 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
57 $(odir_)%.$(way_)o-boot : %.lhs-boot
58 $(HC) $(HC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
60 $(odir_)%.$(way_)hc : %.lhs
62 $(HC) $(HC_OPTS) -C $< -o $@
64 $(odir_)%.$(way_)hc : %.hs
66 $(HC) $(HC_OPTS) -C $< -o $@
68 $(odir_)%.$(way_)o : %.$(way_)hc
70 $(HC) $(HC_OPTS) -c $< -o $@
73 $(odir_)%.$(way_)o : %.hc
75 $(HC) $(HC_OPTS) -c $< -o $@
78 $(odir_)%.$(way_)s : %.$(way_)hc
80 $(HC) $(HC_OPTS) -S $< -o $@
83 $(odir_)%.$(way_)hc : %.lhc
89 # Here's an interesting rule!
90 # The .hi file depends on the .o file,
91 # so if the .hi file is dated earlier than the .o file (commonly the case,
92 # when interfaces are stable) this rule just makes sure that the .o file,
93 # is up to date. Then it does nothing to generate the .hi file from the
94 # .o file, because the act of making sure the .o file is up to date also
95 # updates the .hi file (if necessary).
97 %.$(way_)hi : %.$(way_)o
98 @if [ ! -f $@ ] ; then \
99 echo Panic! $< exists, but $@ does not.; \
104 %.$(way_)hi-boot : %.$(way_)o-boot
105 @if [ ! -f $@ ] ; then \
106 echo Panic! $< exists, but $@ does not.; \
111 $(odir_)%.$(way_)hi : %.$(way_)hc
112 @if [ ! -f $@ ] ; then \
113 echo Panic! $< exists, but $@ does not.; \
120 # -----------------------------------------------------------------------------
121 # suffix rules for building a .o from a .hc file in bootstrap mode.
123 ifeq "$(BootingFromUnregisterisedHc)" "YES"
128 $(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/'`
134 $(odir_)%.raw_s : %.hc
135 $(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/'`
137 $(odir_)%.s : $(odir_)%.raw_s
138 $(MANGLER) $< $@ $(patsubst -monly-%-regs, %, $(filter -monly-%-regs, $($*_HC_OPTS)))
140 $(odir_)%.o : $(odir_)%.s
143 endif # not BootingFromUnregisterisedHc
145 endif # BootingFromHc
147 #-----------------------------------------------------------------------------
151 $(HAPPY) $(HAPPY_OPTS) $<
154 $(HAPPY) $(HAPPY_OPTS) $<
156 #-----------------------------------------------------------------------------
161 $(ALEX) $(ALEX_OPTS) $<
163 #-----------------------------------------------------------------------------
164 # hsc2hs Suffix Rules
166 ifneq "$(BootingFromHc)" "YES"
167 %_hsc.c %_hsc.h %.hs : %.hsc
168 $(HSC2HS_INPLACE) $(HSC2HS_OPTS) $<
169 @touch $(patsubst %.hsc,%_hsc.c,$<)
172 #-----------------------------------------------------------------------------
173 # Green-card Suffix Rules
176 %.hs %_stub_ffi.c %_stub_ffi.h : %.gc
177 $(GREENCARD) $(GC_OPTS) $<
180 $(GREENCARD) $(GC_OPTS) $< -o $@
183 $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
185 #-----------------------------------------------------------------------------
186 # C-related suffix rules
188 # UseGhcForCc is only relevant when not booting from HC files.
189 ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
191 $(odir_)%.$(way_)o : %.c
193 $(HC) $(GHC_CC_OPTS) -c $< -o $@
195 $(odir_)%.$(way_)o : %.$(way_)s
197 $(HC) $(GHC_CC_OPTS) -c $< -o $@
199 $(odir_)%.$(way_)o : %.S
201 $(HC) $(GHC_CC_OPTS) -c $< -o $@
203 $(odir_)%.$(way_)s : %.c
205 $(HC) $(GHC_CC_OPTS) -S $< -o $@
209 $(odir_)%.$(way_)o : %.c
211 $(CC) $(CC_OPTS) -c $< -o $@
213 $(odir_)%.$(way_)o : %.$(way_)s
215 $(AS) $(AS_OPTS) -o $@ $<
217 $(odir_)%.$(way_)o : %.S
219 $(CC) $(CC_OPTS) -c $< -o $@
221 $(odir_)%.$(way_)s : %.c
223 $(CC) $(CC_OPTS) -S $< -o $@
227 # stubs are automatically generated and compiled by GHC
231 # -----------------------------------------------------------------------------
236 $(FLEX) -t $(FLEX_OPTS) $< > $@
239 $(FLEX) -t $(FLEX_OPTS) $< > $@
241 #-----------------------------------------------------------------------------
242 # Runtest rules for calling $(HC) on a single-file Haskell program
245 $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
247 #-----------------------------------------------------------------------------
248 # DocBook XML suffix rules
252 $(XSLTPROC) --output $@ \
253 --stringparam html.stylesheet $(FPTOOLS_CSS) \
254 $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
255 $(DIR_DOCBOOK_XSL)/html/docbook.xsl $<
256 cp $(FPTOOLS_CSS_ABS) .
260 $(XSLTPROC) --stringparam base.dir $(dir $@) \
261 --stringparam use.id.as.filename 1 \
262 --stringparam html.stylesheet $(FPTOOLS_CSS) \
263 $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
264 $(DIR_DOCBOOK_XSL)/html/chunk.xsl $<
265 cp $(FPTOOLS_CSS_ABS) $(dir $@)
267 # Note: Numeric labeling seems to be uncommon for HTML Help
268 %-htmlhelp/index.html : %.xml
270 $(XSLTPROC) --stringparam base.dir $(dir $@) \
271 --stringparam manifest.in.base.dir 1 \
272 --stringparam htmlhelp.chm "..\\"$(basename $<).chm \
274 $(DIR_DOCBOOK_XSL)/htmlhelp/htmlhelp.xsl $<
276 %-htmlhelp2/collection.HxC : %.xml
278 $(XSLTPROC) --stringparam base.dir $(dir $@) \
279 --stringparam use.id.as.filename 1 \
280 --stringparam manifest.in.base.dir 1 \
282 $(DIR_DOCBOOK_XSL)/htmlhelp2/htmlhelp2.xsl $<
284 # TODO: Detect hhc & Hxcomp via autoconf
286 # Two obstacles here:
288 # * The reason for the strange "if" below is that hhc returns 0 on error and 1
289 # on success, the opposite of what shells and make expect.
291 # * There seems to be some trouble with DocBook indices, but the *.chm looks OK,
292 # anyway, therefore we pacify make by "|| true". Ugly...
294 %.chm : %-htmlhelp/index.html
295 ( cd $(dir $<) && if hhc htmlhelp.hhp ; then false ; else true ; fi ) || true
297 %.HxS : %-htmlhelp2/collection.HxC
298 ( cd $(dir $<) && if Hxcomp -p collection.HxC -o ../$@ ; then false ; else true ; fi )
301 $(XSLTPROC) --output $@ \
302 --stringparam draft.mode no \
303 $(XSLTPROC_LABEL_OPTS) $(XSLTPROC_OPTS) \
304 $(DIR_DOCBOOK_XSL)/fo/docbook.xsl $<
307 ifneq "$(PDFXMLTEX)" ""
310 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
317 $(FOP) $(FOP_OPTS) -fo $< -ps $@
320 $(FOP) $(FOP_OPTS) -fo $< -pdf $@
326 if grep "LaTeX Warning: Label(s) may have changed.Rerun to get cross-references right." $(basename $@).log > /dev/null ; then \
332 #-----------------------------------------------------------------------------
333 # Doc processing suffix rules
335 # ToDo: make these more robust
342 @$(RM) $*.tex $*.verb-t.tex
344 expand $*.tib-t.tex | $(VERBATIM) > $*.tex
353 fig2dev -L latex $< $@
355 #-----------------------------------------------------------------------------
356 # Literate suffix rules
360 $(UNLIT) $(UNLIT_OPTS) $< $@
365 $(UNLIT) $(UNLIT_OPTS) $< $@
370 $(UNLIT) $(UNLIT_OPTS) $< $@
373 #-----------------------------------------------------------------------------
374 # Win32 resource files
376 # The default is to use the GNU resource compiler.
379 %.$(way_)o : %.$(way_)rc
381 windres --preprocessor="$(CPP) -xc -DRC_INVOKED" $< $@
383 #-----------------------------------------------------------------------------
384 # Preprocessor suffix rule
386 # Note use of -P option to prevent #line pragmas being left in the CPP
391 $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | \
392 grep -v '^#pragma GCC' > $@