3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
7 # Ethereal - Network traffic analyzer
8 # By Gerald Combs <gerald@ethereal.com>
9 # Copyright 1998 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # usage: ./make-version.pl
27 # If "version.conf" is present, it is parsed for configuration values.
28 # Possible values are:
30 # enable - Enable or disable versioning. Zero (0) disables, nonzero
32 # format - A strftime() formatted string to use as a template for the
35 # Default configuration:
38 # format: SVN %Y%m%d%H%M%S
43 use POSIX qw(strftime);
45 my $version_file = 'svnversion.h';
46 my $vconf_file = 'version.conf';
48 my %version_pref = ("enable" => 1, "format" => "SVN %Y%m%d%H%M%S");
51 # Recursively find all SVN Entries files starting from the given directory,
52 # and compute the modification time of the most recently modified Entries file.
56 open(SVNINFO, "svn info |") || return;
57 while ($line = <SVNINFO>) {
58 if ($line =~ /^Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
59 $last = timegm($6, $5, $4, $3, $2 - 1, $1);
66 # Print the SVN version to $version_file.
67 # Don't change the file if it is not needed.
74 $svn_version = "#define SVNVERSION \"" .
75 strftime($version_pref{"format"}, gmtime($last)) .
78 $svn_version = "/* #define SVNVERSION \"\" */\n";
80 if (open(OLDVER, "<$version_file")) {
81 if (<OLDVER> eq $svn_version) {
82 print "$version_file is up-to-date.\n";
88 if ($needs_update == 1) {
89 # print "Updating $version_file so it contains:\n$svn_version";
90 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
91 print VER "$svn_version";
93 print "$version_file has been updated.\n";
97 # Read values from the configuration file, if it exists.
99 open(FILE, "<$vconf_file") || print STDERR "Version configuration file $vconf_file not found. Using defaults.\n" && return 1;
104 next unless (/^(\w+):\s+(\S.*)/);
105 $version_pref{$1} = $2;
117 if ($version_pref{"enable"} == 0) {
118 print "Version tag disabled in $vconf_file.\n";
119 } elsif (-d "./.svn") {
120 print "This is a build from SVN (or a SVN snapshot), "
121 . "SVN version tag will be computed.\n";
124 print "This is not a SVN build.\n";
127 # Now that we've computed everything, print the SVN version to $version_file