3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 # If "version.conf" is present, it is parsed for configuration values.
26 # Possible values are:
28 # enable - Enable or disable versioning. Zero (0) disables, nonzero
30 # svn_client - Use svn client i.s.o. ugly internal SVN file hack
31 # tortoise_svn - Use TortoiseSVN client instead of ugly internal SVN
33 # format - A strftime() formatted string to use as a template for
34 # the version string. The sequence "%#" will substitute
35 # the number of commits for Git or the revision number
37 # pkg_enable - Enable or disable local package versioning.
38 # pkg_format - Like "format", but used for the local package version.
40 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
41 # configure.ac and the VERSION macro in config.nmake will have the
42 # pkg_format template appended to the version number. version.h will
43 # _not_ be generated if either argument is present.
45 # Default configuration:
51 # format: git %Y%m%d%H%M%S
55 # XXX - We're pretty dumb about the "%#" substitution, and about having
56 # spaces in the package format.
62 use POSIX qw(strftime);
68 my $version_file = 'version.h';
69 my $package_string = "";
70 my $vconf_file = 'version.conf';
72 my $tortoise_file = "tortoise_template";
76 my $repo_branch = "unknown";
77 my $git_description = undef;
90 "git_client" => 0, # set if .git found and .git/svn not found
91 "svn_client" => 0, # set if .svn found
93 "format" => "git %Y%m%d%H%M%S",
95 # Normal development builds
97 "pkg_format" => "-%#",
99 # Development releases
106 # Ensure we run with correct locale
109 $ENV{GIT_PAGER} = "";
111 # Attempt to get revision information from the repository.
114 my $version_format = $version_pref{"format"};
115 my $package_format = "";
119 my $repo_root = undef;
120 my $repo_url = undef;
122 my $info_source = "Unknown";
124 if ($version_pref{"pkg_enable"} > 0) {
125 $package_format = $version_pref{"pkg_format"};
128 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
129 $info_source = "Command line (git)";
130 $version_pref{"git_client"} = 1;
131 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
132 $info_source = "Command line (svn info)";
133 $info_cmd = "svn info $srcdir";
134 $version_pref{"svn_client"} = 1;
135 } elsif (-d "$srcdir/.git/svn") {
136 $info_source = "Command line (git-svn)";
137 $info_cmd = "(cd $srcdir; git svn info)";
142 # A big ugly hash: git rev-parse HEAD
143 # 1ddc83849075addb0cac69a6fe3782f4325337b9
145 # A small ugly hash: git rev-parse --short HEAD
148 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
151 # A version description: git describe --tags --dirty
152 # wireshark-1.8.12-15-g1ddc838
154 # Number of commits in this branch: git rev-list --count HEAD
157 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
160 # Refs: git ls-remote code.wireshark.org:wireshark
161 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
163 if ($version_pref{"git_client"}) {
168 chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
169 if ($? == 0 && length($line) > 1) {
170 $last_change = $line;
173 # Commits since last annotated tag.
174 chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always --match "v*"});
175 if ($? == 0 && length($line) > 1) {
176 my @parts = split(/-/, $line);
177 $git_description = $line;
178 $num_commits = $parts[-2];
179 $commit_id = $parts[-1];
182 chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
183 if (defined($line)) {
187 # This will break in some cases. Hopefully not during
188 # official package builds.
189 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
190 if ($? == 0 && length($line) > 1) {
191 $repo_branch = basename($line);
197 if ($last_change && $num_commits && $repo_url && $repo_branch) {
200 } elsif ($version_pref{"svn_client"}) {
204 $line = qx{$info_cmd};
205 if (defined($line)) {
206 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
207 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
209 if ($line =~ /Last Changed Rev: (\d+)/) {
212 if ($line =~ /URL: (\S+)/) {
215 if ($line =~ /Repository Root: (\S+)/) {
223 if ($last_change && $num_commits && $repo_url && $repo_root) {
226 } elsif ($version_pref{"tortoise_svn"}) {
227 # Dynamically generic template file needed by TortoiseSVN
228 open(TORTOISE, ">$tortoise_file");
229 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
230 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
233 $info_source = "Command line (SubWCRev)";
234 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
235 my $tortoise = system($info_cmd);
236 if ($tortoise == 0) {
241 #clean up the template file
242 unlink($tortoise_file);
245 if ($num_commits == 0) {
246 # Fall back to config.nmake
247 $info_source = "Prodding config.nmake";
248 my $filepath = "$srcdir/config.nmake";
249 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
250 while ($line = <CFGNMAKE>) {
251 if ($line =~ /^VCS_REVISION=(\d+)/) {
259 if ($num_commits == 0 and -d "$srcdir/.git") {
265 # If someone had properly tagged 1.9.0 we could also use
266 # "git describe --abbrev=1 --tags HEAD"
268 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
269 $line = qx{$info_cmd};
270 if (defined($line)) {
271 if ($line =~ /svn path=.*; revision=(\d+)/) {
275 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
276 $line = qx{$info_cmd};
277 if (defined($line)) {
278 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
279 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
282 $info_cmd = "(cd $srcdir; git branch)";
283 $line = qx{$info_cmd};
284 if (defined($line)) {
285 if ($line =~ /\* (\S+)/) {
292 if ($num_commits == 0 and -d "$srcdir/.bzr") {
298 $info_cmd = "(cd $srcdir; bzr log -l 1)";
299 $line = qx{$info_cmd};
300 if (defined($line)) {
301 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
302 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
304 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+)"/) { $num_commits = $1; }
347 if ($line =~ /\/>/) {
348 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
349 $last_change && $num_commits) {
354 # XXX - Fetch the repository root & URL
361 # If we picked up the revision and modification time,
362 # generate our strings.
363 if ($version_pref{"pkg_enable"}) {
364 $version_format =~ s/%#/$num_commits/;
365 $package_format =~ s/%#/$num_commits-$commit_id/;
366 $package_string = strftime($package_format, gmtime($last_change));
369 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
370 $repo_branch = substr($repo_url, length($repo_root));
375 Commit distance : $num_commits
376 Commit ID : $commit_id
377 Revision source : $info_source
378 Release stamp : $package_string
380 } elsif ($print_vcs) {
381 print new_version_h();
386 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
388 # set(GIT_REVISION 999)
389 # set(PROJECT_MAJOR_VERSION 1)
390 # set(PROJECT_MINOR_VERSION 99)
391 # set(PROJECT_PATCH_VERSION 0)
392 # set(PROJECT_VERSION_EXTENSION "-rc5")
393 sub update_cmakelists_txt
398 my $filepath = "$srcdir/CMakeLists.txt";
399 my $cmake_package_string = "\$ENV{WIRESHARK_VERSION_EXTRA}";
401 if ($package_string ne "") { $cmake_package_string = $package_string; }
403 return if (!$set_version && $package_string eq "");
405 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
406 while ($line = <CFGIN>) {
407 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
408 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
409 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
410 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
411 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
412 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
413 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
414 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
415 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
416 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $cmake_package_string);
421 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
422 print(CFGIN $contents);
424 print "$filepath has been updated.\n";
427 # Read configure.ac, then write it back out with an updated
429 sub update_configure_ac
434 my $filepath = "$srcdir/configure.ac";
436 return if (!$set_version && $package_string eq "");
438 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
439 while ($line = <CFGIN>) {
440 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
441 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
442 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
443 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
444 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
445 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
446 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
447 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
452 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
453 print(CFGIN $contents);
455 print "$filepath has been updated.\n";
458 # Read config.nmake, then write it back out with an updated
460 sub update_config_nmake
465 my $filepath = "$srcdir/config.nmake";
466 my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
468 if ($package_string ne "") { $win_package_string = $package_string; }
471 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
472 while ($line = <CFGNMAKE>) {
473 if ($line =~ /^VCS_REVISION=.*([\r\n]+)$/) {
474 $line = sprintf("VCS_REVISION=%d$1", $num_commits);
475 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
476 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
477 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
478 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
479 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
480 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
481 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
482 $line = "VERSION_EXTRA=$win_package_string$1";
487 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
488 print(CFGNMAKE $contents);
490 print "$filepath has been updated.\n";
493 # Read docbook/asciidoc.conf, then write it back out with an updated
494 # wireshark-version replacement line.
495 sub update_release_notes
500 my $filepath = "$srcdir/docbook/asciidoc.conf";
502 return if (!$set_version);
504 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
505 while ($line = <ADOC_CONF>) {
506 # wireshark-version:\[\]=1.9.1
508 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
509 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
510 $version_pref{"version_major"},
511 $version_pref{"version_minor"},
512 $version_pref{"version_micro"},
518 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
519 print(ADOC_CONF $contents);
521 print "$filepath has been updated.\n";
524 # Read debian/changelog, then write back out an updated version.
525 sub update_debian_changelog
530 my $filepath = "$srcdir/debian/changelog";
532 return if ($set_version == 0);
534 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
535 while ($line = <CHANGELOG>) {
536 if ($set_version && CHANGELOG->input_line_number() == 1) {
537 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
538 $version_pref{"version_major"},
539 $version_pref{"version_minor"},
540 $version_pref{"version_micro"},
546 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
547 print(CHANGELOG $contents);
549 print "$filepath has been updated.\n";
552 # Read Makefile.am for each library, then write back out an updated version.
553 sub update_automake_lib_releases
561 return if (!$set_version);
563 # The Libtool manual says
564 # "If the library source code has changed at all since the last
565 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
566 # epan changes with each minor release, almost by definition. wiretap
567 # changes with *most* releases.
569 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
570 for $filedir ("epan", "wiretap") { # "wsutil"
572 $filepath = $filedir . "/Makefile.am";
573 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
574 while ($line = <MAKEFILE_AM>) {
575 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
577 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
578 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
583 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
584 print(MAKEFILE_AM $contents);
586 print "$filepath has been updated.\n";
590 # Read CMakeLists.txt for each library, then write back out an updated version.
591 sub update_cmake_lib_releases
599 return if (!$set_version);
601 for $filedir ("epan", "wiretap") { # "wsutil"
603 $filepath = $filedir . "/CMakeLists.txt";
604 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
605 while ($line = <CMAKELISTS_TXT>) {
606 # set(FULL_SO_VERSION "0.0.0")
608 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
609 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
614 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
615 print(CMAKELISTS_TXT $contents);
616 close(CMAKELISTS_TXT);
617 print "$filepath has been updated.\n";
621 # Update distributed files that contain any version information
622 sub update_versioned_files
624 &update_cmakelists_txt;
625 &update_configure_ac;
626 &update_config_nmake;
627 &update_release_notes;
628 &update_debian_changelog;
629 &update_automake_lib_releases;
630 &update_cmake_lib_releases;
637 if ($git_description) {
638 $VCS_REVISION = "#define VCSVERSION \"" .
639 $git_description . "\"\n" .
640 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
641 } elsif ($last_change && $num_commits) {
642 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name . " Rev " .
643 $num_commits . "\"\n" .
644 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
646 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name .
648 "#define VCSBRANCH \"unknown\"\n";
651 return $VCS_REVISION;
654 # Print the version control system's version to $version_file.
655 # Don't change the file if it is not needed.
656 sub print_VCS_REVISION
658 my $VCS_REVISION = new_version_h();
659 my $needs_update = 1;
660 if (open(OLDREV, "<$version_file")) {
661 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
662 if ($old_VCS_REVISION eq $VCS_REVISION) {
668 if (! $set_vcs) { return; }
671 # print "Updating $version_file so it contains:\n$VCS_REVISION";
672 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
673 print VER "$VCS_REVISION";
675 print "$version_file has been updated.\n";
677 print "$version_file unchanged.\n";
681 # Read values from the configuration file, if it exists.
686 # Get our command-line args
687 # XXX - Do we need an option to undo --set-release?
689 "help|h", \$show_help,
690 "get-vcs|get-svn|g", \$get_vcs,
691 "set-vcs|set-svn|s", \$set_vcs,
692 "print-vcs", \$print_vcs,
693 "set-version|v", \$set_version,
694 "set-release|r|package-version|p", \$set_release
697 if ($show_help) { pod2usage(1); }
699 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
707 if (! open(FILE, "<$vconf_file")) {
708 print STDERR "Version configuration file $vconf_file not "
709 . "found. Using defaults.\n";
714 s/^\s+|\s+$//g; # chomp() may not handle CR
716 next unless (/^(\w+)(:|=)\s*(\S.*)/);
717 $version_pref{$1} = $3;
733 if ($set_version || $set_release) {
735 print "Generating version information\n";
738 if ($version_pref{"enable"} == 0) {
739 print "Release information disabled in $vconf_file.\n";
744 print "Generating release information\n";
746 print "Resetting release information\n";
748 $package_string = "";
751 &update_versioned_files;
758 make-version.pl - Get and set build-time version information for Wireshark
762 make-version.pl [options] [source directory]
766 --help, -h This help message
767 --get-vcs, -g Print the VCS revision and source.
768 --set-vcs, -s Set the information in version.h
769 --print-vcs Print the vcs version to standard output
770 --set-version, -v Set the major, minor, and micro versions in
771 configure.ac, config.nmake, debian/changelog,
772 and docbook/asciidoc.conf.
773 Resets the release information when used by
775 --set-release, -r Set the release information in configure.ac
777 --package-version, -p Deprecated. Same as --set-release.
779 Options can be used in any combination. If none are specified B<--set-svn>
785 # Editor modelines - http://www.wireshark.org/tools/modelines.html
790 # indent-tabs-mode: t
793 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
794 # :indentSize=8:tabSize=8:noTabs=false: