---
 win32/Makefile.msvc | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/win32/Makefile.msvc b/win32/Makefile.msvc
index 23a02d2..b13dd26 100644
--- a/win32/Makefile.msvc
+++ b/win32/Makefile.msvc
@@ -22,7 +22,7 @@ BASEDIR = ..
 XSLT_SRCDIR = $(BASEDIR)\libxslt
 EXSLT_SRCDIR = $(BASEDIR)\libexslt
 UTILS_SRCDIR = $(BASEDIR)\xsltproc
-BINDIR = bin.msvc
+BINDIR = $(OUTDIR)\bin.msvc
 
 # Names of various input and output components.
 XSLT_NAME = xslt
@@ -39,11 +39,11 @@ EXSLT_DEF = $(EXSLT_BASENAME).def
 EXSLT_A = $(EXSLT_BASENAME)_a.lib
 
 # Places where intermediate files produced by the compiler go
-XSLT_INTDIR = int.xslt.msvc
-XSLT_INTDIR_A = int.xslta.msvc
-EXSLT_INTDIR = int.exslt.msvc
-EXSLT_INTDIR_A = int.exslta.msvc
-UTILS_INTDIR = int.utils.msvc
+XSLT_INTDIR = $(OUTDIR)\int.xslt.msvc
+XSLT_INTDIR_A = $(OUTDIR)\int.xslta.msvc
+EXSLT_INTDIR = $(OUTDIR)\int.exslt.msvc
+EXSLT_INTDIR_A = $(OUTDIR)\int.exslta.msvc
+UTILS_INTDIR = $(OUTDIR)\int.utils.msvc
 
 # The preprocessor and its options.
 CPP = cl.exe /EP
@@ -59,7 +59,13 @@ CFLAGS = $(CFLAGS) /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
 LD = link.exe
 LDFLAGS = /nologo
 LDFLAGS = $(LDFLAGS) /LIBPATH:$(BINDIR) /LIBPATH:$(LIBPREFIX)
-LIBS = wsock32.lib
+# The libraries are needed for static builds (the makefile builds all tools and dlls)
+LIBS = wsock32.lib libiconv.lib libcharset.lib
+!if "$(DEBUG)" == "1"
+LIBS = $(LIBS) zlibd.lib
+!else
+LIBS = $(LIBS) zlib.lib
+!endif
 
 # The archiver and its options.
 AR = lib.exe
@@ -71,6 +77,7 @@ CFLAGS = $(CFLAGS) /D "_DEBUG" /Od /Z7
 LDFLAGS = $(LDFLAGS) /DEBUG
 !else
 CFLAGS = $(CFLAGS) /D "NDEBUG" /O2 
+LDFLAGS = $(LDFLAGS) /DEBUG /OPT:REF /OPT:ICF
 !endif
 
 # Libxslt object files.
@@ -309,13 +316,7 @@ $(UTILS_INTDIR) :
 # An implicit rule for xsltproc and friends.
 APPLIBS = $(LIBS)
 !if "$(STATIC)" == "1"
-APPLIBS = $(LIBS) libxml2_a.lib
-!if "$(WITH_ICONV)" == "1"
-APPLIBS = $(APPLIBS) iconv.lib
-!endif
-!if "$(WITH_ZLIB)" == "1"
-APPLIBS = $(APPLIBS) zlib.lib
-!endif
+APPLIBS = $(LIBS) libxml2.lib
 {$(UTILS_SRCDIR)}.c{$(BINDIR)}.exe:
 	$(CC) /D "LIBXML_STATIC" /D "LIBXSLT_STATIC" /D "LIBEXSLT_STATIC" \
 		$(CFLAGS) /Fo$(UTILS_INTDIR)\ /c $< 
--