On 2024-04-05 Fr 10:12, Andrew Dunstan wrote:

On 2024-04-05 Fr 08:25, Andrew Dunstan wrote:



Here is an attempt to fix all that. It's ugly, but I think it's more principled.

First, instead of getting the ldopts and then trying to filter out the ldflags and ccdlflags, it tells perl not to include those in the first place, by overriding a couple of routines in ExtUtils::Embed. And second, it's smarter about splitting what's left, so that it doesn't split on a space that's in a quoted item. The perl that's used to do that second bit is not pretty, but it has been tested on the system where the problem arose and apparently cures the problem. (No doubt some perl guru could improve it.) It also works on my Ubuntu system, so I don't think we'll be breaking anything (famous last words).



Apparently I spoke too soon. Please ignore the above for now.




OK, this has been fixed and checked. The attached is what I propose.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com
diff --git a/meson.build b/meson.build
index 87437960bc..be87ef6950 100644
--- a/meson.build
+++ b/meson.build
@@ -993,21 +993,15 @@ if not perlopt.disabled()
     # Config's ccdlflags and ldflags.  (Those are the choices of those who
     # built the Perl installation, which are not necessarily appropriate
     # for building PostgreSQL.)
-    ldopts = run_command(perl, '-MExtUtils::Embed', '-e', 'ldopts', check: true).stdout().strip()
-    undesired = run_command(perl_conf_cmd, 'ccdlflags', check: true).stdout().split()
-    undesired += run_command(perl_conf_cmd, 'ldflags', check: true).stdout().split()
-
-    perl_ldopts = []
-    foreach ldopt : ldopts.split(' ')
-      if ldopt == '' or ldopt in undesired
-        continue
-      endif
-
-      perl_ldopts += ldopt.strip('"')
-    endforeach
-
+    ldopts = run_command(perl, '-MExtUtils::Embed', '-e', '*ExtUtils::Embed::_ldflags = *Extutils::Embed::_ccdlflags = sub { return q[]; }; ldopts',
+                         check: true).stdout().strip()
+    # avoid use of " char in this perl mini-program to avoid possibly
+    # confusing the Windows command processor
+    perl_ldopts = run_command(perl, '-MEnglish', '-e',
+                              'my $arg = shift; while ($arg =~ /\S/) { if ($arg =~ /^\s*([^\042 ]+)(?![\042])/) { print qq[$1\n]; $arg = $POSTMATCH;} elsif ($arg =~ /^\s*\042([^\042]+)\042/) { print qq[$1\n]; $arg = $POSTMATCH;} }',
+                              '--', ldopts, check: true).stdout().strip().split('\n')
     message('LDFLAGS recommended by perl: "@0@"'.format(ldopts))
-    message('LDFLAGS for embedding perl: "@0@"'.format(' '.join(perl_ldopts)))
+    message('LDFLAGS for embedding perl:\n"@0@"'.format('\n'.join(perl_ldopts)))
 
     perl_dep_int = declare_dependency(
       compile_args: perl_ccflags,

Reply via email to