Remove win32ver.rc from version_stamp.pl

Started by Peter Eisentrautalmost 6 years ago5 messages
#1Peter Eisentraut
peter.eisentraut@2ndquadrant.com
1 attachment(s)

This removes another relic from the old nmake-based Windows build.
version_stamp.pl put version number information into win32ver.rc. But
win32ver.rc already gets other version number information from the
preprocessor at build time, so it would make more sense if all version
number information would be handled in the same way and we don't have
two places that do it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Remove-win32ver.rc-from-version_stamp.pl.patchtext/plain; charset=UTF-8; name=0001-Remove-win32ver.rc-from-version_stamp.pl.patch; x-mac-creator=0; x-mac-type=0Download
From b14ec81c4dd7ee24875aa2b26293ec55237a22d9 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 24 Feb 2020 08:46:13 +0100
Subject: [PATCH] Remove win32ver.rc from version_stamp.pl

This removes another relic from the old nmake-based Windows build.
version_stamp.pl put version number information into win32ver.rc.  But
win32ver.rc already gets other version number information from the
preprocessor at build time, so it would make more sense if all version
number information would be handled in the same way and we don't have
two places that do it.

What we need for this is having the major version number and the minor
version number as separate symbols.  Both configure and Solution.pm
already have that logic, because they compute PG_VERSION_NUM.  So we
just keep all the logic there now.  Put the minor version number into
a new symbol PG_MINORVERSION_NUM.  For consistency, replace
PG_MAJORVERSION, which is a string, with PG_MAJORVERSION_NUM, which is
an integer.
---
 configure                         | 12 +++++++++---
 configure.in                      |  8 +++++---
 src/bin/initdb/initdb.c           |  6 +++---
 src/bin/pg_resetwal/pg_resetwal.c | 12 ++++++------
 src/bin/pg_upgrade/check.c        |  4 ++--
 src/bin/psql/help.c               |  2 +-
 src/bin/psql/startup.c            |  2 +-
 src/include/c.h                   |  4 ++--
 src/include/common/relpath.h      |  2 +-
 src/include/pg_config.h.in        |  7 +++++--
 src/port/win32ver.rc              |  4 ++--
 src/tools/msvc/Install.pm         |  2 +-
 src/tools/msvc/Solution.pm        | 16 ++++++++--------
 src/tools/version_stamp.pl        | 14 +-------------
 14 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/configure b/configure
index d2c74e530c..ce6ff9608e 100755
--- a/configure
+++ b/configure
@@ -2804,10 +2804,17 @@ _ACEOF
 
 
 PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`
+PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`
+test -n "$PG_MINORVERSION" || PG_MINORVERSION=0
 
 
 cat >>confdefs.h <<_ACEOF
-#define PG_MAJORVERSION "$PG_MAJORVERSION"
+#define PG_MAJORVERSION_NUM $PG_MAJORVERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PG_MINORVERSION_NUM $PG_MINORVERSION
 _ACEOF
 
 
@@ -18861,8 +18868,7 @@ _ACEOF
 
 # Supply a numeric version string for use by 3rd party add-ons
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
-PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
-tr '.' '	' |
+PG_VERSION_NUM="`echo "$PG_MAJORVERSION	$PG_MINORVERSION" |
 $AWK '{printf "%d%04d", $1, $2}'`"
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.in b/configure.in
index 0b0a871298..47cd232bf8 100644
--- a/configure.in
+++ b/configure.in
@@ -30,8 +30,11 @@ AC_PREFIX_DEFAULT(/usr/local/pgsql)
 AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["$ac_configure_args"], [Saved arguments from configure])
 
 [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`]
