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.ac 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.
59 use POSIX qw(strftime);
65 my $version_file = 'svnversion.h';
66 my $package_string = "";
67 my $vconf_file = 'version.conf';
68 my $tortoise_file = "tortoise_template";
71 my $repo_path = "unknown";
72 my $git_description = undef;
79 "version_minor" => 11,
87 "format" => "SVN %Y%m%d%H%M%S",
90 # Normal development builds
92 "pkg_format" => "-SVN-%#",
94 # Development releases
101 # Ensure we run with correct locale
104 $ENV{GIT_PAGER} = "";
106 # Run "svn info". Parse out the most recent modification time and the
110 my $version_format = $version_pref{"format"};
111 my $package_format = "";
115 my $repo_root = undef;
116 my $repo_url = undef;
118 my $info_source = "Unknown";
120 if ($version_pref{"pkg_enable"}) {
121 $package_format = $version_pref{"pkg_format"};
124 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
125 $info_source = "Command line (git)";
126 $version_pref{"git_client"} = 1;
127 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
128 $info_source = "Command line (svn info)";
129 $info_cmd = "svn info $srcdir";
130 } elsif (-d "$srcdir/.git/svn") {
131 $info_source = "Command line (git-svn)";
132 $info_cmd = "(cd $srcdir; git svn info)";
137 # A big ugly hash: git rev-parse HEAD
138 # 1ddc83849075addb0cac69a6fe3782f4325337b9
140 # A small ugly hash: git rev-parse --short HEAD
143 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
146 # A version description: git describe --tags --dirty
147 # wireshark-1.8.12-15-g1ddc838
149 # Number of commits in this branch: git rev-list --count HEAD
152 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
155 # Refs: git ls-remote code.wireshark.org:wireshark
156 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
158 if ($version_pref{"git_client"}) {
163 chomp($line = qx{git log -1 --pretty=format:%at});
164 if (defined($line)) {
165 $last_change = $line;
168 # Commits in current (master-1.8) branch. We may want to use
169 # a different number.
170 chomp($line = qx{git rev-list --count ea19c7f952ce9fc53fe4c223f1d9d6797346258b..HEAD});
171 if (defined($line)) {
175 chomp($line = qx{git ls-remote --get-url origin});
176 if (defined($line)) {
180 # Probably not quite what we're looking for
181 chomp($line = qx{git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
182 if (defined($line)) {
183 $repo_path = basename($line);
187 # XXX After the SVN->git migration we'll create tags for 1.11.x.
188 # Until then we'll fake it.
189 #chomp($line = qx{git describe --tags --dirty});
190 chomp($line = qx{git rev-parse --short HEAD});
191 if (defined($line)) {
192 #$git_description = $line;
193 $git_description = "wireshark-1.11." . $version_pref{"version_minor"} .
200 if ($last_change && $revision && $repo_url && $repo_path) {
203 } elsif ($version_pref{"svn_client"}) {
207 $line = qx{$info_cmd};
208 if (defined($line)) {
209 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
210 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
212 if ($line =~ /Last Changed Rev: (\d+)/) {
215 if ($line =~ /URL: (\S+)/) {
218 if ($line =~ /Repository Root: (\S+)/) {
225 if ($last_change && $revision && $repo_url && $repo_root) {
228 } elsif ($version_pref{"tortoise_svn"}) {
229 # Dynamically generic template file needed by TortoiseSVN
230 open(TORTOISE, ">$tortoise_file");
231 print TORTOISE "#define SVNVERSION \"\$WCREV\$\"\r\n";
232 print TORTOISE "#define SVNPATH \"\$WCURL\$\"\r\n";
235 $info_source = "Command line (SubWCRev)";
236 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
237 my $tortoise = system($info_cmd);
238 if ($tortoise == 0) {
242 #clean up the template file
243 unlink($tortoise_file);
246 if ($revision == 0) {
247 # Fall back to config.nmake
248 $info_source = "Prodding config.nmake";
249 my $filepath = "$srcdir/config.nmake";
250 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
251 while ($line = <CFGNMAKE>) {
252 if ($line =~ /^SVN_REVISION=(\d+)/) {
260 if ($revision == 0 and -d "$srcdir/.git") {
266 # If someone had properly tagged 1.9.0 we could also use
267 # "git describe --abbrev=1 --tags HEAD"
269 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
270 $line = qx{$info_cmd};
271 if (defined($line)) {
272 if ($line =~ /svn path=.*; revision=(\d+)/) {
276 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
277 $line = qx{$info_cmd};
278 if (defined($line)) {
279 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
280 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
283 $info_cmd = "(cd $srcdir; git branch)";
284 $line = qx{$info_cmd};
285 if (defined($line)) {
286 if ($line =~ /\* (\S+)/) {
293 if ($revision == 0 and -d "$srcdir/.bzr") {
299 $info_cmd = "(cd $srcdir; bzr log -l 1)";
300 $line = qx{$info_cmd};
301 if (defined($line)) {
302 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
303 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
305 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
315 # 'svn info' failed or the user really wants us to dig around in .svn/entries
317 # Start of ugly internal SVN file hack
318 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
319 print ("Unable to open $srcdir/.svn/entries\n");
321 $info_source = "Prodding .svn";
322 # We need to find out whether our parser can handle the entries file
325 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
326 $repo_version = "pre1.4";
327 } elsif ($line =~ /^8$/) {
328 $repo_version = "1.4";
330 $repo_version = "unknown";
333 if ($repo_version eq "pre1.4") {
334 # The entries schema is flat, so we can use regexes to parse its contents.
335 while ($line = <ENTRIES>) {
336 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
341 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
342 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
343 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
345 if ($line =~ /revision="(\d+)"/) { $revision = $1; }
347 if ($line =~ /\/>/) {
348 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
349 $last_change && $revision) {
354 # XXX - Fetch the repository root & URL
361 # If we picked up the revision and modification time,
362 # generate our strings.
363 if ($revision && $last_change) {
364 $version_format =~ s/%#/$revision/;
365 $package_format =~ s/%#/$revision/;
366 $package_string = strftime($package_format, gmtime($last_change));
369 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
370 $repo_path = substr($repo_url, length($repo_root));
375 SVN revision : $revision
376 Revision source : $info_source
377 Release stamp : $package_string
383 # Read configure.ac, then write it back out with an updated
385 sub update_configure_ac
390 my $filepath = "$srcdir/configure.ac";
392 return if (!$set_version && $package_string eq "");
394 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
395 while ($line = <CFGIN>) {
396 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
397 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
398 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
399 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
400 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
401 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
402 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
403 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
408 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
409 print(CFGIN $contents);
411 print "$filepath has been updated.\n";
414 # Read config.nmake, then write it back out with an updated
416 sub update_config_nmake
421 my $filepath = "$srcdir/config.nmake";
423 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
424 while ($line = <CFGNMAKE>) {
425 if ($line =~ /^SVN_REVISION=.*([\r\n]+)$/) {
426 $line = sprintf("SVN_REVISION=%d$1", $revision);
427 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
428 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
429 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
430 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
431 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
432 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
433 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
434 $line = "VERSION_EXTRA=$package_string$1";
439 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
440 print(CFGNMAKE $contents);
442 print "$filepath has been updated.\n";
445 # Read docbook/asciidoc.conf, then write it back out with an updated
446 # wireshark-version replacement line.
447 sub update_release_notes
452 my $filepath = "$srcdir/docbook/asciidoc.conf";
454 return if (!$set_version);
456 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
457 while ($line = <ADOC_CONF>) {
458 # wireshark-version:\[\]=1.9.1
460 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
461 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
462 $version_pref{"version_major"},
463 $version_pref{"version_minor"},
464 $version_pref{"version_micro"},
470 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
471 print(ADOC_CONF $contents);
473 print "$filepath has been updated.\n";
476 # Read debian/changelog, then write back out an updated version.
477 sub update_debian_changelog
482 my $filepath = "$srcdir/debian/changelog";
484 return if ($set_version == 0);
486 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
487 while ($line = <CHANGELOG>) {
488 if ($set_version && CHANGELOG->input_line_number() == 1) {
489 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
490 $version_pref{"version_major"},
491 $version_pref{"version_minor"},
492 $version_pref{"version_micro"},
498 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
499 print(CHANGELOG $contents);
501 print "$filepath has been updated.\n";
504 # Read debian/wireshark-common.files, then write back out an updated version.
505 # The libraries updated here MUST match the updates made by update_lib_releases
506 # below. We should do this automatically.
507 sub update_debian_wcf
512 my $filepath = "$srcdir/debian/wireshark-common.files";
514 return if (!$set_version);
516 open(DWCF, "< $filepath") || die "Can't read $filepath!";
517 while ($line = <DWCF>) {
518 # /usr/lib/wireshark/libwireshark.so.1.1.0
520 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap|filetap).so\.\d+\.\d+\.)\d+$}) {
521 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
526 open(DWCF, "> $filepath") || die "Can't write $filepath!";
527 print(DWCF $contents);
529 print "$filepath has been updated.\n";
532 # Read Makefile.am for each library, then write back out an updated version.
533 sub update_lib_releases
541 return if (!$set_version);
543 # The Libtool manual says
544 # "If the library source code has changed at all since the last
545 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
546 # epan changes with each minor release, almost by definition. wiretap
547 # and filetap changes with *most* releases.
549 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
550 for $filedir ("epan", "wiretap", "filetap") { # "wsutil"
552 $filepath = $filedir . "/Makefile.am";
553 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
554 while ($line = <MAKEFILE_AM>) {
555 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
557 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
558 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
563 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
564 print(MAKEFILE_AM $contents);
566 print "$filepath has been updated.\n";
570 # Update distributed files that contain any version information
571 sub update_versioned_files
573 &update_configure_ac;
574 &update_config_nmake;
575 &update_release_notes;
576 &update_debian_changelog;
578 &update_lib_releases;
581 # Print the SVN version to $version_file.
582 # Don't change the file if it is not needed.
583 sub print_svn_revision
586 my $needs_update = 1;
588 if ($git_description) {
589 $svn_revision = "#define SVNVERSION \"" .
590 $git_description . "\"\n" .
591 "#define SVNPATH \"" . $repo_path . "\"\n";
592 } elsif ($last_change && $revision) {
593 $svn_revision = "#define SVNVERSION \"SVN Rev " .
595 "#define SVNPATH \"" . $repo_path . "\"\n";
597 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
598 "#define SVNPATH \"unknown\"\n";
600 if (open(OLDREV, "<$version_file")) {
601 my $old_svn_revision = <OLDREV> . <OLDREV>;
602 if ($old_svn_revision eq $svn_revision) {
608 if (! $set_svn) { return; }
611 # print "Updating $version_file so it contains:\n$svn_revision";
612 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
613 print VER "$svn_revision";
615 print "$version_file has been updated.\n";
617 print "$version_file unchanged.\n";
621 # Read values from the configuration file, if it exists.
626 # Get our command-line args
627 # XXX - Do we need an option to undo --set-release?
629 "help|h", \$show_help,
630 "get-svn|g", \$get_svn,
631 "set-svn|s", \$set_svn,
632 "set-version|v", \$set_version,
633 "set-release|r|package-version|p", \$set_release
636 if ($show_help) { pod2usage(1); }
638 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
646 if (! open(FILE, "<$vconf_file")) {
647 print STDERR "Version configuration file $vconf_file not "
648 . "found. Using defaults.\n";
655 next unless (/^(\w+)(:|=)\s*(\S.*)/);
656 $version_pref{$1} = $3;
672 if ($set_version || $set_release) {
674 print "Generating version information\n";
677 if ($version_pref{"enable"} == 0) {
678 print "Release information disabled in $vconf_file.\n";
683 print "Generating release information\n";
685 print "Resetting release information\n";
687 $package_string = "";
690 &update_versioned_files;
697 make-version.pl - Get and set build-time version information for Wireshark
701 make-version.pl [options] [source directory]
705 --help, -h This help message
706 --get-svn, -g Print the SVN revision and source.
707 --set-svn, -s Set the information in svnversion.h
708 --set-version, -v Set the major, minor, and micro versions in
709 configure.ac, config.nmake, debian/changelog,
710 and docbook/asciidoc.conf.
711 Resets the release information when used by
713 --set-release, -r Set the release information in configure.ac
715 --package-version, -p Deprecated. Same as --set-release.
717 Options can be used in any combination. If none are specified B<--set-svn>
721 # Editor modelines - http://www.wireshark.org/tools/modelines.html
726 # indent-tabs-mode: t
729 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
730 # :indentSize=8:tabSize=8:noTabs=false: