--- libp11/configure.ac.orig	2024-11-22 11:52:22.431098100 +0100
+++ libp11/configure.ac	2024-11-22 11:56:06.066591800 +0100
@@ -131,10 +131,10 @@
 	[AS_HELP_STRING([--with-enginesdir], [OpenSSL engines directory])],
 	[enginesexecdir="${withval}"],
 	[
-		enginesexecdir="`$PKG_CONFIG --variable=enginesdir --silence-errors libcrypto`"
+		enginesexecdir="`$PKG_CONFIG --define-variable=prefix="${prefix}" --variable=enginesdir --silence-errors libcrypto`"
 		if test "${enginesexecdir}" = ""; then
-		    libcryptodir="`$PKG_CONFIG --variable=libdir --silence-errors libcrypto || \
-			$PKG_CONFIG --variable=libdir openssl`"
+		    libcryptodir="`$PKG_CONFIG --define-variable=prefix="${prefix}" --variable=libdir --silence-errors libcrypto || \
+			$PKG_CONFIG --define-variable=prefix="${prefix}" --variable=libdir openssl`"
 		    if test -d "$libcryptodir/$debian_ssl_prefix"; then
 			# Debian-based OpenSSL package (for example Ubuntu)
 			enginesexecdir="$libcryptodir/$debian_ssl_prefix"
@@ -153,7 +153,7 @@
 	[pkcs11-module],
 	[AS_HELP_STRING([--with-pkcs11-module], [default PKCS11 module])],
 	[pkcs11_module="${withval}"],
-	[pkcs11_module="`$PKG_CONFIG --variable=proxy_module --silence-errors p11-kit-1`"])
+	[pkcs11_module="`$PKG_CONFIG --define-variable=prefix="${prefix}" --variable=proxy_module --silence-errors p11-kit-1`"])
 
 dnl Checks for programs.
 AC_PROG_CPP