+[PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`]
+test -n "$PG_MINORVERSION" || PG_MINORVERSION=0
 AC_SUBST(PG_MAJORVERSION)
-AC_DEFINE_UNQUOTED(PG_MAJORVERSION, "$PG_MAJORVERSION", [PostgreSQL major version as a string])
+AC_DEFINE_UNQUOTED(PG_MAJORVERSION_NUM, $PG_MAJORVERSION, [PostgreSQL major version number])
+AC_DEFINE_UNQUOTED(PG_MINORVERSION_NUM, $PG_MINORVERSION, [PostgreSQL minor version number])
 
 PGAC_ARG_REQ(with, extra-version, [STRING], [append STRING to version],
              [PG_VERSION="$PACKAGE_VERSION$withval"],
@@ -2317,8 +2320,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
 
 # Supply a numeric version string for use by 3rd party add-ons
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
-[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
-tr '.' '	' |
+[PG_VERSION_NUM="`echo "$PG_MAJORVERSION	$PG_MINORVERSION" |
 $AWK '{printf "%d%04d", $1, $2}'`"]
 AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
 AC_SUBST(PG_VERSION_NUM)
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 5302973379..acdacd05f5 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -846,7 +846,7 @@ write_version_file(const char *extrapath)
 		pg_log_error("could not open file \"%s\" for writing: %m", path);
 		exit(1);
 	}
-	if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
+	if (fprintf(version_file, "%d\n", PG_MAJORVERSION_NUM) < 0 ||
 		fclose(version_file))
 	{
 		pg_log_error("could not write file \"%s\": %m", path);
@@ -1373,8 +1373,8 @@ bootstrap_template1(void)
 
 	/* Check that bki file appears to be of the right version */
 
-	snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
-			 PG_MAJORVERSION);
+	snprintf(headerline, sizeof(headerline), "# PostgreSQL %d\n",
+			 PG_MAJORVERSION_NUM);
 
 	if (strcmp(headerline, *bki_lines) != 0)
 	{
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index c9edeb54d3..f51bcfc63c 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -538,6 +538,8 @@ CheckDataVersion(void)
 	const char *ver_file = "PG_VERSION";
 	FILE	   *ver_fd;
 	char		rawline[64];
+	long		file_major;
+	char	   *endptr;
 
 	if ((ver_fd = fopen(ver_file, "r")) == NULL)
 	{
@@ -556,14 +558,12 @@ CheckDataVersion(void)
 		exit(1);
 	}
 
-	/* strip trailing newline and carriage return */
-	(void) pg_strip_crlf(rawline);
-
-	if (strcmp(rawline, PG_MAJORVERSION) != 0)
+	file_major = strtol(rawline, &endptr, 10);
+	if (endptr == rawline || file_major != PG_MAJORVERSION_NUM)
 	{
 		pg_log_error("data directory is of wrong version");
-		pg_log_info("File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
-					ver_file, rawline, PG_MAJORVERSION);
+		pg_log_info("File \"%s\" contains \"%s\", which is not compatible with this program's version \"%d\".",
+					ver_file, rawline, PG_MAJORVERSION_NUM);
 		exit(1);
 	}
 
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 5f9a102a74..c8efedca5a 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -272,8 +272,8 @@ check_cluster_versions(void)
 
 	/* Only current PG version is supported as a target */
 	if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
-		pg_fatal("This utility can only upgrade to PostgreSQL version %s.\n",
-				 PG_MAJORVERSION);
+		pg_fatal("This utility can only upgrade to PostgreSQL version %d.\n",
+				 PG_MAJORVERSION_NUM);
 
 	/*
 	 * We can't allow downgrading because we use the target pg_dump, and
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 66b47d98cb..cae46c4612 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -631,7 +631,7 @@ helpSQL(const char *topic, unsigned short int pager)
 					QL_HELP[i].syntaxfunc(&buffer);
 					help_found = true;
 					url = psprintf("https://www.postgresql.org/docs/%s/%s.html",
-								   strstr(PG_VERSION, "devel") ? "devel" : PG_MAJORVERSION,
+								   strstr(PG_VERSION, "devel") ? "devel" : CppAsString2(PG_MAJORVERSION_NUM),
 								   QL_HELP[i].docbook_id);
 					fprintf(output, _("Command:     %s\n"
 									  "Description: %s\n"
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 3302bd4dd3..3edc70b738 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -797,7 +797,7 @@ process_psqlrc_file(char *filename)
 #endif
 
 	psqlrc_minor = psprintf("%s-%s", filename, PG_VERSION);
-	psqlrc_major = psprintf("%s-%s", filename, PG_MAJORVERSION);
+	psqlrc_major = psprintf("%s-%d", filename, PG_MAJORVERSION_NUM);
 
 	/* check for minor version first, then major, then no version */
 	if (access(psqlrc_minor, R_OK) == 0)
diff --git a/src/include/c.h b/src/include/c.h
index 831c89f473..73d1306950 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -1169,9 +1169,9 @@ typedef union PGAlignedXLogBlock
  * Make sure this matches the installation rules in nls-global.mk.
  */
 #ifdef SO_MAJOR_VERSION
-#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
+#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" CppAsString2(PG_MAJORVERSION_NUM))
 #else
-#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
+#define PG_TEXTDOMAIN(domain) (domain "-" CppAsString2(PG_MAJORVERSION_NUM))
 #endif
 
 /*
diff --git a/src/include/common/relpath.h b/src/include/common/relpath.h
index 869cabcc0d..e1909ce743 100644
--- a/src/include/common/relpath.h
+++ b/src/include/common/relpath.h
@@ -23,7 +23,7 @@
 /*
  * Name of major-version-specific tablespace subdirectories
  */
-#define TABLESPACE_VERSION_DIRECTORY	"PG_" PG_MAJORVERSION "_" \
+#define TABLESPACE_VERSION_DIRECTORY	"PG_" CppAsString2(PG_MAJORVERSION_NUM) "_" \
 									CppAsString2(CATALOG_VERSION_NO)
 
 /* Characters to allow for an OID in a relation path */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 4fa0f770aa..517e643272 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -774,8 +774,11 @@
    (GSSAPI). (--with-krb-srvnam=NAME) */
 #undef PG_KRB_SRVNAM
 
-/* PostgreSQL major version as a string */
-#undef PG_MAJORVERSION
+/* PostgreSQL major version number */
+#undef PG_MAJORVERSION_NUM
+
+/* PostgreSQL minor version number */
+#undef PG_MINORVERSION_NUM
 
 /* Define to best printf format archetype, usually gnu_printf if available. */
 #undef PG_PRINTF_ATTRIBUTE
diff --git a/src/port/win32ver.rc b/src/port/win32ver.rc
index 7b88d4b36f..5834b31ddc 100644
--- a/src/port/win32ver.rc
+++ b/src/port/win32ver.rc
@@ -4,8 +4,8 @@
 // https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION    13,0,0,0
- PRODUCTVERSION 13,0,0,0
+ FILEVERSION    PG_MAJORVERSION_NUM,0,PG_MINORVERSION_NUM,0
+ PRODUCTVERSION PG_MAJORVERSION_NUM,0,PG_MINORVERSION_NUM,0
  FILEFLAGSMASK  VS_FFI_FILEFLAGSMASK
  FILEFLAGS      0x0L
  FILEOS         VOS_NT_WINDOWS32
diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm
index 1a92ed233a..0eb8fd8b80 100644
--- a/src/tools/msvc/Install.pm
+++ b/src/tools/msvc/Install.pm
@@ -743,7 +743,7 @@ sub DetermineMajorVersion
 {
 	my $f = read_file('src/include/pg_config.h')
 	  || croak 'Could not open pg_config.h';
-	$f =~ /^#define\s+PG_MAJORVERSION\s+"([^"]+)"/m
+	$f =~ /^#define\s+PG_MAJORVERSION_NUM\s+(\d+)/m
 	  || croak 'Could not determine major version';
 	return $1;
 }
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 75f916399c..5ad054189a 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -19,7 +19,6 @@ sub _new
 	my $self      = {
 		projects                   => {},
 		options                    => $options,
-		numver                     => '',
 		VisualStudioVersion        => undef,
 		MinimumVisualStudioVersion => undef,
 		vcver                      => undef,
@@ -149,6 +148,7 @@ sub GenerateFiles
 	my $package_name;
 	my $package_version;
 	my $package_bugreport;
+	my ($majorver, $minorver);
 
 	# Parse configure.in to get version numbers
 	open(my $c, '<', "configure.in")
@@ -165,15 +165,14 @@ sub GenerateFiles
 			{
 				confess "Bad format of version: $self->{strver}\n";
 			}
-			$self->{numver} = sprintf("%d%04d", $1, $2 ? $2 : 0);
-			$self->{majorver} = sprintf("%d", $1);
+			$majorver = sprintf("%d", $1);
+			$minorver = sprintf("%d", $2 ? $2 : 0);
 		}
 	}
 	close($c);
 	confess "Unable to parse configure.in for all variables!"
 	  if ( $package_name eq ''
 		|| $package_version eq ''
-		|| $self->{numver} eq ''
 		|| $package_bugreport eq '');
 
 	if (IsNewer("src/include/pg_config_os.h", "src/include/port/win32.h"))
@@ -436,11 +435,12 @@ sub GenerateFiles
 		PG_INT128_TYPE      => undef,
 		PG_INT64_TYPE       => 'long long int',
 		PG_KRB_SRVNAM       => qq{"postgres"},
-		PG_MAJORVERSION     => qq{"$self->{majorver}"},
+		PG_MAJORVERSION_NUM => $majorver,
+		PG_MINORVERSION_NUM => $minorver,
 		PG_PRINTF_ATTRIBUTE => undef,
 		PG_USE_STDBOOL      => 1,
 		PG_VERSION          => qq{"$package_version$extraver"},
-		PG_VERSION_NUM      => $self->{numver},
+		PG_VERSION_NUM      => sprintf("%d%04d", $majorver, $minorver),
 		PG_VERSION_STR =>
 		  qq{"PostgreSQL $package_version$extraver, compiled by Visual C++ build " CppAsString2(_MSC_VER) ", $bits-bit"},
 		PROFILE_PID_DIR         => undef,
@@ -774,7 +774,7 @@ EOF
 		chdir('src/backend/catalog');
 		my $bki_srcs = join(' ../../../src/include/catalog/', @bki_srcs);
 		system(
-			"perl genbki.pl --include-path ../../../src/include/ --set-version=$self->{majorver} $bki_srcs"
+			"perl genbki.pl --include-path ../../../src/include/ --set-version=$majorver $bki_srcs"
 		);
 		open(my $f, '>', 'bki-stamp')
 		  || confess "Could not touch bki-stamp";
@@ -809,7 +809,7 @@ EOF
 	  || croak "Could not write to version.sgml\n";
 	print $o <<EOF;
 <!ENTITY version "$package_version">
-<!ENTITY majorversion "$self->{majorver}">
+<!ENTITY majorversion "$majorver">
 EOF
 	close($o);
 	return;
diff --git a/src/tools/version_stamp.pl b/src/tools/version_stamp.pl
index d8ab8d9de8..cb59ad234a 100755
--- a/src/tools/version_stamp.pl
+++ b/src/tools/version_stamp.pl
@@ -30,32 +30,27 @@
 my $minor = shift;
 defined($minor) || die "$0: missing required argument: minor-version\n";
 
-my ($dotneeded, $numericminor);
+my ($dotneeded);
 
 if ($minor =~ m/^\d+$/)
 {
 	$dotneeded    = 1;
-	$numericminor = $minor;
 }
 elsif ($minor eq "devel")
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^alpha\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^beta\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^rc\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 else
 {
@@ -73,8 +68,6 @@
 {
 	$fullversion = $majorversion . $minor;
 }
-my $numericversion = $majorversion . "." . $numericminor;
-my $padnumericversion = sprintf("%d%04d", $majorversion, $numericminor);
 
 # Get the autoconf version number for eventual nag message
 # (this also ensures we're in the right directory)
@@ -102,11 +95,6 @@
 	"-e 's/AC_INIT(\\[PostgreSQL\\], \\[[0-9a-z.]*\\]/AC_INIT([PostgreSQL], [$fullversion]/'"
 );
 
-sed_file("src/port/win32ver.rc",
-	"-e 's/FILEVERSION    [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION    $majorversion,0,$numericminor,0/' "
-	  . "-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $majorversion,0,$numericminor,0/'"
-);
-
 print "Stamped these files with version number $fullversion:\n$fixedfiles";
 print "Don't forget to run autoconf $aconfver before committing.\n";
 
-- 
2.25.0

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: Remove win32ver.rc from version_stamp.pl

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

This removes another relic from the old nmake-based Windows build.
version_stamp.pl put version number information into win32ver.rc. But
win32ver.rc already gets other version number information from the
preprocessor at build time, so it would make more sense if all version
number information would be handled in the same way and we don't have
two places that do it.

This has a minor conflict in Solution.pm according to the cfbot.

In general, while I'm on board with the idea, I wonder whether it
wouldn't be smarter to keep on defining PG_MAJORVERSION as a string,
and just add PG_MAJORVERSION_NUM alongside of it. This would
eliminate some hunks from the patch in places where it's more
convenient to have the version as a string, and it would avoid
what could otherwise be a pretty painful cross-version incompatibility
for extensions. We already provide PG_VERSION in both forms, so
I don't see any inconsistency in doing likewise for PG_MAJORVERSION.

regards, tom lane

#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#2)
1 attachment(s)
Re: Remove win32ver.rc from version_stamp.pl

On 2020-03-01 23:51, Tom Lane wrote:

In general, while I'm on board with the idea, I wonder whether it
wouldn't be smarter to keep on defining PG_MAJORVERSION as a string,
and just add PG_MAJORVERSION_NUM alongside of it. This would
eliminate some hunks from the patch in places where it's more
convenient to have the version as a string, and it would avoid
what could otherwise be a pretty painful cross-version incompatibility
for extensions. We already provide PG_VERSION in both forms, so
I don't see any inconsistency in doing likewise for PG_MAJORVERSION.

Agreed. Here is another patch.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Remove-win32ver.rc-from-version_stamp.pl.patchtext/plain; charset=UTF-8; name=v2-0001-Remove-win32ver.rc-from-version_stamp.pl.patch; x-mac-creator=0; x-mac-type=0Download
From 0770c6ef67b78208791e463f4453175e2d152750 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 9 Mar 2020 08:42:02 +0100
Subject: [PATCH v2] Remove win32ver.rc from version_stamp.pl

This removes another relic from the old nmake-based Windows build.
version_stamp.pl put version number information into win32ver.rc.  But
win32ver.rc already gets other version number information from the
preprocessor at build time, so it would make more sense if all version
number information would be handled in the same way and we don't have
two places that do it.

What we need for this is having the major version number and the minor
version number as separate integer symbols.  Both configure and
Solution.pm already have that logic, because they compute
PG_VERSION_NUM.  So we just keep all the logic there now.  Put the
minor version number into a new symbol PG_MINORVERSION_NUM.  Also, add
a symbol PG_MAJORVERSION_NUM, which is a number, alongside the
existing PG_MAJORVERSION, which is a string.

Discussion: https://www.postgresql.org/message-id/flat/1ee46ac4-a9b2-4531-bf54-5ec2e374634d@2ndquadrant.com
---
 configure                  | 15 +++++++++++++--
 configure.in               |  7 +++++--
 src/include/pg_config.h.in |  6 ++++++
 src/port/win32ver.rc       |  4 ++--
 src/tools/msvc/Solution.pm | 16 +++++++++-------
 src/tools/version_stamp.pl | 14 +-------------
 6 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/configure b/configure
index 45dbeb4d19..d6d3f26d03 100755
--- a/configure
+++ b/configure
@@ -2805,6 +2805,8 @@ _ACEOF
 
 
 PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`
+PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`
+test -n "$PG_MINORVERSION" || PG_MINORVERSION=0
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2812,6 +2814,16 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+cat >>confdefs.h <<_ACEOF
+#define PG_MAJORVERSION_NUM $PG_MAJORVERSION
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PG_MINORVERSION_NUM $PG_MINORVERSION
+_ACEOF
+
+
 
 
 
@@ -18875,8 +18887,7 @@ _ACEOF
 
 # Supply a numeric version string for use by 3rd party add-ons
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
-PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
-tr '.' '	' |
+PG_VERSION_NUM="`echo "$PG_MAJORVERSION	$PG_MINORVERSION" |
 $AWK '{printf "%d%04d", $1, $2}'`"
 
 cat >>confdefs.h <<_ACEOF
diff --git a/configure.in b/configure.in
index 22f096a5ac..78902fb60d 100644
--- a/configure.in
+++ b/configure.in
@@ -30,8 +30,12 @@ AC_PREFIX_DEFAULT(/usr/local/pgsql)
 AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["$ac_configure_args"], [Saved arguments from configure])
 
 [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`]
