--- util/pl/VC-32.orig.pl	Thu May 27 08:16:28 2010
+++ util/pl/VC-32.pl	Fri Jul 30 13:18:08 2010
@@ -25,7 +25,14 @@
 $mkdir='$(PERL) util/mkdir-p.pl';
 $rm='del /Q';
 
-$zlib_lib="zlib1.lib";
+if (defined $withargs{"zlib-lib"})
+    {
+    $zlib_lib=$withargs{"zlib-lib"};
+    } 
+else
+    {
+    $zlib_lib = $shlib ? 'zdll.lib' : 'zlib.lib';
+    }
 
 # Santize -L options for ms link
 $l_flags =~ s/-L("\[^"]+")/\/libpath:$1/g;
@@ -46,14 +53,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 /Zi /Yd /nologo -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -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 || $fips ?' /MD':' /MT';
     $lib_cflag='/Zl' if (!$shlib);	# remove /DEFAULTLIBs from static lib
-    $opt_cflags=$f.' /Ox';
+    $opt_cflags=$f.' /Ox /Oy-';
     $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /subsystem:console /opt:ref";
+    $lflags="/nologo /debug /subsystem:console /incremental:no /opt:ref";
     }
 elsif ($FLAVOR =~ /CE/)
     {
@@ -103,22 +110,22 @@
     }
 
     $cc='$(CC)';
-    $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=' /W3 /WX /GF /Gy /Zi /Yd /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...
+    $opt_cflags=' /MC /O1i /Oy-';	# optimize for space, but with intrinsics...
     $dbg_clfags=' /MC /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /opt:ref $wcelflag";
+    $lflags="/nologo /debug /incremental:no /opt:ref $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 /Zi /Yd /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -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 || $fips ?' /MD':' /MT';
     $lib_cflag='/Zl' if (!$shlib);	# remove /DEFAULTLIBs from static lib
-    $opt_cflags=$f.' /Ox /O2 /Ob2';
+    $opt_cflags=$f.' /Ox /O2 /Ob2 /Oy-';
     $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
-    $lflags="/nologo /subsystem:console /opt:ref";
+    $lflags="/nologo /debug /subsystem:console /incremental:no /opt:ref";
     }
 $mlflags='';
 
