[project @ 2001-07-04 16:55:48 by rrt]
[ghc-hetmet.git] / mk / target.mk
index 0a64f06..b67ede9 100644 (file)
 
 ifneq "$(SUBDIRS)" ""
 
-all docs runtests boot TAGS clean distclean mostlyclean maintainer-clean install html ps dvi txt::
+# we override the boot & all targets in the top level Makefile
+ifneq "$(NO_ALL_TARGETS)" "YES"
+ALL_TARGET     = all
+BOOT_TARGET    = boot
+INSTALL_TARGET = install
+endif
+
+$(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) html ps dvi txt::
        @echo "------------------------------------------------------------------------"
        @echo "===fptools== Recursively making \`$@' in $(SUBDIRS) ..."
        @echo "PWD = $(shell pwd)"
@@ -286,8 +293,25 @@ boot :: depend
 ifneq "$(HS_PROG)" ""
 all :: $(HS_PROG)
 
+ifneq "$(BootingFromHc)" "YES"
+$(HS_PROG) :: $(HS_OBJS)
+       $(HC) -o $@ $(HC_OPTS) $(LD_OPTS) $(HS_OBJS)
+else
+# see bootstrp.mk
 $(HS_PROG) :: $(HS_OBJS)
-       $(HC) -o $@ $(HC_OPTS) $(LD_OPTS) $(HS_OBJS) $(LIBS)
+       $(CC) -o $@ $(HC_BOOT_CC_OPTS) $(HC_BOOT_LD_OPTS) $(HS_OBJS) $(HC_BOOT_LIBS)
+endif
+endif
+
+# Object and interface files have suffixes tagged with their ways
+ifneq "$(way)" ""
+SRC_HC_OPTS += -hisuf $(way_)hi -hcsuf $(way_)hc -osuf $(way_)o
+endif
+
+# add syslib dependencies and current package name
+SRC_HC_OPTS += $(patsubst %, -package %, $(HSLIB_DEPS))
+ifneq "$(PACKAGE)" ""
+SRC_HC_OPTS += -package-name $(HSLIB)
 endif
 
 #----------------------------------------
@@ -302,29 +326,67 @@ endif
 
 
 #----------------------------------------
-#      Libraries/archives
+#      Building HsLibs libraries.
+#
+# Inputs:
+#   $(HSLIB) is the name of the library to build
+#   $(IS_CBITS_LIB) should be "YES" for a "cbits" library
+#
+# Outputs:
+#   $(LIBRARY)         the name of the library.a
+#   $(GHIC_LIBRARY)    the name of the library.o (for GHCi0
+#   $(LIBOBJS)         objects to put in library
+#   $(STUBOBJS)                more objects to put in library
+# 
+# $(LIBOBJS) is set to $(HS_OBJS) or $(C_OBJS) depending
+# on whether or not it's a "cbits" library.  But you can
+# override this by setting $(LIBOBJS) yourself
+
+ifneq "$(HSLIB)" ""
 
 ifeq "$(IS_CBITS_LIB)" "YES"
 _cbits := _cbits
 endif
 
-ifneq "$(HSLIB)" ""
-LIBRARY = libHS$(HSLIB)$(_cbits)$(_way).a
+LIBRARY      = libHS$(HSLIB)$(_cbits)$(_way).a
+GHCI_LIBRARY = HS$(HSLIB)$(_cbits)$(_way).o
+
+ifneq "$(IS_CBITS_LIB)" "YES"
+WAYS=$(GhcLibWays)
+endif
+
 ifeq "$(LIBOBJS)" ""
-  ifneq "$(IS_CBITS_LIB)" "YES"
-  LIBOBJS = $(HS_OBJS)
-  else
+  ifeq "$(IS_CBITS_LIB)" "YES"
   LIBOBJS = $(C_OBJS)
+  else
+  LIBOBJS = $(HS_OBJS)
   endif
 endif
