+
+# ----------------------------------------------------------------------------
+# On Windows, as the RTS and base libraries have recursive imports,
+# we have to break the loop with "import libraries".
+# These are made from rts/win32/libHS*.def which contain lists of
+# all the symbols in those libraries used by the RTS.
+#
+ifneq "$$(findstring dyn, $1)" ""
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+
+ALL_RTS_DEF_LIBNAMES = base ghc-prim
+ALL_RTS_DEF_LIBS = \
+ rts/dist/build/win32/libHSbase.dll.a \
+ rts/dist/build/win32/libHSghc-prim.dll.a \
+ rts/dist/build/win32/libHSffi.dll.a
+
+# -- import libs for the regular Haskell libraries
+define make-importlib-def # args $1 = lib name
+rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
+ cat rts/win32/libHS$1.def \
+ | sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
+ | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
+ > rts/dist/build/win32/libHS$1.def
+
+rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
+ "$$(DLLTOOL)" -d rts/dist/build/win32/libHS$1.def \
+ -l rts/dist/build/win32/libHS$1.dll.a
+endef
+$(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
+
+
+# -- import libs for libffi
+rts/dist/build/win32/libHSffi.def : rts/win32/libHSffi.def
+ cat rts/win32/libHSffi.def \
+ | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
+ > rts/dist/build/win32/libHSffi.def
+
+rts/dist/build/win32/libHSffi.dll.a : rts/dist/build/win32/libHSffi.def
+ "$(DLLTOOL)" -d rts/dist/build/win32/libHSffi.def \
+ -l rts/dist/build/win32/libHSffi.dll.a
+endif
+endif
+
+