From 5f70275d2c7c2b844f198aa4da0a0714a46cffa6 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 19 Jan 2022 23:36:50 -0800
Subject: [PATCH v10 10/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 | 62 ++++++++++++++++++++++++++++++
 1 file changed, 62 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..c34ee99083e
--- /dev/null
+++ b/src/tools/gen_versioning_script.pl
@@ -0,0 +1,62 @@
+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: better argument handling
+if (not ($format eq 'aix' or $format eq 'darwin' or $format eq 'gnu'))
+{
+	die "$0: $format is not yet handled (only aix, darwin, gnu are)\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 'aix')
+		{
+			print $output_handle "    $1\n";
+		}
+		elsif ($format eq 'darwin')
+		{
+			print $output_handle "    _$1\n";
+		}
+		elsif ($format eq 'gnu')
+		{
+			print $output_handle "    $1;\n";
+		}
+	}
+	else
+	{
+		die "$0: unexpected line $_\n";
+	}
+}
+
+if ($format eq 'gnu')
+{
+	print $output_handle "  local: *;
+};
+";
+}
+
+exit(0);
-- 
2.37.0.3.g30cc8d0f14

