[project @ 2001-07-04 16:55:48 by rrt]
[ghc-hetmet.git] / mk / target.mk
index 295ec4c..b67ede9 100644 (file)
@@ -308,6 +308,12 @@ 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
+
 #----------------------------------------
 #      C programs
 
@@ -321,6 +327,20 @@ endif
 
 #----------------------------------------
 #      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)" ""
 
@@ -343,16 +363,29 @@ ifeq "$(LIBOBJS)" ""
   endif
 endif
 
+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)
+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)
@@ -393,7 +426,7 @@ ifeq "$(GhcWithInterpreter)" "YES"
 HC_SPLIT_POST = ld -r -x -o $@ $(basename $@)/*.$(way_)o
 else
 HC_SPLIT_POST = touch $@
-endif
+endif # GhcWithInterpreter == YES
 
 SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE);
 SRC_HC_POST_OPTS += $(HC_SPLIT_POST);
@@ -426,35 +459,57 @@ 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
+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)
 
-ifeq "$(GHCI_LIBOBJS)" ""
-GHCI_LIBOBJS = $(LIBOBJS)
+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
 
-$(GHCI_LIBRARY) :: $(GHCI_LIBOBJS)
-       ld -r -x -o $@ $(GHCI_LIBOBJS) $(STUBOBJS)
+endif # GhcWithInterpreter
+endif # way
+endif # GHCI_LIBRARY
 
-INSTALL_LIBS += $(GHCI_LIBRARY)
-CLEAN_FILES += $(GHCI_LIBRARY)
-endif
-endif
-endif
 
 #----------------------------------------
 #      Building Win32 DLLs