-ifneq "$(IS_CBITS_LIB)" ""
-CC = $(HC)
+
+STUBOBJS += $(HSC_C_OBJS)
+SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR) -I$(GHC_RUNTIME_DIR)
+
+ifeq "$(IS_CBITS_LIB)" "YES"
 override datadir:=$(libdir)/includes
 INSTALL_DATAS += Hs$(shell perl -e 'print ucfirst "$(HSLIB)"').h
-SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR) -I$(GHC_RUNTIME_DIR)
-endif
+else
+SRC_CC_OPTS += -Icbits
 endif
 
+endif # HSLIB
+
+#----------------------------------------
+#      Libraries/archives
+#
+# Build $(LIBRARY) from $(LIBOJBS)+$(STUBOBJS)
+#
+# Inputs:
+#   $(LIBOBJS)
+#   $(STUBOBJS)
+#
+# Outputs:
+#   Rule to build $(LIBRARY)
+
 ifneq "$(LIBRARY)" ""
 all :: $(LIBRARY)
 
@@ -351,19 +413,23 @@ SRC_HC_OPTS += -split-objs
 
 define BUILD_LIB
 $(RM) $@
-( echo $(STUBOBJS) ; $(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o' -print ) | xargs ar q $@
+(echo $(STUBOBJS); $(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o') | xargs ar q $@
 $(RANLIB) $@
 endef
 
 # Extra stuff for compiling Haskell files with $(SplitObjs):
 
-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_SPLIT_PRE = \
+    $(RM) $@; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
+    $(FIND) $(basename $@) -name '*.$(way_)o' | xargs $(RM) __rm_food; fi
+ifeq "$(GhcWithInterpreter)" "YES"
+HC_SPLIT_POST = ld -r -x -o $@ $(basename $@)/*.$(way_)o
+else
+HC_SPLIT_POST = touch $@
+endif # GhcWithInterpreter == YES
 
-SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE) ;
-SRC_HC_POST_OPTS += $(HC_SPLIT_POST) ;
+SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE);
+SRC_HC_POST_OPTS += $(HC_SPLIT_POST);
 
 #
 # If (Haskell) object files are split, cleaning up 
@@ -393,13 +459,58 @@ SRC_HC_POST_OPTS += \
 else
 SRC_HC_POST_OPTS += \
   ld -r -x -o $@.tmp $@; $(MV) $@.tmp $@
-endif
-endif
+endif # SplitObjs
+endif # StripLibraries
 
 $(LIBRARY) :: $(STUBOBJS) $(LIBOBJS)
        $(BUILD_LIB)
+endif # LIBRARY = ""
+
+#--------------------------------------------------------------
+#      Build dynamically-linkable libraries for GHCi
+#
+# Build $(GHCI_LIBRARY) from $(LIBOBJS)+$(STUBOBJS)
+#
+# Why?  GHCi can only link .o files (at the moment), not .a files
+# so we have to build libFoo.o as well as libFoo.a
+#
+# Furthermore, GHCi currently never loads 
+# profiling libraries (or other non-std ways)
+#
+# Inputs:
+#   $(GHCI_LIBRARY)
+#
+# Outputs:
+#   Rule to build $(GHCI_LIBRARY)
+
+
+ifneq "$(GHCI_LIBRARY)" ""
+ifeq "$(way)" ""
+ifeq "$(GhcWithInterpreter)" "YES"
+
+
+INSTALL_LIBS += $(GHCI_LIBRARY)
+CLEAN_FILES += $(GHCI_LIBRARY)
+
+all :: $(GHCI_LIBRARY)
+
+ifneq "$(GHCI_LIBRARY)" "HSstd.o"
+# An annoying gotcha is that the Prelude is a bit special,
+# for reasons described in ghc/lib/std/Makefile.
+# So we only put in this standard rule for packages other than std
+# The rule for the Prelude is in ghc/lib/std/Makefile
+# We check for GHCI_LIBRARY being HSstd.o rather than
+# HSLIB being std, because we want to still use the boilerplate rule 
+# for cbits.
+$(GHCI_LIBRARY) :: $(LIBOBJS)
+       ld -r -x -o $@ $(LIBOBJS) $(STUBOBJS)
 endif
 
+endif # GhcWithInterpreter
+endif # way
+endif # GHCI_LIBRARY
+
+
 #----------------------------------------
 #      Building Win32 DLLs
 #
@@ -572,12 +683,6 @@ endif
 
 all :: $(SCRIPT_PROG)
 
-#
-# #! support under cygwin32 is not quite there yet, 
-# so we rely on the eval `trick' instead. On all other
-# platforms, we prepend #!$(INTERP)  -- SOF 6/97
-# 
-
 $(SCRIPT_PROG) : $(SCRIPT_OBJS)
        $(RM) $@
        @echo Creating $@...
@@ -593,37 +698,77 @@ endif
 ifneq "$(SCRIPT_PREFIX_FILES)" ""
        @cat $(SCRIPT_PREFIX_FILES) >> $@
 endif
+ifneq "$(SCRIPT_SUBST)" ""
        @eval $(SCRIPT_SUBST) 
+endif
        @cat $(SCRIPT_OBJS) >> $@
        @chmod a+x $@
        @echo Done.
 endif
 
-# links to script programs: we sometimes install a script as
-# <name>-<version> with a link from <name> to the real script.
+# ---------------------------------------------------------------------------
+# Symbolic links
+
+# links to programs: we sometimes install a program as
+# <name>-<version> with a link from <name> to the real program.
+
+ifneq "$(LINK)" ""
+
+all :: $(LINK)
+
+CLEAN_FILES += $(LINK)
 
-ifneq "$(SCRIPT_LINK)" ""
-all :: $(SCRIPT_LINK)
+ifeq "$(LINK_TARGET)" ""
+ifneq "$(SCRIPT_PROG)" ""
+LINK_TARGET = $(SCRIPT_PROG)
+else
+ifneq "$(HS_PROG)" ""
+LINK_TARGET = $(HS_PROG)
+else
+ifneq "$(C_PROG)" ""
+LINK_TARGET = $(C_PROG)
+else
+LINK_TARGET = dunno
+endif
+endif
+endif
+endif
 
 #
-# Don't want to overwrite $(SCRIPT_LINK)s that aren't symbolic
+# Don't want to overwrite $(LINK)s that aren't symbolic
 # links. Testing for symbolic links is problematic to do in
 # a portable fashion using a /bin/sh test, so we simply rely
 # on perl.
 #
-$(SCRIPT_LINK) : $(SCRIPT_PROG)
-       @if ( $(PERL) -e '$$fn="$(SCRIPT_LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
-          echo "Creating a symbolic link from $(SCRIPT_PROG) to $(SCRIPT_LINK)"; \
-          $(RM) $(SCRIPT_LINK); \
-          $(LN_S) $(SCRIPT_PROG) $(SCRIPT_LINK); \
+$(LINK) : $(LINK_TARGET)
+       @if ( $(PERL) -e '$$fn="$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
+          echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK)"; \
+          $(RM) $(LINK); \
+          $(LN_S) $(LINK_TARGET) $(LINK); \
         else \
-          echo "Creating a symbolic link from $(SCRIPT_PROG) to $(SCRIPT_LINK) failed: \`$(SCRIPT_LINK)' already exists"; \
-          echo "Perhaps remove \`$(SCRIPT_LINK)' manually?"; \
+          echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) failed: \`$(LINK)' already exists"; \
+          echo "Perhaps remove \`$(LINK)' manually?"; \
           exit 1; \
         fi;
-endif
 
 
+#
+# install links to script drivers.
+#
+install ::
+       @$(INSTALL_DIR) $(bindir)
+       @if ( $(PERL) -e '$$fn="$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
+          echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir)"; \
+          $(RM) $(bindir)/$(LINK); \
+          $(LN_S) $(LINK_TARGET) $(bindir)/$(LINK); \
+        else \
+          echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir) failed: \`$(bindir)/$(LINK)' already exists"; \
+          echo "Perhaps remove \`$(bindir)/$(LINK)' manually?"; \
+          exit 1; \
+        fi;
+
+endif # LINK 
+
 
 ###########################################
 #
@@ -676,11 +821,8 @@ ifneq "$(LIBRARY)" ""
 INSTALL_LIBS  += $(LIBRARY)
 ifeq "$(DLLized)" "YES"
 INSTALL_PROGS += $(DLL_NAME)
-else
-ifeq "$(DLLized)" "YES"
 INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
 endif
-endif
 INSTALL_DATAS += $(HS_IFACES)
 endif
 
@@ -822,23 +964,6 @@ install-strip::
        @$(MAKE) EXTRA_INSTALL_OPTS='-s' install                                        
 endif
 
-#
-# install links to script drivers.
-#
-ifneq "$(SCRIPT_LINK)" ""
-install ::
-       @if ( $(PERL) -e '$$fn="$(bindir)/$(SCRIPT_LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
-          echo "Creating a symbol link from $(SCRIPT_PROG) to $(SCRIPT_LINK) in $(bindir)"; \
-          $(RM) $(bindir)/$(SCRIPT_LINK); \
-          $(LN_S) $(SCRIPT_PROG) $(bindir)/$(SCRIPT_LINK); \
-        else \
-          echo "Creating a symbol link from $(SCRIPT_PROG) to $(SCRIPT_LINK) in $(bindir) failed: \`$(bindir)/$(SCRIPT_LINK)' already exists"; \
-          echo "Perhaps remove \`$(bindir)/$(SCRIPT_LINK)' manually?"; \
-          exit 1; \
-        fi;
-
-endif
-
 ###########################################
 #
 #      Targets: check tags show
@@ -893,17 +1018,9 @@ ifneq "$(SGML_DOC)" ""
 # multi-file SGML document: main document name is specified in $(SGML_DOC),
 # sub-documents (.sgml files) listed in $(SGML_SRCS).
 
-ifeq "$(VSGML_SRCS)" ""
-VSGML_SRCS = $(wildcard *.vsgml)
-endif
-
 ifeq "$(SGML_SRCS)" ""
-ifneq "$(VSGML_SRCS)" ""
-SGML_SRCS = $(patsubst %.vsgml, %.sgml, $(VSGML_SRCS))
-else
 SGML_SRCS = $(wildcard *.sgml)
 endif
-endif
 
 SGML_TEX  = $(addsuffix .tex,$(SGML_DOC))
 SGML_DVI  = $(addsuffix .dvi,$(SGML_DOC))
@@ -914,7 +1031,7 @@ SGML_HTML = $(addsuffix .html,$(SGML_DOC))
 # HTML output goes in a subdirectory on its own.
 SGML_TEXT = $(addsuffix .txt,$(SGML_DOC))
 
-$(SGML_DVI) $(SGML_PS) $(SGML_HTML) $(SGML_TEXT) :: $(SGML_SRCS)
+$(SGML_DVI) $(SGML_PS) $(SGML_HTML) $(SGML_TEXT) $(SGML_PDF) :: $(SGML_SRCS)
 
 dvi  :: $(SGML_DVI)
 ps   :: $(SGML_PS)
@@ -925,7 +1042,6 @@ txt  :: $(SGML_TEXT)
 
 CLEAN_FILES += $(SGML_TEXT) $(SGML_TEX) $(SGML_PS) $(SGML_DVI) $(SGML_PDF) $(SGML_RTF) $(SGML_HTML) $(SGML_DOC)-*.html
 # can't use $(SGML_SRCS) here, it was maybe used elsewhere
-MOSTLY_CLEAN_FILES += $(patsubst %.vsgml, %.sgml, $(VSGML_SRCS))
 
 extraclean ::
        $(RM) -rf DBTOHTML_OUTPUT_*