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 # Read debian/wireshark-common.files, then write back out an updated version.
374 # The libraries updated here MUST match the updates made by update_lib_releases
375 # below. We should do this automatically.
376 sub update_debian_wcf
381 my $filepath = "$srcdir/debian/wireshark-common.files";
383 return if (!$set_version);
385 open(DWCF, "< $filepath") || die "Can't read $filepath!";
386 while ($line = <DWCF>) {
387 # /usr/lib/wireshark/libwireshark.so.1.1.0
389 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap).so\.\d+\.\d+\.)\d+$}) {
390 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
395 open(DWCF, "> $filepath") || die "Can't write $filepath!";
396 print(DWCF $contents);
398 print "$filepath has been updated.\n";
401 # Read Makefile.am for each library, then write back out an updated version.
402 sub update_lib_releases
410 return if (!$set_version);
412 # The Libtool manual says
413 # "If the library source code has changed at all since the last
414 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
415 # epan changes with each minor release, almost by definition. wiretap
416 # changes with *most* releases.
418 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
419 for $filedir ("epan", "wiretap") { # "wsutil"
421 $filepath = $filedir . "/Makefile.am";
422 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
423 while ($line = <MAKEFILE_AM>) {
424 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
426 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
427 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
432 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
433 print(MAKEFILE_AM $contents);
435 print "$filepath has been updated.\n";
439 # Update distributed files that contain any version information
440 sub update_versioned_files
442 &update_configure_in;
443 &update_config_nmake;
444 &update_release_notes;
445 &update_debian_changelog;
447 &update_lib_releases;
450 # Print the SVN version to $version_file.
451 # Don't change the file if it is not needed.
452 sub print_svn_revision
455 my $needs_update = 1;
457 if ($last_change && $revision) {
458 $svn_revision = "#define SVNVERSION \"SVN Rev " .
460 "#define SVNPATH \"" . $repo_path . "\"\n";
462 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
463 "#define SVNPATH \"unknown\"\n";
465 if (open(OLDREV, "<$version_file")) {
466 my $old_svn_revision = <OLDREV> . <OLDREV>;
467 if ($old_svn_revision eq $svn_revision) {
473 if (! $set_svn) { return; }
476 # print "Updating $version_file so it contains:\n$svn_revision";
477 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
478 print VER "$svn_revision";
480 print "$version_file has been updated.\n";
482 print "$version_file unchanged.\n";
486 # Read values from the configuration file, if it exists.
491 # Get our command-line args
492 # XXX - Do we need an option to undo --set-release?
494 "help|h", \$show_help,
495 "get-svn|g", \$get_svn,
496 "set-svn|s", \$set_svn,
497 "set-version|v", \$set_version,
498 "set-release|r|package-version|p", \$set_release
501 if ($show_help) { pod2usage(1); }
503 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
511 if (! open(FILE, "<$vconf_file")) {
512 print STDERR "Version configuration file $vconf_file not "
513 . "found. Using defaults.\n";
520 next unless (/^(\w+)(:|=)\s*(\S.*)/);
521 $version_pref{$1} = $3;
537 if ($set_version || $set_release) {
539 print "Generating version information\n";
542 if ($version_pref{"enable"} == 0) {
543 print "Release information disabled in $vconf_file.\n";
548 print "Generating release information\n";
550 print "Resetting release information\n";
552 $package_string = "";
555 &update_versioned_files;
562 make-version.pl - Get and set build-time version information for Wireshark
566 make-version.pl [options] [source directory]
570 --help, -h This help message
571 --get-svn, -g Print the SVN revision and source.
572 --set-svn, -s Set the information in svnversion.h
573 --set-version, -v Set the major, minor, and micro versions in
574 configure.in, config.nmake, debian/changelog,
575 and docbook/release_notes.xml.
576 Resets the release information when used by
578 --set-release, -r Set the release information in configure.in
580 --package-version, -p Deprecated. Same as --set-release.
582 Options can be used in any combination. If none are specified B<--set-svn>