1#! /usr/bin/perl -w
2
3#################################################################
4# version_stamp.pl -- update version stamps throughout the source tree
5#
6# Copyright (c) 2008-2017, 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;
24
25# Major version is hard-wired into the script.  We update it when we branch
26# a new development version.
27my $majorversion = 10;
28
29# Validate argument and compute derived variables
30my $minor = shift;
31defined($minor) || die "$0: missing required argument: minor-version\n";
32
33my ($dotneeded, $numericminor);
34
35if ($minor =~ m/^\d+$/)
36{
37	$dotneeded    = 1;
38	$numericminor = $minor;
39}
40elsif ($minor eq "devel")
41{
42	$dotneeded    = 0;
43	$numericminor = 0;
44}
45elsif ($minor =~ m/^alpha\d+$/)
46{
47	$dotneeded    = 0;
48	$numericminor = 0;
49}
50elsif ($minor =~ m/^beta\d+$/)
51{
52	$dotneeded    = 0;
53	$numericminor = 0;
54}
55elsif ($minor =~ m/^rc\d+$/)
56{
57	$dotneeded    = 0;
58	$numericminor = 0;
59}
60else
61{
62	die "$0: minor-version must be N, devel, alphaN, betaN, or rcN\n";
63}
64
65my $fullversion;
66
67# Create various required forms of the version number
68if ($dotneeded)
69{
70	$fullversion = $majorversion . "." . $minor;
71}
72else
73{
74	$fullversion = $majorversion . $minor;
75}
76my $numericversion = $majorversion . "." . $numericminor;
77my $padnumericversion = sprintf("%d%04d", $majorversion, $numericminor);
78
79# Get the autoconf version number for eventual nag message
80# (this also ensures we're in the right directory)
81
82my $aconfver = "";
83open(my $fh, '<', "configure.in") || die "could not read configure.in: $!\n";
84while (<$fh>)
85{
86	if (
87m/^m4_if\(m4_defn\(\[m4_PACKAGE_VERSION\]\), \[(.*)\], \[\], \[m4_fatal/)
88	{
89		$aconfver = $1;
90		last;
91	}
92}
93close($fh);
94$aconfver ne ""
95  || die "could not find autoconf version number in configure.in\n";
96
97# Update configure.in and other files that contain version numbers
98
99my $fixedfiles = "";
100
101sed_file("configure.in",
102"-e 's/AC_INIT(\\[PostgreSQL\\], \\[[0-9a-z.]*\\]/AC_INIT([PostgreSQL], [$fullversion]/'"
103);
104
105sed_file("doc/bug.template",
106"-e 's/PostgreSQL version (example: PostgreSQL .*) *:  PostgreSQL .*/PostgreSQL version (example: PostgreSQL $fullversion):  PostgreSQL $fullversion/'"
107);
108
109sed_file("src/include/pg_config.h.win32",
110"-e 's/#define PACKAGE_STRING \"PostgreSQL .*\"/#define PACKAGE_STRING \"PostgreSQL $fullversion\"/' "
111	  . "-e 's/#define PACKAGE_VERSION \".*\"/#define PACKAGE_VERSION \"$fullversion\"/' "
112	  . "-e 's/#define PG_VERSION \".*\"/#define PG_VERSION \"$fullversion\"/' "
113	  . "-e 's/#define PG_VERSION_NUM .*/#define PG_VERSION_NUM $padnumericversion/'"
114);
115
116sed_file("src/interfaces/libpq/libpq.rc.in",
117"-e 's/FILEVERSION [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION $majorversion,0,$numericminor,0/' "
118	  . "-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $majorversion,0,$numericminor,0/' "
119	  . "-e 's/VALUE \"FileVersion\", \"[0-9.]*/VALUE \"FileVersion\", \"$numericversion/' "
120	  . "-e 's/VALUE \"ProductVersion\", \"[0-9.]*/VALUE \"ProductVersion\", \"$numericversion/'"
121);
122
123sed_file("src/port/win32ver.rc",
124"-e 's/FILEVERSION    [0-9]*,[0-9]*,[0-9]*,0/FILEVERSION    $majorversion,0,$numericminor,0/' "
125	  . "-e 's/PRODUCTVERSION [0-9]*,[0-9]*,[0-9]*,0/PRODUCTVERSION $majorversion,0,$numericminor,0/'"
126);
127
128print "Stamped these files with version number $fullversion:\n$fixedfiles";
129print "Don't forget to run autoconf $aconfver before committing.\n";
130
131exit 0;
132
133sub sed_file
134{
135	my ($filename, $sedargs) = @_;
136	my ($tmpfilename) = $filename . ".tmp";
137
138	system("sed $sedargs $filename >$tmpfilename") == 0
139	  or die "sed failed: $?";
140	system("mv $tmpfilename $filename") == 0
141	  or die "mv failed: $?";
142
143	$fixedfiles .= "\t$filename\n";
144}
145