-ifeq "$(GhcWithTablesNextToCode)" "YES"
-SRC_CC_OPTS += -DTABLES_NEXT_TO_CODE
-SRC_HC_OPTS += -optc-DTABLES_NEXT_TO_CODE
+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)
+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)")
+endif