450916
diff --git a/Configure b/Configure
450916
index c39f71a..7f3d905 100755
450916
--- a/Configure
450916
+++ b/Configure
450916
@@ -727,6 +727,7 @@ my $idx_multilib = $idx++;
450916
 my $prefix="";
450916
 my $libdir="";
450916
 my $openssldir="";
450916
+my $enginesdir="";
450916
 my $exe_ext="";
450916
 my $install_prefix= "$ENV{'INSTALL_PREFIX'}";
450916
 my $cross_compile_prefix="";
450916
@@ -956,6 +957,10 @@ PROCESS_ARGS:
450916
 				{
450916
 				$openssldir=$1;
450916
 				}
450916
+			elsif (/^--enginesdir=(.*)$/)
450916
+				{
450916
+				$enginesdir=$1;
450916
+				}
450916
 			elsif (/^--install.prefix=(.*)$/)
450916
 				{
450916
 				$install_prefix=$1;
450916
@@ -1207,7 +1212,7 @@ chop $prefix if $prefix =~ /.\/$/;
450916
 
450916
 $openssldir=$prefix . "/ssl" if $openssldir eq "";
450916
 $openssldir=$prefix . "/" . $openssldir if $openssldir !~ /(^\/|^[a-zA-Z]:[\\\/])/;
450916
-
450916
+$enginesdir="$prefix/lib/engines" if $enginesdir eq "";
450916
 
450916
 print "IsMK1MF=$IsMK1MF\n";
450916
 
450916
@@ -1709,6 +1714,7 @@ while (<IN>)
450916
 	s/^INSTALLTOP=.*$/INSTALLTOP=$prefix/;
450916
 	s/^MULTILIB=.*$/MULTILIB=$multilib/;
450916
 	s/^OPENSSLDIR=.*$/OPENSSLDIR=$openssldir/;
450916
+	s/^ENGINESDIR=.*$/ENGINESDIR=$enginesdir/;
450916
 	s/^LIBDIR=.*$/LIBDIR=$libdir/;
450916
 	s/^INSTALL_PREFIX=.*$/INSTALL_PREFIX=$install_prefix/;
450916
 	s/^PLATFORM=.*$/PLATFORM=$target/;
450916
@@ -1915,7 +1921,7 @@ while (<IN>)
450916
 		}
450916
 	elsif	(/^#define\s+ENGINESDIR/)
450916
 		{
450916
-		my $foo = "$prefix/$libdir/engines";
450916
+		my $foo = "$enginesdir";
450916
 		$foo =~ s/\\/\\\\/g;
450916
 		print OUT "#define ENGINESDIR \"$foo\"\n";
450916
 		}
450916
diff --git a/Makefile.org b/Makefile.org
450916
index 2377f50..fe8d54c 100644
450916
--- a/Makefile.org
450916
+++ b/Makefile.org
450916
@@ -28,6 +28,7 @@ INSTALLTOP=/usr/local/ssl
450916
 
450916
 # Do not edit this manually. Use Configure --openssldir=DIR do change this!
450916
 OPENSSLDIR=/usr/local/ssl
450916
+ENGINESDIR=$${libdir}/engines
450916
 
450916
 # NO_IDEA - Define to build without the IDEA algorithm
450916
 # NO_RC4  - Define to build without the RC4 algorithm
450916
@@ -368,7 +369,7 @@ libcrypto.pc: Makefile
450916
 	    echo 'exec_prefix=$${prefix}'; \
450916
 	    echo 'libdir=$${exec_prefix}/$(LIBDIR)'; \
450916
 	    echo 'includedir=$${prefix}/include'; \
450916
-	    echo 'enginesdir=$${libdir}/engines'; \
450916
+	    echo 'enginesdir=$(ENGINESDIR)'; \
450916
 	    echo ''; \
450916
 	    echo 'Name: OpenSSL-libcrypto'; \
450916
 	    echo 'Description: OpenSSL cryptography library'; \
450916
diff --git a/engines/Makefile b/engines/Makefile
450916
index 2058ff4..a2c407b 100644
450916
--- a/engines/Makefile
450916
+++ b/engines/Makefile
450916
@@ -124,7 +124,7 @@ install:
450916
 				esac; \
450916
 				cp $$pfx$$l$$sfx $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
450916
 			  fi; \
450916
-			  chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
450916
+			  chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new; \
450916
 			  mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx.new $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/engines/$$pfx$$l$$sfx ); \
450916
 		done; \
450916
 	fi