diff -Naur openssl-1.0.1t.orig/crypto/Makefile openssl-1.0.1t.patched/crypto/Makefile
--- openssl-1.0.1t.orig/crypto/Makefile	2016-05-03 16:49:36.000000000 +0300
+++ openssl-1.0.1t.patched/crypto/Makefile	2016-05-08 00:53:02.241275100 +0300
@@ -10,7 +10,7 @@
 INCLUDES=	-I.. -I../.. -I../modes -I../asn1 -I../evp -I../../include $(ZLIB_INCLUDE)
 CFLAG=		-g
 MAKEDEPPROG=	makedepend
-MAKEDEPEND=	$(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+MAKEDEPEND=	$(TOP)/util/domd $(TOP) $(LCONFIG) $(MAKEDEPPROG)
 MAKEFILE=       Makefile
 RM=             rm -f
 AR=		ar r
diff -Naur openssl-1.0.1t.orig/crypto/srp/Makefile openssl-1.0.1t.patched/crypto/srp/Makefile
--- openssl-1.0.1t.orig/crypto/srp/Makefile	2016-05-03 16:49:48.000000000 +0300
+++ openssl-1.0.1t.patched/crypto/srp/Makefile	2016-05-08 00:53:02.243275200 +0300
@@ -8,7 +8,7 @@
 INSTALLTOP=/usr/local/ssl
 MAKE=		make -f Makefile.ssl
 MAKEDEPPROG=	makedepend
-MAKEDEPEND=	$(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+MAKEDEPEND=	$(TOP)/util/domd $(TOP) $(LCONFIG) $(MAKEDEPPROG)
 MAKEFILE=	Makefile.ssl
 AR=		ar r
 
diff -Naur openssl-1.0.1t.orig/crypto/ts/Makefile openssl-1.0.1t.patched/crypto/ts/Makefile
--- openssl-1.0.1t.orig/crypto/ts/Makefile	2016-05-03 16:49:48.000000000 +0300
+++ openssl-1.0.1t.patched/crypto/ts/Makefile	2016-05-08 00:53:02.245275300 +0300
@@ -11,7 +11,7 @@
 OPENSSLDIR=     /usr/local/ssl
 INSTALLTOP=/usr/local/ssl
 MAKEDEPPROG=	makedepend
-MAKEDEPEND=	$(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+MAKEDEPEND=	$(TOP)/util/domd $(TOP) $(LCONFIG) $(MAKEDEPPROG)
 MAKEFILE=	Makefile
 AR=		ar r
 
diff -Naur openssl-1.0.1t.orig/Makefile openssl-1.0.1t.patched/Makefile
--- openssl-1.0.1t.orig/Makefile	2016-05-03 16:49:53.000000000 +0300
+++ openssl-1.0.1t.patched/Makefile	2016-05-08 00:53:02.251275700 +0300
@@ -212,8 +212,8 @@
 		SDIRS='$(SDIRS)' LIBRPATH='$(INSTALLTOP)/$(LIBDIR)'	\
 		INSTALL_PREFIX='$(INSTALL_PREFIX)'		\
 		INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)'	\
-		LIBDIR='$(LIBDIR)'				\
-		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD $(MAKEDEPPROG)' \
+		LIBDIR='$(LIBDIR) -llegacy_stdio_definitions'				\
+		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} $(LCONFIG) $(MAKEDEPPROG)' \
 		DEPFLAG='-DOPENSSL_NO_DEPRECATED $(DEPFLAG)'	\
 		MAKEDEPPROG='$(MAKEDEPPROG)'			\
 		SHARED_LDFLAGS='$(SHARED_LDFLAGS)'		\
diff -Naur openssl-1.0.1t.orig/Makefile.bak openssl-1.0.1t.patched/Makefile.bak
--- openssl-1.0.1t.orig/Makefile.bak	2016-05-03 16:49:52.000000000 +0300
+++ openssl-1.0.1t.patched/Makefile.bak	2016-05-08 00:53:02.255275900 +0300
@@ -213,7 +213,7 @@
 		INSTALL_PREFIX='$(INSTALL_PREFIX)'		\
 		INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)'	\
 		LIBDIR='$(LIBDIR)'				\
-		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD $(MAKEDEPPROG)' \
+		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} $(LCONFIG) $(MAKEDEPPROG)' \
 		DEPFLAG='-DOPENSSL_NO_DEPRECATED $(DEPFLAG)'	\
 		MAKEDEPPROG='$(MAKEDEPPROG)'			\
 		SHARED_LDFLAGS='$(SHARED_LDFLAGS)'		\
diff -Naur openssl-1.0.1t.orig/Makefile.org openssl-1.0.1t.patched/Makefile.org
--- openssl-1.0.1t.orig/Makefile.org	2016-05-03 16:49:00.000000000 +0300
+++ openssl-1.0.1t.patched/Makefile.org	2016-05-08 00:53:02.256276000 +0300
@@ -211,7 +211,7 @@
 		INSTALL_PREFIX='$(INSTALL_PREFIX)'		\
 		INSTALLTOP='$(INSTALLTOP)' OPENSSLDIR='$(OPENSSLDIR)'	\
 		LIBDIR='$(LIBDIR)'				\