+[PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`]
+test -n "$PG_MINORVERSION" || PG_MINORVERSION=0
 AC_SUBST(PG_MAJORVERSION)
 AC_DEFINE_UNQUOTED(PG_MAJORVERSION, "$PG_MAJORVERSION", [PostgreSQL major version as a string])
+AC_DEFINE_UNQUOTED(PG_MAJORVERSION_NUM, $PG_MAJORVERSION, [PostgreSQL major version number])
+AC_DEFINE_UNQUOTED(PG_MINORVERSION_NUM, $PG_MINORVERSION, [PostgreSQL minor version number])
 
 PGAC_ARG_REQ(with, extra-version, [STRING], [append STRING to version],
              [PG_VERSION="$PACKAGE_VERSION$withval"],
@@ -2318,8 +2322,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
 
 # Supply a numeric version string for use by 3rd party add-ons
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
-[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
-tr '.' '	' |
+[PG_VERSION_NUM="`echo "$PG_MAJORVERSION	$PG_MINORVERSION" |
 $AWK '{printf "%d%04d", $1, $2}'`"]
 AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
 AC_SUBST(PG_VERSION_NUM)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d758dfd36e..41ad209380 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -780,6 +780,12 @@
 /* PostgreSQL major version as a string */
 #undef PG_MAJORVERSION
 
+/* PostgreSQL major version number */
+#undef PG_MAJORVERSION_NUM
+
+/* PostgreSQL minor version number */
+#undef PG_MINORVERSION_NUM
+
 /* Define to best printf format archetype, usually gnu_printf if available. */
 #undef PG_PRINTF_ATTRIBUTE
 
diff --git a/src/port/win32ver.rc b/src/port/win32ver.rc
index 7b88d4b36f..5834b31ddc 100644
--- a/src/port/win32ver.rc
+++ b/src/port/win32ver.rc
@@ -4,8 +4,8 @@
 // https://docs.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION    13,0,0,0
- PRODUCTVERSION 13,0,0,0
+ FILEVERSION    PG_MAJORVERSION_NUM,0,PG_MINORVERSION_NUM,0
+ PRODUCTVERSION PG_MAJORVERSION_NUM,0,PG_MINORVERSION_NUM,0
  FILEFLAGSMASK  VS_FFI_FILEFLAGSMASK
  FILEFLAGS      0x0L
  FILEOS         VOS_NT_WINDOWS32
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 4244a4a8ac..34d1f61dba 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -19,7 +19,6 @@ sub _new
 	my $self      = {
 		projects                   => {},
 		options                    => $options,
-		numver                     => '',
 		VisualStudioVersion        => undef,
 		MinimumVisualStudioVersion => undef,
 		vcver                      => undef,
@@ -151,6 +150,7 @@ sub GenerateFiles
 	my $package_version;
 	my $package_bugreport;
 	my $package_url;
+	my ($majorver, $minorver);
 
 	# Parse configure.in to get version numbers
 	open(my $c, '<', "configure.in")
@@ -171,8 +171,8 @@ sub GenerateFiles
 			{
 				confess "Bad format of version: $self->{strver}\n";
 			}
-			$self->{numver} = sprintf("%d%04d", $1, $2 ? $2 : 0);
-			$self->{majorver} = sprintf("%d", $1);
+			$majorver = sprintf("%d", $1);
+			$minorver = sprintf("%d", $2 ? $2 : 0);
 		}
 	}
 	close($c);
@@ -440,11 +440,13 @@ sub GenerateFiles
 		PG_INT128_TYPE      => undef,
 		PG_INT64_TYPE       => 'long long int',
 		PG_KRB_SRVNAM       => qq{"postgres"},
-		PG_MAJORVERSION     => qq{"$self->{majorver}"},
+		PG_MAJORVERSION     => qq{"$majorver"},
+		PG_MAJORVERSION_NUM => $majorver,
+		PG_MINORVERSION_NUM => $minorver,
 		PG_PRINTF_ATTRIBUTE => undef,
 		PG_USE_STDBOOL      => 1,
 		PG_VERSION          => qq{"$package_version$extraver"},
-		PG_VERSION_NUM      => $self->{numver},
+		PG_VERSION_NUM      => sprintf("%d%04d", $majorver, $minorver),
 		PG_VERSION_STR =>
 		  qq{"PostgreSQL $package_version$extraver, compiled by Visual C++ build " CppAsString2(_MSC_VER) ", $bits-bit"},
 		PROFILE_PID_DIR         => undef,
@@ -778,7 +780,7 @@ EOF
 		chdir('src/backend/catalog');
 		my $bki_srcs = join(' ../../../src/include/catalog/', @bki_srcs);
 		system(
-			"perl genbki.pl --include-path ../../../src/include/ --set-version=$self->{majorver} $bki_srcs"
+			"perl genbki.pl --include-path ../../../src/include/ --set-version=$majorver $bki_srcs"
 		);
 		open(my $f, '>', 'bki-stamp')
 		  || confess "Could not touch bki-stamp";
@@ -813,7 +815,7 @@ EOF
 	  || croak "Could not write to version.sgml\n";
 	print $o <<EOF;
 <!ENTITY version "$package_version">
-<!ENTITY majorversion "$self->{majorver}">
+<!ENTITY majorversion "$majorver">
 EOF
 	close($o);
 	return;
diff --git a/src/tools/version_stamp.pl b/src/tools/version_stamp.pl
index d8ab8d9de8..cb59ad234a 100755
--- a/src/tools/version_stamp.pl
+++ b/src/tools/version_stamp.pl
@@ -30,32 +30,27 @@
 my $minor = shift;
 defined($minor) || die "$0: missing required argument: minor-version\n";
 
-my ($dotneeded, $numericminor);
+my ($dotneeded);
 
 if ($minor =~ m/^\d+$/)
 {
 	$dotneeded    = 1;
-	$numericminor = $minor;
 }
 elsif ($minor eq "devel")
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^alpha\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^beta\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 elsif ($minor =~ m/^rc\d+$/)
 {
 	$dotneeded    = 0;
-	$numericminor = 0;
 }
 else
 {
@@ -73,8 +68,6 @@
 {
 	$fullversion = $majorversion . $minor;
 }
-my $numericversion = $majorversion . "." . $numericminor;
-my $padnumericversion = sprintf("%d%04d", $majorversion, $numericminor);
 
 # Get the autoconf version number for eventual nag message
 # (this also ensures we're in the right directory)
@@ -102,11 +95,6 @@
 	"-e 's/AC_INIT(\\[PostgreSQL\\], \\[[0-9a-z.]*\\]/AC_INIT([PostgreSQL], [$fullversion]/'"
 );
 
-sed_file("src/port/win32ver.rc",
-	"-e 's/FILEVERSION    [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION    $majorversion,0,$numericminor,0/' "
-	  . "-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $majorversion,0,$numericminor,0/'"
-);
-
 print "Stamped these files with version number $fullversion:\n$fixedfiles";
 print "Don't forget to run autoconf $aconfver before committing.\n";
 
-- 
2.25.0

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#3)
Re: Remove win32ver.rc from version_stamp.pl

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2020-03-01 23:51, Tom Lane wrote:

In general, while I'm on board with the idea, I wonder whether it
wouldn't be smarter to keep on defining PG_MAJORVERSION as a string,
and just add PG_MAJORVERSION_NUM alongside of it.

Agreed. Here is another patch.

This version LGTM. (I can't actually test the Windows aspects
of this, but I assume you did.)

I'm wondering a little bit whether it'd be worth back-patching the
additions of the new #defines. That would cut about five years off
the time till they could be relied on by extensions. However,
I'm not sure anyone is eager to rely on them, so it may not be
worth the effort.

regards, tom lane

#5Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#4)
Re: Remove win32ver.rc from version_stamp.pl

On 2020-03-09 15:55, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

On 2020-03-01 23:51, Tom Lane wrote:

In general, while I'm on board with the idea, I wonder whether it
wouldn't be smarter to keep on defining PG_MAJORVERSION as a string,
and just add PG_MAJORVERSION_NUM alongside of it.

Agreed. Here is another patch.

This version LGTM. (I can't actually test the Windows aspects
of this, but I assume you did.)

committed

I'm wondering a little bit whether it'd be worth back-patching the
additions of the new #defines. That would cut about five years off
the time till they could be relied on by extensions. However,
I'm not sure anyone is eager to rely on them, so it may not be
worth the effort.

I doubt external code really needs these symbols. You can always use
PG_VERSION_NUM.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services