diff -ur openssl-0.9.8.orig\ms\32all.bat openssl-0.9.8\ms\32all.bat
--- openssl-0.9.8.orig\ms\32all.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\32all.bat	Sun Jun 29 21:21:28 2008
@@ -1,5 +1,46 @@
-set OPTS=no-asm
+@echo off
+setlocal
+set OPTS=nasm
 
+if not ''=='%2' goto usage
+if ''=='%*' goto usage
+if 'masm'=='%1' goto masmerr
+set OPTS=%1
+goto nasmcheck
+
+:masmerr
+echo MASM support is deprecated. Use NASM for assembler builds.
+echo Download from http://sourceforge.net/projects/nasm
+set OPTS=
+goto end
+
+:nasmcheck
+if 'masm'=='%OPTS%' goto masmerr
+if not 'nasm'=='%OPTS%' goto no-asmcheck
+goto task
+
+:no-asmcheck
+if not 'no-asm'=='%OPTS%' goto usage
+goto task
+
+:usage
+echo Usage: ms\32all [nasm/no-asm]
+
+:choice
+choice Assembler build (nasm) 2>nul
+if errorlevel 3 goto setp
+if errorlevel 2 set OPTS=no-asm
+goto task
+
+:setp
+set OPTS=
+set /p OPTS=Enter 'nasm' or 'no-asm': 
+echo.
+if ''=='%OPTS%' goto setp
+set OPTS=%OPTS: =%
+goto nasmcheck
+
+:task
 perl Configure VC-WIN32
 perl util\mkfiles.pl >MINFO
 perl util\mk1mf.pl %OPTS% debug VC-WIN32 >d32.mak
@@ -8,7 +49,10 @@
 perl util\mk1mf.pl %OPTS% dll VC-WIN32 >32dll.mak
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
 
+:make
 nmake -f d32.mak
 @if errorlevel 1 goto end
 nmake -f 32.mak
diff -ur openssl-0.9.8.orig\ms\bcb4.bat openssl-0.9.8\ms\bcb4.bat
--- openssl-0.9.8.orig\ms\bcb4.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\bcb4.bat	Sun Jun 29 18:52:17 2008
@@ -3,4 +3,4 @@
 
 @rem create make file
 perl util\mk1mf.pl no-asm BC-NT > bcb.mak
-
+perl util\mk1mf.pl no-asm debug BC-NT > bcbd.mak
diff -ur openssl-0.9.8.orig\ms\do_masm.bat openssl-0.9.8\ms\do_masm.bat
--- openssl-0.9.8.orig\ms\do_masm.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_masm.bat	Sun Jun 29 21:21:44 2008
@@ -1,7 +1,7 @@
 @echo off
 
 SET ASMOPTS=-DOPENSSL_IA32_SSE2
-echo Generating x86 for MASM assember
+echo Generating x86 for MASM assembler
 
 echo Bignum
 cd crypto\bn\asm
@@ -67,6 +67,9 @@
 perl x86cpuid.pl win32 %ASMOPTS% > cpu_win32.asm
 cd ..
 
+echo MASM support is deprecated. Use NASM for assembler builds.
+echo Download from http://sourceforge.net/projects/nasm
+
 echo on
 
 perl util\mkfiles.pl >MINFO
@@ -75,3 +78,5 @@
 
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\ms\do_ms.bat openssl-0.9.8\ms\do_ms.bat
--- openssl-0.9.8.orig\ms\do_ms.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_ms.bat	Sun Jun 29 21:21:59 2008
@@ -1,9 +1,23 @@
 
 perl util\mkfiles.pl >MINFO
 perl util\mk1mf.pl no-asm VC-WIN32 >ms\nt.mak
+perl util\mk1mf.pl no-asm debug VC-WIN32 >ms\ntd.mak
 perl util\mk1mf.pl dll no-asm VC-WIN32 >ms\ntdll.mak
+perl util\mk1mf.pl dll no-asm debug VC-WIN32 >ms\ntdlld.mak
+
+@echo off
+set OSVERSION 2>nul
+if errorlevel 1 goto defs
+
+@echo on
 perl util\mk1mf.pl no-asm VC-CE >ms\ce.mak
+perl util\mk1mf.pl no-asm debug VC-CE >ms\ced.mak
 perl util\mk1mf.pl dll no-asm VC-CE >ms\cedll.mak
+perl util\mk1mf.pl dll no-asm debug VC-CE >ms\cedlld.mak
 
