diff -Naur openssl-1.0.1p.orig/crypto/Makefile openssl-1.0.1p.new/crypto/Makefile
--- openssl-1.0.1p.orig/crypto/Makefile	2015-07-09 15:22:09.000000000 +0300
+++ openssl-1.0.1p.new/crypto/Makefile	2015-08-15 22:30:53.335069000 +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.1p.orig/crypto/srp/Makefile openssl-1.0.1p.new/crypto/srp/Makefile
--- openssl-1.0.1p.orig/crypto/srp/Makefile	2015-07-09 15:22:19.000000000 +0300
+++ openssl-1.0.1p.new/crypto/srp/Makefile	2015-08-15 22:30:53.355069000 +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.1p.orig/crypto/ts/Makefile openssl-1.0.1p.new/crypto/ts/Makefile
--- openssl-1.0.1p.orig/crypto/ts/Makefile	2015-07-09 15:22:19.000000000 +0300
+++ openssl-1.0.1p.new/crypto/ts/Makefile	2015-08-15 22:30:53.355069000 +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.1p.orig/Makefile.bak openssl-1.0.1p.new/Makefile.bak
--- openssl-1.0.1p.orig/Makefile.bak	2015-07-09 15:22:06.000000000 +0300
+++ openssl-1.0.1p.new/Makefile.bak	2015-08-15 22:30:53.355069000 +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.1p.orig/Makefile.org openssl-1.0.1p.new/Makefile.org
--- openssl-1.0.1p.orig/Makefile.org	2015-07-09 15:21:24.000000000 +0300
+++ openssl-1.0.1p.new/Makefile.org	2015-08-15 22:30:53.365069000 +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.1p.orig/test/Makefile openssl-1.0.1p.new/test/Makefile
--- openssl-1.0.1p.orig/test/Makefile	2015-07-09 15:22:23.000000000 +0300
+++ openssl-1.0.1p.new/test/Makefile	2015-08-15 22:30:53.365069000 +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.1p.orig/util/mk1mf.pl openssl-1.0.1p.new/util/mk1mf.pl
--- openssl-1.0.1p.orig/util/mk1mf.pl	2015-07-09 15:21:24.000000000 +0300
+++ openssl-1.0.1p.new/util/mk1mf.pl	2015-08-15 22:30:53.365069000 +0300
@@ -496,7 +496,8 @@
 # You should not need to touch anything below this point
 ######################################################
 
-E_EXE=openssl
+E_EXE=openssl$libsuffix
+LCONFIG=-$libsuffix
 SSL=$ssl
 CRYPTO=$crypto
 
@@ -1144,6 +1145,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.1p.orig/util/mkdef.pl openssl-1.0.1p.new/util/mkdef.pl
--- openssl-1.0.1p.orig/util/mkdef.pl	2015-07-09 15:21:24.000000000 +0300
+++ openssl-1.0.1p.new/util/mkdef.pl	2015-08-15 22:30:53.365069000 +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";
@@ -153,6 +155,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") {
@@ -1313,7 +1317,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.1p.orig/Makefile openssl-1.0.1p.new/Makefile
--- openssl-1.0.1p.orig/Makefile	2015-07-09 15:22:23.000000000 +0300
+++ openssl-1.0.1p.new/Makefile	2015-10-22 15:01:16.059482200 +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.1p.orig/util/pl/VC-32.pl openssl-1.0.1p.new/util/pl/VC-32.pl
--- openssl-1.0.1p.orig/util/pl/VC-32.pl	2015-07-09 15:21:24.000000000 +0300
+++ openssl-1.0.1p.new/util/pl/VC-32.pl	2015-08-15 22:30:53.365069000 +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';
