Optionally use libffi to implement 'foreign import "wrapper"' (#793)
[ghc-hetmet.git] / rts / Makefile
index 2bc31b3..74a37fd 100644 (file)
@@ -25,6 +25,14 @@ PACKAGE = rts
 
 HC=$(GHC_INPLACE)
 
+
+# Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
+# rather than just libHSrts.a when we are making and installing
+# bindists.
+ifeq "$(DOING_BIN_DIST)" "YES"
+_way = *
+endif
+
 # -----------------------------------------------------------------------------
 # RTS ways
 
@@ -35,6 +43,15 @@ GhcRtsHcOpts=
 GhcRtsCcOpts=-g -O0
 endif
 
+ifeq "$(BeConservative)" "YES"
+GhcRtsCcOpts += -DBE_CONSERVATIVE
+endif
+
+# -----------------------------------------------------------------------------
+
+# There's nothing for Haddock here...
+override HADDOCK_DOCS = NO
+
 # -----------------------------------------------------------------------------
 
 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
@@ -124,38 +141,72 @@ SRC_CC_OPTS += $(WARNING_OPTS)
 SRC_CC_OPTS += $(STANDARD_OPTS)
 
 SRC_CC_OPTS += $(GhcRtsCcOpts)
-SRC_HC_OPTS += $(GhcRtsHcOpts) -package-name rts
+SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
 
 ifneq "$(GhcWithSMP)" "YES"
 SRC_CC_OPTS += -DNOSMP
 SRC_HC_OPTS += -optc-DNOSMP
 endif
 
+ifeq "$(UseLibFFI)" "YES"
+SRC_CC_OPTS += -DUSE_LIBFFI
+PACKAGE_CPP_OPTS += -DUSE_LIBFFI
+endif
+
 ifneq "$(DYNAMIC_RTS)" "YES"
 SRC_HC_OPTS += -static
 else
 LIB_LD_OPTS += -ignore-package base -ignore-package rts
 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
-BASE_VERSION=$(strip $(shell grep version: $(TOP)/libraries/base/base.cabal | cut -f2 -d:))
-BASE_NAME=HSbase-$(BASE_VERSION)-ghc$(ProjectVersion)$(soext)
+LIB_DEPS=buildbase
+.PHONY: buildbase
+
 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
-BASE_IMPORT_LIBRARY=$(BASE_DIST_LIB)/lib$(BASE_NAME).a
-LIB_DEPS=$(BASE_IMPORT_LIBRARY)
-LIB_LD_OPTS += -L$(BASE_DIST_LIB) -l$(BASE_NAME)
-# We extract a good bit of information out of the rts package.conf by going via ghc-pkg
-LIB_LD_OPTS += $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)")
-LIB_LD_OPTS += $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
+
+# The following must be a one liner otherwise its evaluation won't be delayed until base/rts packages are properly registered
+LIB_LD_OPTS = -L$(shell $(GHC_PKG_INPLACE) field base library-dirs | sed -e 's/library-dirs: //') -l$(shell $(GHC_PKG_INPLACE) field base hs-libraries | sed -e 's/hs-libraries: //')-ghc$(ProjectVersion)$(soext) $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)") $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
 endif
 endif
 
-RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
-RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
-RtsUtils_CC_OPTS += -DRtsWay=\"rts$(_way)\"
-RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
-RtsUtils_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
-RtsUtils_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
-RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
-RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
+ifeq "$(Windows)" "YES"
+# On Windows GHC does its own commandline parsing, so we need extra
+# doublequote protection. Sigh.
+DQ = \\\"
+else
+DQ = \"
+endif
+
+# If Main.c is built with optimisation then the SEH exception stuff on
+# Windows gets confused.
+# This has to be in HC rather than CC opts, as otherwise there's a
+# -optc-O2 that comes after it.
+Main_HC_OPTS += -optc-O0
+
+RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
+RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
+RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
+RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
+RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
+RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
+
+StgCRun_CC_OPTS += -w
+Typeable_CC_OPTS += -w
+RetainerProfile_CC_OPTS += -w
+sm/Compact_CC_OPTS += -w
+# On Windows:
+win32/ConsoleHandler_CC_OPTS += -w
+win32/ThrIOManager_CC_OPTS += -w
+win32/Ticker_CC_OPTS += -w
+Threads_CC_OPTS += -w
+Capability_CC_OPTS += -w
+Schedule_CC_OPTS += -w
+# The above warning supression flags are a temporary kludge.
+# While working on this module you are encouraged to remove it and fix
+# any warnings in the module. See
+#     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
+# for details
 
 ifeq "$(way)" "mp"
 SRC_HC_OPTS += -I$$PVM_ROOT/include
@@ -360,10 +411,11 @@ endif
 include $(TOP)/mk/target.mk
 
 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
-$(BASE_IMPORT_LIBRARY): $(LIBRARY).a
-       $(MAKE) -C ../libraries/ make.library.base
-# just for the timestamps
-       touch $(BASE_IMPORT_LIBRARY)
+# $(LIBRARY).a is not the static library libHSrts.a but
+# libHSrts.dll.a, the import library for dynamic linking required for
+# linking the dynamic version of base
+buildbase: $(LIBRARY).a
+       $(MAKE) way="" -C ../libraries/ make.library.base
 endif
 
 #-----------------------------------------------------------------------------