[project @ 2003-07-23 15:12:30 by simonmar]
[ghc-hetmet.git] / mk / suffix.mk
index cb68ea1..d16513f 100644 (file)
 
 .SUFFIXES:
 
-# However, if $(way) is set then we have to define $(way_) and $(_way)
-# from it in the obvious fashion.
-# This must be done here (or earlier), but not in target.mk with the other
-# way management, because the pattern rules in this file take a snapshot of
-# the value of $(way_) and $(_way), and it's no good setting them later!
-
-ifneq "$(way)" ""
-  way_ := $(way)_
-  _way := _$(way)
-endif
+# This declaration tells GNU make to delete the target if it has
+# changed and the command which created it exited with a non-zero exit
+# code.
+
+.DELETE_ON_ERROR:
 
 #-----------------------------------------------------------------------------
 # Haskell Suffix Rules
 
-HASKELL_SPLIT_PRE= \
- $(RM) $@ ; if [ ! -d $(basename $@) ]; then mkdir $(basename $@) ; else exit 0; fi; \
- find $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food;
-HASKELL_SPLIT_POST= touch $@
-HASKELL_PRE_COMPILE=$(patsubst %,$(HASKELL_SPLIT_PRE),$(filter -split-objs,$(HC_OPTS)))
-HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(HC_OPTS)))
-
-%.$(way_)o : %.hs
-       $(HASKELL_PRE_COMPILE)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
-       $(HASKELL_POST_COMPILE)
-                        
-%.$(way_)o : %.lhs      
-       $(HASKELL_PRE_COMPILE)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
-       $(HASKELL_POST_COMPILE)
-                        
-%.$(way_)hc : %.lhs     
+# Turn off all the Haskell suffix rules if we're booting from .hc
+# files.  The file bootstrap.mk contains alternative suffix rules in
+# this case.
+ifneq "$(BootingFromHc)" "YES"
+
+# The $(odir) support is for building GHC, where we need to build three
+# different versions from the same sources.  See ghc/compiler/Makefile.
+ifneq "$(odir)" ""
+odir_ = $(odir)/
+else
+odir_ =
+endif
+
+$(odir_)%.$(way_)o : %.hs
+       $(HC_PRE_OPTS)
+       $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
+       $(HC_POST_OPTS)
+
+$(odir_)%.$(way_)o : %.lhs      
+       $(HC_PRE_OPTS)
+       $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
+       $(HC_POST_OPTS)
+
+$(odir_)%.$(way_)hc : %.lhs     
        $(RM) $@
        $(HC) $(HC_OPTS) -C $< -o $@
-                        
-%.$(way_)hc : %.hs      
+
+$(odir_)%.$(way_)hc : %.hs      
        $(RM) $@
        $(HC) $(HC_OPTS) -C $< -o $@
-                        
-%.$(way_)o : %.$(way_)hc 
-       $(HASKELL_PRE_COMPILE)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
-       $(HASKELL_POST_COMPILE)
 
-%.$(way_)hc : %.lhc
+$(odir_)%.$(way_)o : %.$(way_)hc 
+       $(HC_PRE_OPTS)
+       $(HC) $(HC_OPTS) -c $< -o $@
+       $(HC_POST_OPTS)
+
+$(odir_)%.$(way_)o : %.hc 
+       $(HC_PRE_OPTS)
+       $(HC) $(HC_OPTS) -c $< -o $@
+       $(HC_POST_OPTS)
+
+$(odir_)%.$(way_)s : %.$(way_)hc 
+       $(HC_PRE_OPTS)
+       $(HC) $(HC_OPTS) -S $< -o $@
+       $(HC_POST_OPTS)
+
+$(odir_)%.$(way_)hc : %.lhc
        @$(RM) $@
        $(UNLIT) $< $@
        @chmod 444 $@
