[project @ 2002-11-13 12:21:08 by simonmar]
[ghc-hetmet.git] / mk / suffix.mk
index 67657c1..96834fc 100644 (file)
 
 .SUFFIXES:
 
+# 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:
+
 # 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
@@ -30,51 +36,53 @@ endif
 #-----------------------------------------------------------------------------
 # Haskell Suffix Rules
 
-HC_SPLIT_PRE= \
- $(RM) $@ ; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
- find $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food ; fi
-HC_SPLIT_POST  = touch $@
-
-HC_PRE__       = $(patsubst %,$(HC_SPLIT_PRE) ; ,$(filter -split-objs,$(HC_OPTS)))
-HC_POST__      = $(patsubst %,$(HC_SPLIT_POST) ; ,$(filter -split-objs,$(HC_OPTS)))
-
-SRC_HC_POST_OPTS += $(HC_POST__)
-SRC_HC_PRE_OPTS  += $(HC_PRE__)
+# 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
 
-%.$(way_)o : %.hs
+$(odir_)%.$(way_)o : %.hs
        $(HC_PRE_OPTS)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
+       $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
        $(HC_POST_OPTS)
-                        
-%.$(way_)o : %.lhs      
+
+$(odir_)%.$(way_)o : %.lhs      
        $(HC_PRE_OPTS)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
+       $(HC) $(HC_OPTS) -c $< -o $@  -ohi $(basename $@).$(way_)hi
        $(HC_POST_OPTS)
-                        
-%.$(way_)hc : %.lhs     
+
+$(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 
+
+$(odir_)%.$(way_)o : %.$(way_)hc 
        $(HC_PRE_OPTS)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
+       $(HC) $(HC_OPTS) -c $< -o $@
        $(HC_POST_OPTS)
 
-%.$(way_)o : %.hc 
+$(odir_)%.$(way_)o : %.hc 
        $(HC_PRE_OPTS)
-       $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
+       $(HC) $(HC_OPTS) -c $< -o $@
        $(HC_POST_OPTS)
 
-%.$(way_)s : %.$(way_)hc 
+$(odir_)%.$(way_)s : %.$(way_)hc 
        $(HC_PRE_OPTS)
-       $(HC) $(HC_OPTS) -S $< -o $@ -osuf $(subst .,,$(suffix $@))
+       $(HC) $(HC_OPTS) -S $< -o $@
        $(HC_POST_OPTS)
 
-%.$(way_)hc : %.lhc
+$(odir_)%.$(way_)hc : %.lhc
        @$(RM) $@
        $(UNLIT) $< $@
        @chmod 444 $@
@@ -90,26 +98,40 @@ SRC_HC_PRE_OPTS  += $(HC_PRE__)
 
 %.$(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) $<
 
+%.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
 #
@@ -121,37 +143,71 @@ SRC_HC_PRE_OPTS  += $(HC_PRE__)
 # Green-card Suffix Rules
 #
 
+.PRECIOUS: %.gc
+
 %.hs : %.gc
-       $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
+       $(GREENCARD) $(GC_OPTS) $< -o $@
 
 %.lhs : %.gc
-       $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
+       $(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)" "YES"
+
+$(odir_)%.$(way_)o : %.$(way_)s
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)o : %.c
        @$(RM) $@
-       $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
 
-%.$(way_)o : %.c
+$(odir_)%.$(way_)o : %.S
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -c $< -o $@
+
+$(odir_)%.$(way_)s : %.c
+       @$(RM) $@
+       $(HC) $(GHC_CC_OPTS) -S $< -o $@
+
+else
+
+$(odir_)%.$(way_)o : %.$(way_)s
+       @$(RM) $@
+       $(AS) $(AS_OPTS) -o $@ $<
+
+$(odir_)%.$(way_)o : %.c
        @$(RM) $@
        $(CC) $(CC_OPTS) -c $< -o $@
 
-%.$(way_)o : %.S
+$(odir_)%.$(way_)o : %.S
        @$(RM) $@
        $(CC) $(CC_OPTS) -c $< -o $@
 
-#%.$(way_)s : %.c
-#      @$(RM) $@
-#      $(CC) $(CC_OPTS) -S $< -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
@@ -197,10 +253,6 @@ SRC_HC_PRE_OPTS  += $(HC_PRE__)
 #-----------------------------------------------------------------------------
 # SGML suffix rules
 #
-%.sgml : %.vsgml
-       @$(RM) $@
-       expand $< | $(SGMLVERB) > $@
-
 %.dvi : %.sgml
        @$(RM) $@
        $(SGML2DVI) $(SGML2DVI_OPTS) $<
@@ -211,16 +263,28 @@ SRC_HC_PRE_OPTS  += $(HC_PRE__)
 
 %.html : %.sgml
        @$(RM) $@
+#      $(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 : %.sgml
+%.html : %.tex
        @$(RM) $@
-       $(SGML2INFO) $(SGML2INFO_OPTS) $<
+       $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
+       $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
+       $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
+# Run HeVeA twice to resolve labels
 
 %.rtf : %.sgml
        @$(RM) $@
        $(SGML2RTF) $(SGML2RTF_OPTS) $<
 
+%.pdf : %.sgml
+       @$(RM) $@
+       $(SGML2PDF) $(SGML2PDF_OPTS) $<
+
 #-----------------------------------------------------------------------------
 # Literate suffix rules
 
@@ -245,6 +309,13 @@ SRC_HC_PRE_OPTS  += $(HC_PRE__)
 # The default is to use the GNU resource compiler.
 #
 
-%.o : %.rc
+%.$(way_)o : %.$(way_)rc
        @$(RM) $@
        windres $< $@
+
+#-----------------------------------------------------------------------------
+# Preprocessor suffix rule
+
+% : %.pp
+       @$(RM) $@
+       $(CPP) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@