3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 # svn_client - Use svn client i.s.o. ugly internal SVN file hack
33 # format - A strftime() formatted string to use as a template for
34 # the version string. The sequence "%#" will substitute
35 # the SVN revision number.
36 # pkg_enable - Enable or disable local package versioning.
37 # pkg_format - Like "format", but used for the local package version.
39 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
40 # configure.in and the VERSION macro in config.nmake will have the
41 # pkg_format template appended to the version number. svnversion.h will
42 # _not_ be generated if either argument is present.
44 # Default configuration:
48 # format: SVN %Y%m%d%H%M%S
52 # XXX - We're pretty dumb about the "%#" substitution, and about having
53 # spaces in the package format.
58 use POSIX qw(strftime);
64 my $version_file = 'svnversion.h';
65 my $package_string = "";
66 my $vconf_file = 'version.conf';
67 my $tortoise_file = "tortoise_template";
70 my $repo_path = "unknown";
84 "format" => "SVN %Y%m%d%H%M%S",
87 # Normal development builds
89 "pkg_format" => "-SVN-%#",
91 # Development releases
96 my $svn_info_cmd = "";
98 $ENV{LANG} = "C"; # Ensure we run with correct locale
100 # Run "svn info". Parse out the most recent modification time and the
104 my $version_format = $version_pref{"format"};
105 my $package_format = "";
109 my $repo_root = undef;
110 my $repo_url = undef;
112 my $info_source = "Unknown";
114 if ($version_pref{"pkg_enable"}) {
115 $package_format = $version_pref{"pkg_format"};
118 if (-d "$srcdir/.svn") {
119 $info_source = "Command line (svn info)";
120 $svn_info_cmd = "svn info $srcdir";
121 } elsif (-d "$srcdir/.git/svn") {
122 $info_source = "Command line (git-svn)";
123 $svn_info_cmd = "(cd $srcdir; git svn info)";
126 if ($version_pref{"svn_client"}) {
130 $line = qx{$svn_info_cmd};
131 if (defined($line)) {
132 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
133 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
135 if ($line =~ /Last Changed Rev: (\d+)/) {
138 if ($line =~ /URL: (\S+)/) {
141 if ($line =~ /Repository Root: (\S+)/) {
148 if ($last_change && $revision && $repo_url && $repo_root) {
151 } elsif ($version_pref{"tortoise_svn"}) {
152 # Dynamically generic template file needed by TortoiseSVN
153 open(TORTOISE, ">$tortoise_file");
154 print TORTOISE "#define SVNVERSION \"\$WCREV\$\"\r\n";
155 print TORTOISE "#define SVNPATH \"\$WCURL\$\"\r\n";
158 $info_source = "Command line (SubWCRev)";
159 $svn_info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
160 my $tortoise = system($svn_info_cmd);
161 if ($tortoise == 0) {
165 #clean up the template file
166 unlink($tortoise_file);
169 if ($revision == 0) {
170 # Fall back to config.nmake
171 $info_source = "Prodding config.nmake";
172 my $filepath = "$srcdir/config.nmake";
173 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
174 while ($line = <CFGNMAKE>) {
175 if ($line =~ /^SVN_REVISION=(\d+)/) {
184 # 'svn info' failed or the user really wants us to dig around in .svn/entries
186 # Start of ugly internal SVN file hack
187 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
188 print ("Unable to open $srcdir/.svn/entries\n");
190 $info_source = "Prodding .svn";
191 # We need to find out whether our parser can handle the entries file
194 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
195 $repo_version = "pre1.4";
196 } elsif ($line =~ /^8$/) {
197 $repo_version = "1.4";
199 $repo_version = "unknown";
202 if ($repo_version eq "pre1.4") {
203 # The entries schema is flat, so we can use regexes to parse its contents.
204 while ($line = <ENTRIES>) {
205 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
210 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
211 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
212 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
214 if ($line =~ /revision="(\d+)"/) { $revision = $1; }
216 if ($line =~ /\/>/) {
217 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
218 $last_change && $revision) {
223 # XXX - Fetch the repository root & URL
230 # If we picked up the revision and modification time,
231 # generate our strings.
232 if ($revision && $last_change) {
233 $version_format =~ s/%#/$revision/;
234 $package_format =~ s/%#/$revision/;
235 $package_string = strftime($package_format, gmtime($last_change));
238 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
239 $repo_path = substr($repo_url, length($repo_root));
244 SVN revision : $revision
245 Revision source : $info_source
246 Release stamp : $package_string
252 # Read configure.in, then write it back out with an updated
254 sub update_configure_in
259 my $filepath = "$srcdir/configure.in";
261 return if (!$set_version && $package_string eq "");
263 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
264 while ($line = <CFGIN>) {
265 if ($line =~ /^AC_INIT\(wireshark, (\d+)\.(\d+).(\d+).*([\r\n]+)$/) {
266 $line = sprintf("AC_INIT\(wireshark, %d.%d.%d%s)$4",
267 $set_version ? $version_pref{"version_major"} : $1,
268 $set_version ? $version_pref{"version_minor"} : $2,
269 $set_version ? $version_pref{"version_micro"} : $3,
277 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
278 print(CFGIN $contents);
280 print "$filepath has been updated.\n";
283 # Read config.nmake, then write it back out with an updated
285 sub update_config_nmake
290 my $filepath = "$srcdir/config.nmake";
292 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
293 while ($line = <CFGNMAKE>) {
294 if ($line =~ /^SVN_REVISION=.*([\r\n]+)$/) {
295 $line = sprintf("SVN_REVISION=%d$1", $revision);
296 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
297 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
298 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
299 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
300 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
301 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
302 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
303 $line = "VERSION_EXTRA=$package_string$1";
308 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
309 print(CFGNMAKE $contents);
311 print "$filepath has been updated.\n";
314 # Read docbook/release_notes.xml, then write it back out with an updated
315 # "WiresharkCurrentVersion" line.
316 sub update_release_notes
321 my $filepath = "$srcdir/docbook/release-notes.xml";
323 return if (!$set_version);
325 open(RELNOTES, "< $filepath") || die "Can't read $filepath!";
326 while ($line = <RELNOTES>) {
327 # <!ENTITY WiresharkCurrentVersion "1.7.1">
329 if ($line =~ /<\!ENTITY\s+WiresharkCurrentVersion\s+.*([\r\n]+)$/) {
330 $line = sprintf("<!ENTITY WiresharkCurrentVersion \"%d.%d.%d\">$1",
331 $version_pref{"version_major"},
332 $version_pref{"version_minor"},
333 $version_pref{"version_micro"},
339 open(RELNOTES, "> $filepath") || die "Can't write $filepath!";
340 print(RELNOTES $contents);
342 print "$filepath has been updated.\n";
345 # Read debian/changelog, then write back out an updated version.
346 sub update_debian_changelog
351 my $filepath = "$srcdir/debian/changelog";
353 return if ($set_version == 0);
355 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
356 while ($line = <CHANGELOG>) {
357 if ($set_version && CHANGELOG->input_line_number() == 1) {
358 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
359 $version_pref{"version_major"},
360 $version_pref{"version_minor"},
361 $version_pref{"version_micro"},
367 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
368 print(CHANGELOG $contents);
370 print "$filepath has been updated.\n";
373 # Update distributed files that contain any version information
374 sub update_versioned_files
376 &update_configure_in;
377 &update_config_nmake;
378 &update_release_notes;
379 &update_debian_changelog;
382 # Print the SVN version to $version_file.
383 # Don't change the file if it is not needed.
384 sub print_svn_revision
387 my $needs_update = 1;
389 if ($last_change && $revision) {
390 $svn_revision = "#define SVNVERSION \"SVN Rev " .
392 "#define SVNPATH \"" . $repo_path . "\"\n";
394 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
395 "#define SVNPATH \"unknown\"\n";
397 if (open(OLDREV, "<$version_file")) {
398 my $old_svn_revision = <OLDREV> . <OLDREV>;
399 if ($old_svn_revision eq $svn_revision) {
405 if (! $set_svn) { return; }
408 # print "Updating $version_file so it contains:\n$svn_revision";
409 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
410 print VER "$svn_revision";
412 print "$version_file has been updated.\n";
414 print "$version_file unchanged.\n";
418 # Read values from the configuration file, if it exists.
423 # Get our command-line args
424 # XXX - Do we need an option to undo --set-release?
426 "help|h", \$show_help,
427 "get-svn|g", \$get_svn,
428 "set-svn|s", \$set_svn,
429 "set-version|v", \$set_version,
430 "set-release|r|package-version|p", \$set_release
433 if ($show_help) { pod2usage(1); }
435 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
443 if (! open(FILE, "<$vconf_file")) {
444 print STDERR "Version configuration file $vconf_file not "
445 . "found. Using defaults.\n";
452 next unless (/^(\w+)(:|=)\s*(\S.*)/);
453 $version_pref{$1} = $3;
469 if ($set_version || $set_release) {
471 print "Generating version information\n";
474 if ($version_pref{"enable"} == 0) {
475 print "Release information disabled in $vconf_file.\n";
480 print "Generating release information\n";
482 print "Resetting release information\n";
484 $package_string = "";
487 &update_versioned_files;
494 make-version.pl - Get and set build-time version information for Wireshark
498 make-version.pl [options] [source directory]
502 --help, -h This help message
503 --get-svn, -g Print the SVN revision and source.
504 --set-svn, -s Set the information in svnversion.h
505 --set-version, -v Set the major, minor, and micro versions in
506 configure.in, config.nmake, debian/changelog,
507 and docbook/release_notes.xml.
508 Resets the release information when used by
510 --set-release, -r Set the release information in configure.in
512 --package-version, -p Deprecated. Same as --set-release.
514 Options can be used in any combination. If none are specified B<--set-svn>