@@ -113,6 +113,34 @@ sub copyFile
113113 close ($o );
114114}
115115
116+ # Fetch version of OpenSSL based on a parsing of the command shipped with
117+ # the installer this build is linking to. This returns as result an array
118+ # made of the three first digits of the OpenSSL version, which is enough
119+ # to decide which options to apply depending on the version of OpenSSL
120+ # linking with.
121+ sub GetOpenSSLVersion
122+ {
123+ my $self = shift ;
124+
125+ # Attempt to get OpenSSL version and location. This assumes that
126+ # openssl.exe is in the specified directory.
127+ my $opensslcmd =
128+ $self -> {options }-> {openssl } . " \\ bin\\ openssl.exe version 2>&1" ;
129+ my $sslout = ` $opensslcmd ` ;
130+
131+ $? >> 8 == 0
132+ or croak
133+ " Unable to determine OpenSSL version: The openssl.exe command wasn't found." ;
134+
135+ if ($sslout =~ / (\d +)\. (\d +)\. (\d +)(\D )/m )
136+ {
137+ return ($1 , $2 , $3 );
138+ }
139+
140+ croak
141+ " Unable to determine OpenSSL version: The openssl.exe version could not be determined." ;
142+ }
143+
116144sub GenerateFiles
117145{
118146 my $self = shift ;
@@ -167,10 +195,9 @@ s{PG_VERSION_STR "[^"]+"}{PG_VERSION_STR "PostgreSQL $self->{strver}$extraver, c
167195 print $o " #ifndef IGNORE_CONFIGURED_SETTINGS\n " ;
168196 print $o " #define USE_ASSERT_CHECKING 1\n "
169197 if ($self -> {options }-> {asserts });
170- print $o " #define USE_LDAP 1\n " if ($self -> {options }-> {ldap });
171- print $o " #define HAVE_LIBZ 1\n " if ($self -> {options }-> {zlib });
172- print $o " #define USE_OPENSSL 1\n " if ($self -> {options }-> {openssl });
173- print $o " #define ENABLE_NLS 1\n " if ($self -> {options }-> {nls });
198+ print $o " #define USE_LDAP 1\n " if ($self -> {options }-> {ldap });
199+ print $o " #define HAVE_LIBZ 1\n " if ($self -> {options }-> {zlib });
200+ print $o " #define ENABLE_NLS 1\n " if ($self -> {options }-> {nls });
174201
175202 print $o " #define BLCKSZ " , 1024 * $self -> {options }-> {blocksize },
176203 " \n " ;
@@ -221,6 +248,21 @@ s{PG_VERSION_STR "[^"]+"}{PG_VERSION_STR "PostgreSQL $self->{strver}$extraver, c
221248 {
222249 print $o " #define ENABLE_GSS 1\n " ;
223250 }
251+ if ($self -> {options }-> {openssl })
252+ {
253+ print $o " #define USE_OPENSSL 1\n " ;
254+
255+ my ($digit1 , $digit2 , $digit3 ) = $self -> GetOpenSSLVersion();
256+
257+ # More symbols are needed with OpenSSL 1.1.0 and above.
258+ if ($digit1 >= ' 1' && $digit2 >= ' 1' && $digit3 >= ' 0' )
259+ {
260+ print $o " #define HAVE_ASN1_STRING_GET0_DATA 1\n " ;
261+ print $o " #define HAVE_BIO_GET_DATA 1\n " ;
262+ print $o " #define HAVE_BIO_METH_NEW 1\n " ;
263+ print $o " #define HAVE_OPENSSL_INIT_SSL 1\n " ;
264+ }
265+ }
224266 if ($self -> {options }-> {icu })
225267 {
226268 print $o " #define USE_ICU 1\n " ;
@@ -529,21 +571,70 @@ sub AddProject
529571 if ($self -> {options }-> {openssl })
530572 {
531573 $proj -> AddIncludeDir($self -> {options }-> {openssl } . ' \include' );
532- if (-e " $self ->{options}->{openssl}/lib/VC/ssleay32MD.lib" )
574+ my ($digit1 , $digit2 , $digit3 ) = $self -> GetOpenSSLVersion();
575+
576+ # Starting at version 1.1.0 the OpenSSL installers have
577+ # changed their library names from:
578+ # - libeay to libcrypto
579+ # - ssleay to libssl
580+ if ($digit1 >= ' 1' && $digit2 >= ' 1' && $digit3 >= ' 0' )
533581 {
534- $proj -> AddLibrary(
535- $self -> {options }-> {openssl } . ' \lib\VC\ssleay32.lib' , 1);
536- $proj -> AddLibrary(
537- $self -> {options }-> {openssl } . ' \lib\VC\libeay32.lib' , 1);
582+ my $dbgsuffix ;
583+ my $libsslpath ;
584+ my $libcryptopath ;
585+
586+ # The format name of the libraries is slightly
587+ # different between the Win32 and Win64 platform, so
588+ # adapt.
589+ if (-e " $self ->{options}->{openssl}/lib/VC/sslcrypto32MD.lib" )
590+ {
591+ # Win32 here, with a debugging library set.
592+ $dbgsuffix = 1;
593+ $libsslpath = ' \lib\VC\libssl32.lib' ;
594+ $libcryptopath = ' \lib\VC\libcrypto32.lib' ;
595+ }
596+ elsif (-e " $self ->{options}->{openssl}/lib/VC/sslcrypto64MD.lib" )
597+ {
598+ # Win64 here, with a debugging library set.
599+ $dbgsuffix = 1;
600+ $libsslpath = ' \lib\VC\libssl64.lib' ;
601+ $libcryptopath = ' \lib\VC\libcrypto64.lib' ;
602+ }
603+ else
604+ {
605+ # On both Win32 and Win64 the same library
606+ # names are used without a debugging context.
607+ $dbgsuffix = 0;
608+ $libsslpath = ' \lib\libssl.lib' ;
609+ $libcryptopath = ' \lib\libcrypto.lib' ;
610+ }
611+
612+ $proj -> AddLibrary($self -> {options }-> {openssl } . $libsslpath ,
613+ $dbgsuffix );
614+ $proj -> AddLibrary($self -> {options }-> {openssl } . $libcryptopath ,
615+ $dbgsuffix );
538616 }
539617 else
540618 {
541- # We don't expect the config-specific library to be here,
542- # so don't ask for it in last parameter
543- $proj -> AddLibrary(
544- $self -> {options }-> {openssl } . ' \lib\ssleay32.lib' , 0);
545- $proj -> AddLibrary(
546- $self -> {options }-> {openssl } . ' \lib\libeay32.lib' , 0);
619+ # Choose which set of libraries to use depending on if
620+ # debugging libraries are in place in the installer.
621+ if (-e " $self ->{options}->{openssl}/lib/VC/ssleay32MD.lib" )
622+ {
623+ $proj -> AddLibrary(
624+ $self -> {options }-> {openssl } . ' \lib\VC\ssleay32.lib' , 1);
625+ $proj -> AddLibrary(
626+ $self -> {options }-> {openssl } . ' \lib\VC\libeay32.lib' , 1);
627+ }
628+ else
629+ {
630+ # We don't expect the config-specific library
631+ # to be here, so don't ask for it in last
632+ # parameter.
633+ $proj -> AddLibrary(
634+ $self -> {options }-> {openssl } . ' \lib\ssleay32.lib' , 0);
635+ $proj -> AddLibrary(
636+ $self -> {options }-> {openssl } . ' \lib\libeay32.lib' , 0);
637+ }
547638 }
548639 }
549640 if ($self -> {options }-> {nls })
0 commit comments