From 0fd47642701e4941c6a2bb3eca29b9509b999399 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 10 Mar 2021 15:11:13 -0800
Subject: [PATCH v5 07/16] meson: prereq: add
 src/tools/gen_versioning_script.pl.

Currently the logic is all in src/Makefile.shlib. This adds a sketch
of a generation script that can be used from meson.
---
 src/tools/gen_versioning_script.pl | 58 ++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 src/tools/gen_versioning_script.pl

diff --git a/src/tools/gen_versioning_script.pl b/src/tools/gen_versioning_script.pl
new file mode 100644
index 00000000000..862b5e14aad
--- /dev/null
+++ b/src/tools/gen_versioning_script.pl
@@ -0,0 +1,58 @@
+use strict;
+use warnings;
+
+my $format = $ARGV[0] or die "$0: missing required argument: format\n";
+my $input = $ARGV[1] or die "$0: missing required argument: input\n";
+my $output = $ARGV[2] or die "$0: missing required argument: output\n";
+
+#FIXME: handle format argument, so we can reuse the one script for several platforms
+if (not ($format eq 'gnu' or $format eq 'darwin'))
+{
+	die "$0: $format is not yet handled (only gnu is)\n";
+}
+
+open(my $input_handle, '<', $input)
+  or die "$0: could not open input file '$input': $!\n";
+
+open(my $output_handle, '>', $output)
+  or die "$0: could not open output file '$output': $!\n";
+
+
+if ($format eq 'gnu')
+{
+	print $output_handle "{
+  global:
+";
+}
+
+while (<$input_handle>)
+{
+	if (/^#/)
+	{
+		# don't do anything with a comment
+	}
+	elsif (/^([^\s]+)\s+([^\s]+)/)
+	{
+		if ($format eq 'gnu')
+		{
+			print $output_handle "    $1;\n";
+		}
+		elsif ($format eq 'darwin')
+		{
+			print $output_handle "    _$1\n";
+		}
+	}
+	else
+	{
+		die "$0: unexpected line $_\n";
+	}
+}
+
+if ($format eq 'gnu')
+{
+	print $output_handle "  local: *;
+};
+";
+}
+
+exit(0);
-- 
2.23.0.385.gbc12974a89