+:defs
+@echo on
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\ms\do_nasm.bat openssl-0.9.8\ms\do_nasm.bat
--- openssl-0.9.8.orig\ms\do_nasm.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_nasm.bat	Sun Jun 29 21:22:40 2008
@@ -2,7 +2,7 @@
 @echo off
 
 SET ASMOPTS=-DOPENSSL_IA32_SSE2
-echo Generating x86 for NASM assember
+echo Generating x86 for NASM assembler
 
 echo Bignum
 cd crypto\bn\asm
@@ -72,8 +72,13 @@
 
 perl util\mkfiles.pl >MINFO
 perl util\mk1mf.pl nasm VC-WIN32 >ms\nt.mak
+perl util\mk1mf.pl nasm debug VC-WIN32 >ms\ntd.mak
 perl util\mk1mf.pl dll nasm VC-WIN32 >ms\ntdll.mak
+perl util\mk1mf.pl dll nasm debug VC-WIN32 >ms\ntdlld.mak
 perl util\mk1mf.pl nasm BC-NT >ms\bcb.mak
+perl util\mk1mf.pl nasm debug BC-NT >ms\bcbd.mak
 
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\ms\do_nt.bat openssl-0.9.8\ms\do_nt.bat
--- openssl-0.9.8.orig\ms\do_nt.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_nt.bat	Sun Jun 29 21:22:40 2008
@@ -1,7 +1,11 @@
 
 perl util\mkfiles.pl >MINFO
 perl util\mk1mf.pl no-asm VC-NT >ms\nt.mak
+perl util\mk1mf.pl no-asm debug VC-NT >ms\ntd.mak
 perl util\mk1mf.pl dll no-asm VC-NT >ms\ntdll.mak
+perl util\mk1mf.pl dll no-asm debug VC-NT >ms\ntdlld.mak
 
 perl util\mkdef.pl libeay NT > ms\libeay32.def
 perl util\mkdef.pl ssleay NT > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\ms\do_win64a.bat openssl-0.9.8\ms\do_win64a.bat
--- openssl-0.9.8.orig\ms\do_win64a.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_win64a.bat	Sun Jun 29 21:22:40 2008
@@ -3,7 +3,11 @@
 perl ms\uplink.pl win64a > ms\uptable.asm
 ml64 -c -Foms\uptable.obj ms\uptable.asm
 perl util\mk1mf.pl no-asm VC-WIN64A >ms\nt.mak
+perl util\mk1mf.pl no-asm debug VC-WIN64A >ms\ntd.mak
 perl util\mk1mf.pl dll no-asm VC-WIN64A >ms\ntdll.mak
+perl util\mk1mf.pl dll no-asm debug VC-WIN64A >ms\ntdlld.mak
 
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\ms\do_win64i.bat openssl-0.9.8\ms\do_win64i.bat
--- openssl-0.9.8.orig\ms\do_win64i.bat	Sun Jun 29 18:20:30 2008
+++ openssl-0.9.8\ms\do_win64i.bat	Sun Jun 29 21:22:40 2008
@@ -3,7 +3,11 @@
 perl ms\uplink.pl win64i > ms\uptable.asm
 ias -o ms\uptable.obj ms\uptable.asm
 perl util\mk1mf.pl no-asm VC-WIN64I >ms\nt.mak
+perl util\mk1mf.pl no-asm debug VC-WIN64I >ms\ntd.mak
 perl util\mk1mf.pl dll no-asm VC-WIN64I >ms\ntdll.mak
+perl util\mk1mf.pl dll no-asm debug VC-WIN64I >ms\ntdlld.mak
 
 perl util\mkdef.pl 32 libeay > ms\libeay32.def
 perl util\mkdef.pl 32 ssleay > ms\ssleay32.def
+copy ms\libeay32.def ms\libeay32d.def >nul
+copy ms\ssleay32.def ms\ssleay32d.def >nul
diff -ur openssl-0.9.8.orig\util\pl\VC-32.pl openssl-0.9.8\util\pl\VC-32.pl
--- openssl-0.9.8.orig\util\pl\VC-32.pl	Sun Jun 29 18:20:33 2008
+++ openssl-0.9.8\util\pl\VC-32.pl	Sun Jun 29 20:39:32 2008
@@ -6,6 +6,17 @@
 $ssl=	"ssleay32";
 $crypto="libeay32";
 
+if (!$shlib) {
+	$ssl.="st";
+	$crypto.="st";
+}
+
+if ($debug) {
+	$ssl.="d";
+	$crypto.="d";
+	$pdbname=$ssl.".pdb";
+}
+
 $o='\\';
 $cp='$(PERL) util/copy.pl';
 $mkdir='$(PERL) util/mkdir-p.pl';