-		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} -MD $(MAKEDEPPROG)' \
+		MAKEDEPEND='$$$${TOP}/util/domd $$$${TOP} $(LCONFIG) $(MAKEDEPPROG)' \
 		DEPFLAG='-DOPENSSL_NO_DEPRECATED $(DEPFLAG)'	\
 		MAKEDEPPROG='$(MAKEDEPPROG)'			\
 		SHARED_LDFLAGS='$(SHARED_LDFLAGS)'		\
diff -Naur openssl-1.0.1t.orig/test/Makefile openssl-1.0.1t.patched/test/Makefile
--- openssl-1.0.1t.orig/test/Makefile	2016-05-03 16:49:51.000000000 +0300
+++ openssl-1.0.1t.patched/test/Makefile	2016-05-08 00:53:02.258276100 +0300
@@ -7,7 +7,7 @@
 CC=		cc
 INCLUDES=	-I$(TOP) -I../include $(KRB5_INCLUDES)
 CFLAG=		-g
-MAKEDEPEND=	$(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
+MAKEDEPEND=	$(TOP)/util/domd $(TOP) $(LCONFIG) $(MAKEDEPPROG)
 PERL=		perl
 # KRB5 stuff
 KRB5_INCLUDES=
diff -Naur openssl-1.0.1t.orig/util/mk1mf.pl openssl-1.0.1t.patched/util/mk1mf.pl
--- openssl-1.0.1t.orig/util/mk1mf.pl	2016-05-03 16:49:00.000000000 +0300
+++ openssl-1.0.1t.patched/util/mk1mf.pl	2016-05-08 00:53:02.260276200 +0300
@@ -498,7 +498,8 @@
 # You should not need to touch anything below this point
 ######################################################
 
-E_EXE=openssl
+E_EXE=openssl$libsuffix
+LCONFIG=-$libsuffix
 SSL=$ssl
 CRYPTO=$crypto
 
@@ -1149,6 +1150,8 @@
 		"shlib" => \$shlib,
 		"dll" => \$shlib,
 		"shared" => 0,
+		"debug_lib" => \$debug_lib,
+		"static_lib" => \$static_lib,
 		"no-sctp" => 0,
 		"no-srtp" => 0,
 		"no-gmp" => 0,
diff -Naur openssl-1.0.1t.orig/util/mkdef.pl openssl-1.0.1t.patched/util/mkdef.pl
--- openssl-1.0.1t.orig/util/mkdef.pl	2016-05-03 16:49:00.000000000 +0300
+++ openssl-1.0.1t.patched/util/mkdef.pl	2016-05-08 00:53:02.262276300 +0300
@@ -55,6 +55,8 @@
 #
 
 my $debug=0;
+my $debug_lib=0;
+my $static_lib=0;
 
 my $crypto_num= "util/libeay.num";
 my $ssl_num=    "util/ssleay.num";
@@ -155,6 +157,8 @@
 foreach (@ARGV, split(/ /, $options))
 	{
 	$debug=1 if $_ eq "debug";
+	$debug_lib=1 if $_ eq "debug_lib";
+	$static_lib=1 if $_ eq "static_lib";
 	$W32=1 if $_ eq "32";
 	$W16=1 if $_ eq "16";
 	if($_ eq "NT") {
@@ -1317,7 +1321,20 @@
 		  # Vendor field can't contain colon, drat; so we omit http://
 		  $description = "\@#$http_vendor:$version#\@$what; DLL for library $name.  Build for EMX -Zmtd";
 		}
-
+		
+	$libsuffix="";
+	if ($static_lib) {
+		$libsuffix="MT";
+	} else {
+		$libsuffix="MD";
+	}
+	
+	if ($debug_lib) {
+		$libsuffix=$libsuffix."d";
+	}
+		
+	$libname=$libname.$libsuffix;
+	
 	print OUT <<"EOF";
 ;
 ; Definition file for the DLL version of the $name library from OpenSSL
diff -Naur openssl-1.0.1t.orig/util/pl/VC-32.pl openssl-1.0.1t.patched/util/pl/VC-32.pl
--- openssl-1.0.1t.orig/util/pl/VC-32.pl	2016-05-03 16:49:00.000000000 +0300
+++ openssl-1.0.1t.patched/util/pl/VC-32.pl	2016-05-08 00:53:02.264276400 +0300
@@ -15,6 +15,20 @@
 	{
 	$crypto="libeay32";
 	}
+	
+$libsuffix="";
+if ($static_lib) {
+	$libsuffix="MT";
+} else {
+	$libsuffix="MD";
+}
+
+if ($debug_lib) {
+	$libsuffix=$libsuffix."d";
+}
+	
+$ssl=$ssl.$libsuffix;
+$crypto=$crypto.$libsuffix;
 
 $o='\\';
 $cp='$(PERL) util/copy.pl';
@@ -151,8 +165,8 @@
 	}
 
 # generate symbols.pdb unconditionally
-$app_cflag.=" /Zi /Fd\$(TMP_D)/app";
-$lib_cflag.=" /Zi /Fd\$(TMP_D)/lib";
+$app_cflag.=" /Zi /Fd\$(TMP_D)/app".$libsuffix;
+$lib_cflag.=" /Zi /Fd\$(TMP_D)/lib".$libsuffix;
 $lflags.=" /debug";
 
 $obj='.obj';
