1#! /usr/bin/perl
2
3#################################################################
4# version_stamp.pl -- update version stamps throughout the source tree
5#
6# Copyright (c) 2008-2020, PostgreSQL Global Development Group
7#
8# src/tools/version_stamp.pl
9#################################################################
10
11#
12# This script updates the version stamp in configure.in, and also in assorted
13# other files wherein it's not convenient to obtain the version number from
14# configure's output.  Note that you still have to run autoconf afterward
15# to regenerate configure from the updated configure.in.
16#
17# Usage: cd to top of source tree and issue
18#	src/tools/version_stamp.pl MINORVERSION
19# where MINORVERSION can be a minor release number (0, 1, etc), or
20# "devel", "alphaN", "betaN", "rcN".
21#
22
23use strict;
24use warnings;
25
26# Major version is hard-wired into the script.  We update it when we branch
27# a new development version.
28my $majorversion = 13;
29
30# Validate argument and compute derived variables
31my $minor = shift;
32defined($minor) || die "$0: missing required argument: minor-version\n";
33
34my ($dotneeded);
35
36if ($minor =~ m/^\d+$/)
37{
38	$dotneeded = 1;
39}
40elsif ($minor eq "devel")
41{
42	$dotneeded = 0;
43}
44elsif ($minor =~ m/^alpha\d+$/)
45{
46	$dotneeded = 0;
47}
48elsif ($minor =~ m/^beta\d+$/)
49{
50	$dotneeded = 0;
51}
52elsif ($minor =~ m/^rc\d+$/)
53{
54	$dotneeded = 0;
55}
56else
57{
58	die "$0: minor-version must be N, devel, alphaN, betaN, or rcN\n";
59}
60
61my $fullversion;
62
63# Create various required forms of the version number
64if ($dotneeded)
65{
66	$fullversion = $majorversion . "." . $minor;
67}
68else
69{
70	$fullversion = $majorversion . $minor;
71}
72
73# Get the autoconf version number for eventual nag message
74# (this also ensures we're in the right directory)
75
76my $aconfver = "";
77open(my $fh, '<', "configure.in") || die "could not read configure.in: $!\n";
78while (<$fh>)
79{
80	if (m/^m4_if\(m4_defn\(\[m4_PACKAGE_VERSION\]\), \[(.*)\], \[\], \[m4_fatal/
81	  )
82	{
83		$aconfver = $1;
84		last;
85	}
86}
87close($fh);
88$aconfver ne ""
89  || die "could not find autoconf version number in configure.in\n";
90
91# Update configure.in and other files that contain version numbers
92
93my $fixedfiles = "";
94
95sed_file("configure.in",
96	"-e 's/AC_INIT(\\[PostgreSQL\\], \\[[0-9a-z.]*\\]/AC_INIT([PostgreSQL], [$fullversion]/'"
97);
98
99print "Stamped these files with version number $fullversion:\n$fixedfiles";
100print "Don't forget to run autoconf $aconfver before committing.\n";
101
102exit 0;
103
104sub sed_file
105{
106	my ($filename, $sedargs) = @_;
107	my ($tmpfilename) = $filename . ".tmp";
108
109	system("sed $sedargs $filename >$tmpfilename") == 0
110	  or die "sed failed: $?";
111	system("mv $tmpfilename $filename") == 0
112	  or die "mv failed: $?";
113
114	$fixedfiles .= "\t$filename\n";
115	return;
116}
117