@@ -28,14 +39,14 @@
     # per 0.9.8 release remaining warnings were explicitly examined and
     # considered safe to ignore.
     # 
-    $base_cflags=' /W3 /Gs0 /GF /Gy /nologo -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DOPENSSL_SYSNAME_WIN32 -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE';
+    $base_cflags=' /W3 /Gs0 /GF /Gy /nologo -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DOPENSSL_THREADS -DDSO_WIN32 -DOPENSSL_SYSNAME_WIN32 -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE';
     $base_cflags.=' -D_CRT_SECURE_NO_DEPRECATE';	# shut up VC8
     $base_cflags.=' -D_CRT_NONSTDC_NO_DEPRECATE';	# shut up VC8
     my $f = $shlib?' /MD':' /MT';
     $lib_cflag='/Zl' if (!$shlib);	# remove /DEFAULTLIBs from static lib
     $opt_cflags=$f.' /Ox';
-    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /subsystem:console /opt:ref";
+    $dbg_cflags=$f.'d /Od /Zi -DDEBUG -D_DEBUG';
+    $lflags="/nologo /subsystem:console";
     }
 elsif ($FLAVOR =~ /CE/)
     {
@@ -88,19 +99,19 @@
     $base_cflags=' /W3 /WX /GF /Gy /nologo -DUNICODE -D_UNICODE -DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -I$(WCECOMPAT)/include -DOPENSSL_SMALL_FOOTPRINT';
     $base_cflags.=" $wcecdefs";
     $opt_cflags=' /MC /O1i';	# optimize for space, but with intrinsics...
-    $dbg_clfags=' /MC /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /opt:ref $wcelflag";
+    $dbg_clfags=' /MC /Od /Zi -DDEBUG -D_DEBUG';
+    $lflags="/nologo $wcelflag";
     }
 else	# Win32
     {
-    $base_cflags=' /W3 /WX /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
+    $base_cflags=' /W3 /WX /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DOPENSSL_THREADS -DDSO_WIN32';
     $base_cflags.=' -D_CRT_SECURE_NO_DEPRECATE';	# shut up VC8
     $base_cflags.=' -D_CRT_NONSTDC_NO_DEPRECATE';	# shut up VC8
     my $f = $shlib?' /MD':' /MT';
     $lib_cflag='/Zl' if (!$shlib);	# remove /DEFAULTLIBs from static lib
     $opt_cflags=$f.' /Ox /O2 /Ob2';
-    $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /subsystem:console /opt:ref";
+    $dbg_cflags=$f.'d /Od /Zi -DDEBUG -D_DEBUG';
+    $lflags="/nologo /subsystem:console";
     }
 $mlflags='';
 
@@ -112,7 +123,6 @@
 	{
 	$cflags=$dbg_cflags.$base_cflags;
 	$lflags.=" /debug";
-	$mlflags.=' /debug';
 	}
 else
 	{
@@ -246,14 +256,14 @@
 	$tmp_def='tmp32dll_$(TARGETCPU)';
 	}
 
-$cflags.=" /Fd$out_def";
+$cflags.=" /Fd$out_def".".dbg/".$pdbname if $debug;
 
 sub do_lib_rule
 	{
 	local($objs,$target,$name,$shlib)=@_;
 	local($ret);
 
-	$taget =~ s/\//$o/g if $o ne '/';
+	$target =~ s/\//$o/g if $o ne '/';
 	if ($name ne "")
 		{
 		$name =~ tr/a-z/A-Z/;
@@ -291,7 +301,10 @@
 			}
 		$ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
 		$ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
-        $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;2\n\n";
+		if ($FLAVOR !~ /CE/)
+			{
+			$ret.="\tIF EXIST \$@.manifest mt -manifest \$@.manifest -outputresource:\$@;2\n\n";
+			}
 		}
 	$ret.="\n";
 	return($ret);
@@ -303,11 +316,14 @@
 	local($ret,$_);
 	
 	$file =~ s/\//$o/g if $o ne '/';
-	$n=&bname($targer);
+	$n=&bname($target);
 	$ret.="$target: $files $dep_libs\n";
 	$ret.="\t\$(LINK) \$(LFLAGS) $efile$target @<<\n";
 	$ret.="  \$(APP_EX_OBJ) $files $libs\n<<\n";
-    $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;1\n\n";
+	if ($FLAVOR !~ /CE/)
+		{
+		$ret.="\tIF EXIST \$@.manifest mt -manifest \$@.manifest -outputresource:\$@;1\n\n";
+		}
 	return($ret);
 	}
 
