From: Timo Paulssen <timonator@perpetuum-immobile.de>
Date: Fri, 20 Sep 2024 22:35:01 +0200
Subject: Allow passing -ffile-prefix-map without storing it in gen/config.c

---
 Configure.pl      | 19 ++++++++++++++++++-
 build/Makefile.in |  2 +-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Configure.pl b/Configure.pl
index b6d2a32..a7c8ff2 100755
--- a/Configure.pl
+++ b/Configure.pl
@@ -510,7 +510,23 @@ push @cflags, $ENV{CPPFLAGS} if $ENV{CPPFLAGS};
 # #ifdef _GNU_SOURCE/#endif.
 push @cflags, '-D_GNU_SOURCE' unless $args{'has-libuv'};
 
+# If there is a -ffile-prefix-map, it must not go into the moar config,
+# since it's meant to be for making builds reproducible.
+
+@cflags = uniq(@cflags);
+
+my @silent_cflags;
+@cflags = map {
+    if ($_ =~ /(-ffile-prefix-map=[^=]+?=[^-]+?)(?:\s-|$)/) {
+        my $fullflag = $1;
+        push @silent_cflags, $fullflag;
+        $_ =~ s/$fullflag//;
+    }
+    $_;
+    } @cflags;
+
 $config{cflags} = join ' ', uniq(@cflags);
+$config{silent_cflags} = join ' ', uniq(@silent_cflags);
 
 # generate LDFLAGS
 my @ldflags = ($config{ldmiscflags});
@@ -671,7 +687,7 @@ my $order = $config{be} ? 'big endian' : 'little endian';
 # dump configuration
 print "\n", <<TERM, "\n";
         make: $config{make}
-     compile: $config{cc} $config{cflags}
+     compile: $config{cc} $config{cflags} $config{silent_cflags}
     includes: $config{cincludes} $config{moar_cincludes}
         link: $config{ld} $config{ldflags}
         libs: $config{ldlibs}
@@ -1046,6 +1062,7 @@ sub write_backend_config {
     $config{backendconfig} = '';
     for my $k (sort keys %config) {
         next if $k eq 'backendconfig';
+        next if $k eq "silent_cflags";
         my $v = $config{$k};
 
         if (ref($v) eq 'ARRAY') {
diff --git a/build/Makefile.in b/build/Makefile.in
index fe58124..020ddbf 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -37,7 +37,7 @@ MASTDIR   = @mastdir@
 
 PKGCONFIGDIR = @prefix@/share/pkgconfig
 
-CFLAGS    = @cflags@ @ccdef@MVM_TRACING=$(TRACING) @ccdef@MVM_CGOTO=$(CGOTO)
+CFLAGS    = @cflags@ @silent_cflags@ @ccdef@MVM_TRACING=$(TRACING) @ccdef@MVM_CGOTO=$(CGOTO)
 CINCLUDES = @moar_cincludes@ \
             @ccinc@@shaincludedir@ \
             @mimalloc_include@ \