@@ -76,25 +87,39 @@ HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(H
 
 %.$(way_)hi : %.$(way_)o
        @if [ ! -f $@ ] ; then \
-           echo Panic! $< exists, but $@ does not. \
+           echo Panic! $< exists, but $@ does not.; \
            exit 1; \
        else exit 0 ; \
        fi                                                      
 
-%.$(way_)hi : %.$(way_)hc
+$(odir_)%.$(way_)hi : %.$(way_)hc
        @if [ ! -f $@ ] ; then \
-           echo Panic! $< exists, but $@ does not. \
+           echo Panic! $< exists, but $@ does not.; \
            exit 1; \
        else exit 0 ; \
        fi
 
+endif # BootingViaC
+
 #-----------------------------------------------------------------------------
 # Happy Suffix Rules
 #
-.PRECIOUS: %.hs
+.SECONDARY: %.hs
 
 %.hs : %.ly
-       $(HAPPY) $(HAPPY_OPTS) -g $<
+       $(HAPPY) $(HAPPY_OPTS) $<
+
+%.hs : %.y
+       $(HAPPY) $(HAPPY_OPTS) $<
+
+#-----------------------------------------------------------------------------
+# hsc2hs Suffix Rules
+#
+ifneq "$(BootingFromHc)" "YES"
+%_hsc.c %_hsc.h %.hs : %.hsc
+       $(HSC2HS) $(HSC2HS_OPTS) $<
+       @touch $(patsubst %.hsc,%_hsc.c,$<)
+endif
 
 #-----------------------------------------------------------------------------
 # Lx Suffix Rules
@@ -107,30 +132,71 @@ HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(H
 # Green-card Suffix Rules
 #
 
-%.hs : %.gc
-       $(GREENCARD) $(GREENCARD_OPTS) $<
+.PRECIOUS: %.gc
+
+%.hs %_stub_ffi.c %_stub_ffi.h : %.gc
+       $(GREENCARD) $(GC_OPTS) $<
+
+%.lhs : %.gc
+       $(GREENCARD) $(GC_OPTS) $< -o $@
+
+%.gc : %.pgc
+       $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
 
 #-----------------------------------------------------------------------------
 # C-related suffix rules
 
-%.$(way_)o : %.$(way_)s
+ifeq "$(UseGhcForCc) $(BootingFromHc)" "YES NO"
+
+$(odir_)%.$(way_)o : %.c
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)o : %.$(way_)s
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)o : %.S
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)s : %.c
        @$(RM) $@
-       $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
+       $(HC) $(GHC_CC_OPTS) -S $< -o $@
+
+else
 
-%.$(way_)o : %.c
+$(odir_)%.$(way_)o : %.c
        @$(RM) $@
        $(CC) $(CC_OPTS) -c $< -o $@
 
-#%.$(way_)s : %.c
-#      @$(RM) $@
-#      $(CC) $(CC_OPTS) -S $< -o $@
+$(odir_)%.$(way_)o : %.$(way_)s
+       @$(RM) $@
+       $(AS) $(AS_OPTS) -o $@ $<
+
+$(odir_)%.$(way_)o : %.S
+       @$(RM) $@
+       $(CC) $(CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)s : %.c
+       @$(RM) $@
+       $(CC) $(CC_OPTS) -S $< -o $@
+
+endif
+
+# stubs are automatically generated and compiled by GHC
+%_stub.$(way_)o: %.o
+       @:
+
+# -----------------------------------------------------------------------------
+# Flex/lex
 
 %.c : %.flex
        @$(RM) $@
-       $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
+       $(FLEX) -t $(FLEX_OPTS) $< > $@
 %.c : %.lex
        @$(RM) $@
-       $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
+       $(FLEX) -t $(FLEX_OPTS) $< > $@
 
 #-----------------------------------------------------------------------------
 # Yacc stuff