@@ -128,9 +135,7 @@
 
 if ($debug)
 	{
-	$cflags=$dbg_cflags.$base_cflags.' /Zi';
-	$lflags.=" /debug";
-	$mlflags.=' /debug';
+	$cflags=$dbg_cflags.$base_cflags;
 	}
 else
 	{
@@ -145,13 +150,9 @@
 $rsc="rc";
 $efile="/out:";
 $exep='.exe';
-if ($no_sock)		{ $ex_libs=''; }
-elsif ($FLAVOR =~ /CE/)	{ $ex_libs='winsock.lib'; }
-else			{ $ex_libs='wsock32.lib'; }
 
 my $oflow;
 
-
 if ($FLAVOR =~ /WIN64/ and `cl 2>&1` =~ /14\.00\.4[0-9]{4}\./)
 	{
 	$oflow=' bufferoverflowu.lib';
@@ -163,11 +164,13 @@
 
 if ($FLAVOR =~ /CE/)
 	{
+	$ex_libs.=' winsock.lib' if (!$no_sock);
 	$ex_libs.=' $(WCECOMPAT)/lib/wcecompatex.lib';
 	$ex_libs.=' /nodefaultlib:oldnames.lib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");
 	}
 else
 	{
+	$ex_libs.=' wsock32.lib' if (!$no_sock);
 	$ex_libs.=' gdi32.lib crypt32.lib advapi32.lib user32.lib';
 	$ex_libs.= $oflow;
 
@@ -197,12 +200,10 @@
 	$asm=($ver gt $vew?"nasm":"nasmw")." -f win32";
 	$afile='-o ';
 } elsif ($ml64) {
-	$asm='ml64 /c /Cp /Cx';
-	$asm.=' /Zi' if $debug;
+	$asm='ml64 /c /Cp /Cx /Zi';
 	$afile='/Fo';
 } else {
-	$asm='ml /nologo /Cp /coff /c /Cx';
-	$asm.=" /Zi" if $debug;
+	$asm='ml /nologo /Cp /coff /c /Cx /Zi';
 	$afile='/Fo';
 }
 
@@ -261,7 +262,6 @@
 if ($shlib && $FLAVOR !~ /CE/)
 	{
 	$mlflags.=" $lflags /dll";
-#	$cflags =~ s| /MD| /MT|;
 	$lib_cflag=" -D_WINDLL";
 	$out_def="out32dll";
 	$tmp_def="tmp32dll";
@@ -298,7 +298,7 @@
 	$tmp_def='tmp32dll_$(TARGETCPU)';
 	}
 
-$cflags.=" /Fd$out_def";
+$cflags.=" /Fd$tmp_def/c_src";
 
 sub do_lib_rule
 	{
@@ -325,23 +325,17 @@
 		$name = "/def:ms/${name}.def";
 		}
 
-#	$target="\$(LIB_D)$o$target";
-#	$ret.="$target: $objs\n";
 	if (!$shlib)
 		{
-#		$ret.="\t\$(RM) \$(O_$Name)\n";
-		$ex =' ';
 		$ret.="$target: $objs\n";
-		$ret.="\t\$(MKLIB) $lfile$target @<<\n  $objs $ex\n<<\n";
+		$ret.="\t\$(MKLIB) $lfile$target @<<\n  $objs\n<<\n";
 		}
 	else
 		{
 		my $ex = "";		
-		if ($target =~ /O_SSL/)
-			{
-			$ex .= " \$(L_CRYPTO)";
-			#$ex .= " \$(L_FIPS)" if $fipsdso;
-			}
+		$ex.=" \$(L_CRYPTO)" if $target =~ /O_SSL/;
+		$ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
+
 		my $fipstarget;
 		if ($fipsdso)
 			{
@@ -353,30 +347,8 @@
 			}
 
 
-		if ($name eq "")
-			{
-			$ex.= $oflow;
-			if ($target =~ /capi/)
-				{
-				$ex.=' crypt32.lib advapi32.lib';
-				}
-			}
-		elsif ($FLAVOR =~ /CE/)
-			{
-			$ex.=' winsock.lib $(WCECOMPAT)/lib/wcecompatex.lib';
-			}
-		else
-			{
-			$ex.=' unicows.lib' if ($FLAVOR =~ /NT/);
-			$ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
-			$ex.=' crypt32.lib';
-			$ex.= $oflow;
-			}
-		$ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
-
  		if ($fips && $target =~ /$fipstarget/)
 			{
-			$ex.= $mwex unless $fipscanisterbuild;
 			$ret.="$target: $objs \$(PREMAIN_DSO_EXE)";
 			if ($fipsdso)
 				{
@@ -393,7 +365,7 @@
 			$ret.="\tSET FIPSLIB_D=\$(FIPSLIB_D)\n";
 			$ret.="\t\$(FIPSLINK) \$(MLFLAGS) /map $base_arg $efile$target ";
 			$ret.="$name @<<\n  \$(SHLIB_EX_OBJ) $objs ";
-			$ret.="\$(OBJ_D)${o}fips_premain.obj $ex\n<<\n";
+			$ret.="\$(OBJ_D)${o}fips_premain.obj $ex \$(EX_LIBS)\n<<\n";
 			}
 		else
 			{
@@ -403,7 +375,7 @@
 				$ret .= " \$(O_FIPS)";
 				$ex .= " \$(L_FIPS)";
 				}
-			$ret.="\n\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
+			$ret.="\n\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex \$(EX_LIBS)\n<<\n";
 			}
 
         $ret.="\tIF EXIST \$@.manifest mt -nologo -manifest \$@.manifest -outputresource:\$@;2\n\n";

