Support linking with MinGW-built Perl.
authorNoah Misch
Fri, 24 Nov 2017 04:22:04 +0000 (20:22 -0800)
committerNoah Misch
Fri, 24 Nov 2017 04:32:01 +0000 (20:32 -0800)
This is necessary for ActivePerl 5.18 onwards and for Strawberry Perl.
It is not sufficient for 32-bit builds with newer Visual Studio; these
fail with error LINK2026.  Back-patch to 9.3 (all supported versions).

Reported by Victor Wagner.

Discussion: https://postgr.es/m/20160326154321.7754ab8f@wagner.wagner.home

config/perl.m4
configure
src/pl/plperl/plperl.h
src/tools/msvc/Mkvcbuild.pm

index fbb13ed1c02f646516ae5d8112e028e0cd6ae3a7..1db1e627d8defff45c80720805a354fba427493b 100644 (file)
@@ -86,12 +86,19 @@ AC_DEFUN([PGAC_CHECK_PERL_EMBED_LDFLAGS],
 [AC_REQUIRE([PGAC_PATH_PERL])
 AC_MSG_CHECKING(for flags to link embedded Perl)
 if test "$PORTNAME" = "win32" ; then
-perl_lib=`basename $perl_archlibexp/CORE/perl[[5-9]]*.lib .lib`
-test -e "$perl_archlibexp/CORE/$perl_lib.lib" && perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+   perl_lib=`basename $perl_archlibexp/CORE/perl[[5-9]]*.lib .lib`
+   if test -e "$perl_archlibexp/CORE/$perl_lib.lib"; then
+       perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+   else
+       perl_lib=`basename $perl_archlibexp/CORE/libperl[[5-9]]*.a .a | sed 's/^lib//'`
+       if test -e "$perl_archlibexp/CORE/lib$perl_lib.a"; then
+           perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+       fi
+   fi
 else
-pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
-pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
-perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e ["s/ -arch [-a-zA-Z0-9_]*//g"]`
+   pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
+   pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
+   perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e ["s/ -arch [-a-zA-Z0-9_]*//g"]`
 fi
 AC_SUBST(perl_embed_ldflags)dnl
 if test -z "$perl_embed_ldflags" ; then
index 185c207fde51a4a5fa9d5e8f47e3e73d207504e6..611983d1a3d287a07f9a64b4d123f919851eb41a 100755 (executable)
--- a/configure
+++ b/configure
@@ -7617,12 +7617,19 @@ $as_echo "$perl_embed_ccflags" >&6; }
 { $as_echo "$as_me:$LINENO: checking for flags to link embedded Perl" >&5
 $as_echo_n "checking for flags to link embedded Perl... " >&6; }
 if test "$PORTNAME" = "win32" ; then
-perl_lib=`basename $perl_archlibexp/CORE/perl[5-9]*.lib .lib`
-test -e "$perl_archlibexp/CORE/$perl_lib.lib" && perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+   perl_lib=`basename $perl_archlibexp/CORE/perl[5-9]*.lib .lib`
+   if test -e "$perl_archlibexp/CORE/$perl_lib.lib"; then
+       perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+   else
+       perl_lib=`basename $perl_archlibexp/CORE/libperl[5-9]*.a .a | sed 's/^lib//'`
+       if test -e "$perl_archlibexp/CORE/lib$perl_lib.a"; then
+           perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+       fi
+   fi
 else
-pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
-pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
-perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e "s/ -arch [-a-zA-Z0-9_]*//g"`
+   pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
+   pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
+   perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e "s/ -arch [-a-zA-Z0-9_]*//g"`
 fi
 if test -z "$perl_embed_ldflags" ; then
    { $as_echo "$as_me:$LINENO: result: no" >&5
index b7fc76193820f860b980c72815dae011c8e61c52..542bb3cda1cb59d86e708906456b8bb4ff6c227e 100644 (file)
 #undef vsnprintf
 #endif
 
+/*
+ * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
+ * __inline__.  Translate to something MSVC recognizes.
+ */
+#ifdef _MSC_VER
+#define __inline__ inline
+#endif
+
 
 /*
  * Get the basic Perl API.  We use PERL_NO_GET_CONTEXT mode so that our code
index 1424bcd926c288ee446487902f8ee15be67e5088..20de55f988bd8c5c4771ba1c63591a727d0392b6 100644 (file)
@@ -238,9 +238,10 @@ sub mkvcbuild
            }
        }
        $plperl->AddReference($postgres);
+       my $perl_path = $solution->{options}->{perl} . '\lib\CORE\*perl*';
+       # ActivePerl 5.16 provided perl516.lib; 5.18 provided libperl518.a
        my @perl_libs =
-         grep { /perl\d+.lib$/ }
-         glob($solution->{options}->{perl} . '\lib\CORE\perl*.lib');
+         grep { /perl\d+\.lib$|libperl\d+\.a$/ } glob($perl_path);
        if (@perl_libs == 1)
        {
            $plperl->AddLibrary($perl_libs[0]);