@@ -147,25 +213,18 @@ HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(H
 #-----------------------------------------------------------------------------
 # Runtest rules for calling $(HC) on a single-file Haskell program
 
-%.hs : %.runtest
-       $(TIME) $(RUNTEST) $(HC) $(RUNTEST_FLAGS) -o2 $*.stderr $<
-
+%.runtest : %.hs
+       $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
 
 #-----------------------------------------------------------------------------
 # Doc processing suffix rules
-
-%.dvi : %.tex
-       @$(RM) $@
-       $(LTX) $<
-
+#
+# ToDo: make these more robust
+#
 %.ps : %.dvi
        @$(RM) $@
        dvips $< -o $@
 
-%.tex : %.verb
-       @$(RM) $*.tex
-       expand $*.verb | $(VERBATIM) > $*.tex
-
 %.tex : %.tib
        @$(RM) $*.tex $*.verb-t.tex
        $(TIB) $*.tib
@@ -181,199 +240,71 @@ HASKELL_POST_COMPILE=$(patsubst %,$(HASKELL_SPLIT_POST),$(filter -split-objs,$(H
        fig2dev -L latex $< $@
 
 #-----------------------------------------------------------------------------
-# Literate suffix rules
-
-# ToDo: somehow macroize this lot. (if only!)
-
-%.itxi : %.lit
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.txt : %.lit
-       @$(RM) $@
-       $(LIT2TEXT) $(LIT2TEXT_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lit
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lit
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
-
+# SGML suffix rules
 #
-# Produce stand-alone TEX documents
-#
-%.tex : %.itex
+%.dvi : %.sgml
        @$(RM) $@
-       $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
+       $(SGML2DVI) $(SGML2DVI_OPTS) $<
 
-%.tex : %.lhs
+%.ps : %.sgml
        @$(RM) $@
-       $(LIT2LATEX) -S $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
+       $(SGML2PS) $(SGML2PS_OPTS) $<
 
-%.texi : %.lhs
+%.html : %.sgml
        @$(RM) $@
-       $(LIT2TEXI) -S $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.html : %.lhs
-       @$(RM) $@ 
-       $(LIT2TEXI) $(LIT2TEXI_OPTS) -o $(patsubst %.html,%.texi,$@) $<
-       $(TEXI2HTML) $(TEXI2HTML_OPTS) $(patsubst %.lhs,%.texi,$<) 
+#      $(PERL) $(COLLATEINDEX) -N -o index.sgml
+#      $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
+#      $(PERL) $(COLLATEINDEX) -N -o index.sgml
+       $(SGML2HTML) $(SGML2HTML_OPTS) $<
+# touch the .html file so that it is seen to be built
        @touch $@
 
-%.info:: %.texi
+%.html : %.tex
        @$(RM) $@
-       $(MAKEINFO) $(MAKEINFO_OPTS) $< && $(POSTMAKEINFO) $@
+       $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
+       $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
+       $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
+# Run HeVeA twice to resolve labels
 
-%.hs : %.lhs
+%.rtf : %.sgml
        @$(RM) $@
-       $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
-       @chmod 444 $@
+       $(SGML2RTF) $(SGML2RTF_OPTS) $<
 
-%.itxi : %.lhs
+%.pdf : %.sgml
        @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
+       $(SGML2PDF) $(SGML2PDF_OPTS) $<
 
-%.ihtml : %.lhs
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lhs
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.tex : %.lhs
-       $(LIT2LATEX) -S -c $(LIT2LATEX_OPTS) -o $@ $<
-       $(HC) $(HC_OPTS) -c $< -o $@
-
-
-%.itxi : %.lhc
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lhc
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lhc
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
+#-----------------------------------------------------------------------------
+# Literate suffix rules
 
-#
-# Temporary, until either unlit is lifted out of ghc/
-# or literate is properly set up locally -- SOF
-#
 %.prl : %.lprl
        @$(RM) $@
        $(UNLIT) $(UNLIT_OPTS) $< $@
        @chmod 444 $@
 
-%.itxi : %.lprl
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lprl
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lprl
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.sh : %.lsh
-       @$(RM) $@
-       $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itxi : %.lsh
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lsh
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lsh
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
-
 %.c : %.lc
        @$(RM) $@
-       $(UNLIT) $< $@
-       @chmod 444 $@
-
-%.itxi : %.lc
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lc
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lc
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
+       $(UNLIT) $(UNLIT_OPTS) $< $@
        @chmod 444 $@
 
 %.h : %.lh
        @$(RM) $@
-       $(UNLIT) $< $@
-       @chmod 444 $@
-
-%.itxi : %.lh
-       @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.ihtml : %.lh
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
-
-%.itex : %.lh
-       @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
+       $(UNLIT) $(UNLIT_OPTS) $< $@
        @chmod 444 $@
 
-%.flex : %.lflex
-       @$(RM) $@
-       $(LIT2PGM) $(LIT2PGM_OPTS) -o $@ $<
-       @chmod 444 $@
+#-----------------------------------------------------------------------------
+# Win32 resource files
+#
+# The default is to use the GNU resource compiler.
+#
 
-%.itxi : %.lflex
+%.$(way_)o : %.$(way_)rc
        @$(RM) $@
-       $(LIT2TEXI) -c $(LIT2TEXI_OPTS) -o $@ $<
-       @chmod 444 $@
+       windres $< $@
 
-%.ihtml : %.lflex
-       @$(RM) $@
-       $(LIT2HTML) -c $(LIT2HTML_OPTS) -o $@ $<
-       @chmod 444 $@
+#-----------------------------------------------------------------------------
+# Preprocessor suffix rule
 
-%.itex : %.lflex
+% : %.pp
        @$(RM) $@
-       $(LIT2LATEX) -c $(LIT2LATEX_OPTS) -o $@ $<
-       @chmod 444 $@
-
+       $(CPP) $(RAWCPP_FLAGS) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@