Add libssl libraries to Windows build

This commit extends the perl Configure script to also check for libssl
in addition to libcrypto and change the vcxproj source files to link
with both libcrypto and libssl.
This commit is contained in:
Ondřej Surý
2020-10-10 07:26:18 +02:00
parent 9a2065e2f4
commit 127ba7e930
49 changed files with 204 additions and 171 deletions

View File

@@ -248,7 +248,8 @@ my @substlib = ("GSSAPI_LIB",
"KRB5_LIB",
"LIBXML2_LIB",
"LIBUV_LIB",
"OPENSSL_LIB",
"OPENSSL_LIBCRYPTO",
"OPENSSL_LIBSSL",
"READLINE_LIB",
"READLINE_LIBD",
"ZLIB_LIB");
@@ -265,7 +266,8 @@ my @substdll = ("COMERR_DLL",
"K5SPRT_DLL",
"LIBXML2_DLL",
"LIBUV_DLL",
"OPENSSL_DLL",
"OPENSSL_DLLCRYPTO",
"OPENSSL_DLLSSL",
"WSHELP_DLL",
"ZLIB_DLL");
@@ -1379,60 +1381,59 @@ if ($use_openssl eq "auto") {
}
# falls into (so no else)
if ($use_openssl eq "yes") {
my @dirlist;
$openssl_path = File::Spec->rel2abs($openssl_path);
if ($verbose) {
print "checking for OpenSSL built directory at \"$openssl_path\"\n";
}
my $openssl_new = 0;
if (!-f File::Spec->catfile($openssl_path,
"inc32/openssl/opensslv.h")) {
$openssl_new = 1;
if (!-f File::Spec->catfile($openssl_path,
"include/openssl/opensslv.h")) {
die "can't find OpenSSL opensslv.h include\n";
}
die "can't find OpenSSL 1.1 opensslv.h include\n";
}
my $openssl_inc = File::Spec->catdir($openssl_path, "inc32");
my $openssl_libdir = File::Spec->catdir($openssl_path, "out32dll");
my $openssl_lib = File::Spec->catfile($openssl_libdir, "libeay32.lib");
my $openssl_dll = File::Spec->catfile($openssl_libdir, "libeay32.dll");
if (!$openssl_new) {
# Check libraries are where we expect
if (!-f $openssl_lib) {
die "can't find OpenSSL libeay32.lib library\n";
}
if (!-f $openssl_dll) {
die "can't find OpenSSL libeay32.dll DLL\n";
}
} else {
# OpenSSL >= 1.1 is easier at the exception of the DLL
if ($verbose) {
print "new (>= 1.1) OpenSSL version\n";
}
$openssl_inc = File::Spec->catdir($openssl_path, "include");
$openssl_libdir = $openssl_path;
$openssl_lib = File::Spec->catfile($openssl_path, "libcrypto.lib");
if (!-f $openssl_lib) {
die "can't find OpenSSL libcrypto.lib library\n";
}
opendir DIR, $openssl_path || die "No Directory: $!\n";
my @dirlist = grep (/^libcrypto-[^.]+\.dll$/i, readdir(DIR));
closedir(DIR);
# We must get one file only
if (scalar(@dirlist) == 0) {
die "can't find OpenSSL libcrypto-*.dll DLL\n";
}
if (scalar(@dirlist) != 1) {
die "find more than one OpenSSL libcrypto-*.dll DLL candidate\n";
}
$openssl_dll = File::Spec->catdir($openssl_path, "$dirlist[0]");
my $openssl_inc = File::Spec->catdir($openssl_path, "include");
my $openssl_libdir = $openssl_path;
my $openssl_libcrypto = File::Spec->catfile($openssl_path, "libcrypto.lib");
my $openssl_libssl = File::Spec->catfile($openssl_libdir, "libssl.lib");
my $openssl_dllcrypto = File::Spec->catfile($openssl_libdir, "libcrypto.dll");
my $openssl_dllssl = File::Spec->catfile($openssl_libdir, "libssl.dll");
if (!-f $openssl_libcrypto) {
die "can't find OpenSSL libcrypto.lib library\n";
}
opendir DIR, $openssl_path || die "No Directory: $!\n";
@dirlist = grep (/^libcrypto-[^.]+\.dll$/i, readdir(DIR));
closedir(DIR);
# We must get one file only
if (scalar(@dirlist) == 0) {
die "can't find OpenSSL libcrypto-*.dll DLL\n";
}
if (scalar(@dirlist) != 1) {
die "found more than one OpenSSL libcrypto-*.dll DLL candidate\n";
}
$openssl_dllcrypto = File::Spec->catdir($openssl_path, "$dirlist[0]");
if (!-f $openssl_libssl) {
die "can't find OpenSSL libssl.lib library\n";
}
opendir DIR, $openssl_path || die "No Directory: $!\n";
@dirlist = grep (/^libssl-[^.]+\.dll$/i, readdir(DIR));
closedir(DIR);
# We must get one file only
if (scalar(@dirlist) == 0) {
die "can't find OpenSSL libssl-*.dll DLL\n";
}
if (scalar(@dirlist) != 1) {
die "found more than one OpenSSL libssl-*.dll DLL candidate\n";
}
$openssl_dllssl = File::Spec->catdir($openssl_path, "$dirlist[0]");
$cryptolib = "openssl";
$configvar{"OPENSSL_PATH"} = "$openssl_path";
$configinc{"OPENSSL_INC"} = "$openssl_inc";
$configlib{"OPENSSL_LIB"} = "$openssl_lib";
$configdll{"OPENSSL_DLL"} = "$openssl_dll";
$configlib{"OPENSSL_LIBCRYPTO"} = "$openssl_libcrypto";
$configdll{"OPENSSL_DLLCRYPTO"} = "$openssl_dllcrypto";
$configlib{"OPENSSL_LIBSSL"} = "$openssl_libssl";
$configdll{"OPENSSL_DLLSSL"} = "$openssl_dllssl";
}
if ($cryptolib eq "openssl") {
@@ -1445,14 +1446,28 @@ if ($cryptolib eq "openssl") {
# check OpenSSL
if ($use_openssl eq "yes") {
if ($verbose) {
print "checking whether linking with OpenSSL works\n";
}
my $dll = $configdll{"OPENSSL_DLL"};
#prepare the environment
my $dll = $configdll{"OPENSSL_DLLCRYPTO"};
my $ret = `copy "$dll" .`;
if ($? != 0) {
die "Can't copy OpenSSL DLL to working directory: $ret\n";
}
$dll = $configdll{"OPENSSL_DLLSSL"};
$ret = `copy "$dll" .`;
if ($? != 0) {
die "Can't copy OpenSSL DLL to working directory: $ret\n";
}
my $include = $configinc{"OPENSSL_INC"};
my $libcrypto = $configlib{"OPENSSL_LIBCRYPTO"};
my $libssl = $configlib{"OPENSSL_LIBSSL"};
# check libcrypto
if ($verbose) {
print "checking whether linking with OpenSSL libcrypto works\n";
}
open F, ">testossl.c" || die $!;
print F << 'EOF';
#include <openssl/err.h>
@@ -1465,21 +1480,45 @@ main(void)
}
EOF
close F;
my $include = $configinc{"OPENSSL_INC"};
my $library = $configlib{"OPENSSL_LIB"};
$compret = `cl /nologo /MD /I "$include" testossl.c "$library"`;
$compret = `cl /nologo /MD /I "$include" testossl.c "$libcrypto"`;
if (grep { -f and -x } "./testossl.exe") {
`./testossl.exe`;
if ($? != 0) {
die "OpenSSL test failed\n";
die "OpenSSL libcrypto test failed\n";
}
} else {
die "can't compile OpenSSL test: $compret\n";
die "can't compile OpenSSL libcrypto test: $compret\n";
}
if ($verbose) {
print "checking whether linking with OpenSSL libssl works\n";
}
open F, ">testossl.c" || die $!;
print F << 'EOF';
#include <openssl/ssl.h>
int
main(void)
{
SSL_CTX *ctx = SSL_CTX_new(SSLv23_method());
SSL_CTX_free(ctx);
return(0);
}
EOF
close F;
$compret = `cl /nologo /MD /I "$include" testossl.c "$libcrypto" "$libssl"`;
if (grep { -f and -x } "./testossl.exe") {
`./testossl.exe`;
if ($? != 0) {
die "OpenSSL libssl test failed\n";
}
} else {
die "can't compile OpenSSL libssl test: $compret\n";
}
# check OpenSSL version
if ($use_openssl eq "yes") {
if ($verbose) {
printf "checking OpenSSL library version\n";
}
@@ -1499,9 +1538,8 @@ int main() {
}
EOF
close F;
my $include = $configinc{"OPENSSL_INC"};
my $library = $configlib{"OPENSSL_LIB"};
$compret = `cl /nologo /MD /I "$include" testosslv.c "$library"`;
$compret = `cl /nologo /MD /I "$include" testosslv.c "$libcrypto"`;
if (grep { -f and -x } "./testosslv.exe") {
`./testosslv.exe`;
if ($? != 0) {
@@ -1510,10 +1548,8 @@ EOF
} else {
die "can't compile OpenSSL version test: $compret\n";
}
}
# check OpenSSL built-in support for DH/ECDSA/RSA/CRYPTO_ZALLOC/EVP_CIPHER_CTX/EVP_MD_CTX/HMAC_CTX functions
if ($use_openssl eq "yes") {
if ($verbose) {
printf "checking OpenSSL built-in support for DH/ECDSA/RSA/CRYPTO_ZALLOC/EVP_CIPHER_CTX/EVP_MD_CTX/HMAC_CTX functions\n";
}
@@ -1533,9 +1569,8 @@ int main() {
}
EOF
close F;
my $include = $configinc{"OPENSSL_INC"};
my $library = $configlib{"OPENSSL_LIB"};
$compret = `cl /nologo /MD /I "$include" testosslfunc.c "$library"`;
$compret = `cl /nologo /MD /I "$include" testosslfunc.c "$libcrypto"`;
if (grep { -f and -x } "./testosslfunc.exe") {
`./testosslfunc.exe`;
if ($? == 0) {
@@ -1554,9 +1589,7 @@ EOF
$configdefh{"HAVE_HMAC_CTX_RESET"} = 1;
}
}
}
if ($use_openssl eq "yes") {
if ($verbose) {
print "checking for OpenSSL Ed25519 support\n";
}
@@ -1577,9 +1610,8 @@ main(void)
}
EOF
close F;
my $include = $configinc{"OPENSSL_INC"};
my $library = $configlib{"OPENSSL_LIB"};
$compret = `cl /nologo /MD /I "$include" tested25519.c "$library"`;
$compret = `cl /nologo /MD /I "$include" tested25519.c "$libcrypto"`;
if (grep { -f and -x } "./tested25519.exe") {
`./tested25519.exe`;
if ($? == 0) {
@@ -1595,9 +1627,7 @@ EOF
print "disabling Ed25519\n";
}
}
}
if ($use_openssl eq "yes") {
if ($verbose) {
print "checking for OpenSSL Ed448 support\n";
}
@@ -1618,9 +1648,8 @@ main(void)
}
EOF
close F;
my $include = $configinc{"OPENSSL_INC"};
my $library = $configlib{"OPENSSL_LIB"};
$compret = `cl /nologo /MD /I "$include" tested448.c "$library"`;
$compret = `cl /nologo /MD /I "$include" tested448.c "$libcrypto"`;
if (grep { -f and -x } "./tested448.exe") {
`./tested448.exe`;
if ($? == 0) {
@@ -2463,7 +2492,9 @@ sub makeinstallfile {
my $v;
my $d;
my $name;
($v, $d, $name) =File::Spec->splitpath($configdll{"OPENSSL_DLL"});
($v, $d, $name) =File::Spec->splitpath($configdll{"OPENSSL_DLLCRYPTO"});
print LOUT "${name}-BCFT\n";
($v, $d, $name) =File::Spec->splitpath($configdll{"OPENSSL_DLLSSL"});
print LOUT "${name}-BCFT\n";
}
if ($use_libxml2 eq "yes") {