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 package versioning.
37 # pkg_format - Like "format", but used for the package version.
39 # If run with the "-p" or "--package-version" argument, the
40 # AC_INIT macro in configure.in and the VERSION macro in
41 # config.nmake will have the pkg_format template appended to the
42 # version number. svnversion.h will _not_ be generated if either
43 # argument is present (it will also not be generated if 'is_release' is set
46 # Default configuration:
50 # format: SVN %Y%m%d%H%M%S
54 # XXX - We're pretty dumb about the "%#" substitution, and about having
55 # spaces in the package format.
60 use POSIX qw(strftime);
66 my $version_file = 'svnversion.h';
67 my $package_string = "";
68 my $vconf_file = 'version.conf';
69 my $tortoise_file = "tortoise_template";
72 my $repo_path = "unknown";
85 "format" => "SVN %Y%m%d%H%M%S",
88 # Normal development builds
90 "pkg_format" => "-SVN-%#",
92 # Development releases
97 my $svn_info_cmd = "";
99 $ENV{LANG} = "C"; # Ensure we run with correct locale
101 # Run "svn info". Parse out the most recent modification time and the
105 my $version_format = $version_pref{"format"};
106 my $package_format = "";
110 my $repo_root = undef;
111 my $repo_url = undef;
113 my $info_source = "Unknown";
115 if ($version_pref{"pkg_enable"}) {
116 $package_format = $version_pref{"pkg_format"};
119 if (-d "$srcdir/.svn") {
120 $info_source = "Command line (svn info)";
121 $svn_info_cmd = "svn info $srcdir";
122 } elsif (-d "$srcdir/.git/svn") {
123 $info_source = "Command line (git-svn)";
124 $svn_info_cmd = "(cd $srcdir; git svn info)";
127 if ($version_pref{"svn_client"}) {
131 $line = qx{$svn_info_cmd};
132 if (defined($line)) {
133 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
134 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
136 if ($line =~ /Last Changed Rev: (\d+)/) {
139 if ($line =~ /URL: (\S+)/) {
142 if ($line =~ /Repository Root: (\S+)/) {
149 if ($last_change && $revision && $repo_url && $repo_root) {
152 } elsif ($version_pref{"tortoise_svn"}) {
153 # Dynamically generic template file needed by TortoiseSVN
154 open(TORTOISE, ">$tortoise_file");
155 print TORTOISE "#define SVNVERSION \"\$WCREV\$\"\r\n";
156 print TORTOISE "#define SVNPATH \"\$WCURL\$\"\r\n";
159 $info_source = "Command line (SubWCRev)";
160 $svn_info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
161 my $tortoise = system($svn_info_cmd);
162 if ($tortoise == 0) {
166 #clean up the template file
167 unlink($tortoise_file);
170 if ($revision == 0) {
171 # Fall back to config.nmake
172 $info_source = "Prodding config.nmake";
173 my $filepath = "config.nmake";
174 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
175 while ($line = <CFGNMAKE>) {
176 if ($line =~ /^SVN_REVISION=(\d+)/) {
185 # 'svn info' failed or the user really wants us to dig around in .svn/entries
187 # Start of ugly internal SVN file hack
188 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
189 print ("Unable to open $srcdir/.svn/entries\n");
191 $info_source = "Prodding .svn";
192 # We need to find out whether our parser can handle the entries file
195 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
196 $repo_version = "pre1.4";
197 } elsif ($line =~ /^8$/) {
198 $repo_version = "1.4";
200 $repo_version = "unknown";
203 if ($repo_version eq "pre1.4") {
204 # The entries schema is flat, so we can use regexes to parse its contents.
205 while ($line = <ENTRIES>) {
206 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
211 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
212 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
213 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
215 if ($line =~ /revision="(\d+)"/) { $revision = $1; }
217 if ($line =~ /\/>/) {
218 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
219 $last_change && $revision) {
224 # XXX - Fetch the repository root & URL
231 # If we picked up the revision and modification time,
232 # generate our strings.
233 if ($revision && $last_change) {
234 $version_format =~ s/%#/$revision/;
235 $package_format =~ s/%#/$revision/;
236 $package_string = strftime($package_format, gmtime($last_change));
239 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
240 $repo_path = substr($repo_url, length($repo_root));
245 SVN revision : $revision
246 Revision source : $info_source
247 Release stamp : $package_string
253 # Read configure.in, then write it back out with an updated
255 sub update_configure_in
260 my $filepath = "configure.in";
262 return if (!$set_version && $package_string eq "");
264 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
265 while ($line = <CFGIN>) {
266 if ($line =~ /^AC_INIT\(wireshark, (\d+)\.(\d+).(\d+)/) {
267 $line = sprintf("AC_INIT\(wireshark, %d.%d.%d%s)\n",
268 $set_version ? $version_pref{"version_major"} : $1,
269 $set_version ? $version_pref{"version_minor"} : $2,
270 $set_version ? $version_pref{"version_micro"} : $3,
271 $set_release ? $package_string : ""
278 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
279 print(CFGIN $contents);
281 print "$filepath has been updated.\n";
284 # Read config.nmake, then write it back out with an updated
286 sub update_config_nmake
291 my $filepath = "config.nmake";
293 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
294 while ($line = <CFGNMAKE>) {
295 if ($line =~ /^SVN_REVISION=/) {
296 $line = sprintf("SVN_REVISION=%d\n", $revision);
297 } elsif ($set_version && $line =~ /^VERSION_MAJOR=/) {
298 $line = sprintf("VERSION_MAJOR=%d\n", $version_pref{"version_major"});
299 } elsif ($set_version && $line =~ /^VERSION_MINOR=/) {
300 $line = sprintf("VERSION_MINOR=%d\n", $version_pref{"version_minor"});
301 } elsif ($set_version && $line =~ /^VERSION_MICRO=/) {
302 $line = sprintf("VERSION_MICRO=%d\n", $version_pref{"version_micro"});
303 } elsif ($line =~ /^VERSION_EXTRA=/) {
304 $line = "VERSION_EXTRA=$package_string\n";
309 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
310 print(CFGNMAKE $contents);
312 print "$filepath has been updated.\n";
315 # Read docbook/release_notes.xml, then write it back out with an updated
316 # "WiresharkCurrentVersion" line.
317 sub update_release_notes
322 my $filepath = "docbook/release-notes.xml";
324 return if (!$set_version);
326 open(RELNOTES, "< $filepath") || die "Can't read $filepath!";
327 while ($line = <RELNOTES>) {
328 # <!ENTITY WiresharkCurrentVersion "1.7.1">
330 if ($line =~ /<\!ENTITY\s+WiresharkCurrentVersion\s+/) {
331 $line = sprintf("<!ENTITY WiresharkCurrentVersion \"%d.%d.%d\">\n",
332 $version_pref{"version_major"},
333 $version_pref{"version_minor"},
334 $version_pref{"version_micro"},
340 open(RELNOTES, "> $filepath") || die "Can't write $filepath!";
341 print(RELNOTES $contents);
343 print "$filepath has been updated.\n";
346 # Read debian/changelog, then write back out an updated version.
347 sub update_debian_changelog
352 my $filepath = "debian/changelog";
354 return if ($set_version == 0);
356 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
357 while ($line = <CHANGELOG>) {
358 if ($set_version && CHANGELOG->input_line_number() == 1) {
359 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
360 $version_pref{"version_major"},
361 $version_pref{"version_minor"},
362 $version_pref{"version_micro"},
368 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
369 print(CHANGELOG $contents);
371 print "$filepath has been updated.\n";
374 # Update distributed files that contain any version information
375 sub update_versioned_files
377 &update_configure_in;
378 &update_config_nmake;
379 &update_release_notes;
380 &update_debian_changelog;
383 # Print the SVN version to $version_file.
384 # Don't change the file if it is not needed.
385 sub print_svn_revision
388 my $needs_update = 1;
390 if ($last_change && $revision) {
391 $svn_revision = "#define SVNVERSION \"SVN Rev " .
393 "#define SVNPATH \"" . $repo_path . "\"\n";
395 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
396 "#define SVNPATH \"unknown\"\n";
398 if (open(OLDREV, "<$version_file")) {
399 my $old_svn_revision = <OLDREV> . <OLDREV>;
400 if ($old_svn_revision eq $svn_revision) {
406 if (! $set_version && ! $set_release) { return; }
409 # print "Updating $version_file so it contains:\n$svn_revision";
410 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
411 print VER "$svn_revision";
413 print "$version_file has been updated.\n";
415 print "$version_file unchanged.\n";
419 # Read values from the configuration file, if it exists.
424 # Get our command-line args
426 "help|h", \$show_help,
427 "get-svn|g", \$get_svn,
428 "set-version|v", \$set_version,
429 "set-release|r|package-version|p", \$set_release
432 if ($show_help) { pod2usage(1); }
434 if ( !( $show_help || $get_svn || $set_release ) ) {
442 if (! open(FILE, "<$vconf_file")) {
443 print STDERR "Version configuration file $vconf_file not "
444 . "found. Using defaults.\n";
451 next unless (/^(\w+)(:|=)\s*(\S.*)/);
452 $version_pref{$1} = $3;
468 if ($set_version || $set_release) {
470 print "Generating version information\n";
473 if ($version_pref{"enable"} == 0) {
474 print "Release information disabled in $vconf_file.\n";
479 print "Generating release information\n";
482 &update_versioned_files;
489 make-version.pl - Get and set build-time version information for Wireshark
493 make-version.pl [options] [source directory]
497 --help, -h This help message
498 --get-svn, -g Print the SVN revision and source.
499 --set-version, -v Set the major, minor, and micro versions.
500 Resets the release information when used by
502 --set-release, -r Set the release information.
503 --package-version, -p Deprecated. Same as --set-release.
505 Options can be used in any combination. If none are specified B<--set-version>