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_executable = "git";
78 my $git_description = undef;
91 "git_client" => 0, # set if .git found and .git/svn not found
92 "svn_client" => 0, # set if .svn found
94 "format" => "git %Y%m%d%H%M%S",
96 # Normal development builds
98 "pkg_format" => "-%#",
100 # Development releases
108 # Ensure we run with correct locale
111 $ENV{GIT_PAGER} = "";
114 print STDERR @_ if $verbose;
117 # Attempt to get revision information from the repository.
120 my $version_format = $version_pref{"format"};
121 my $package_format = "";
126 my $info_source = "Unknown";
128 # Make sure git is available.
129 if (!`$git_executable --version`) {
130 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
134 if ($version_pref{"pkg_enable"} > 0) {
135 $package_format = $version_pref{"pkg_format"};
138 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
139 $info_source = "Command line (git)";
140 $version_pref{"git_client"} = 1;
141 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
142 $info_source = "Command line (svn info)";
143 $info_cmd = "svn info $srcdir";
144 $version_pref{"svn_client"} = 1;
145 } elsif (-d "$srcdir/.git/svn") {
146 $info_source = "Command line (git-svn)";
147 $info_cmd = "(cd $srcdir; $git_executable svn info)";
152 # A big ugly hash: git rev-parse HEAD
153 # 1ddc83849075addb0cac69a6fe3782f4325337b9
155 # A small ugly hash: git rev-parse --short HEAD
158 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
161 # A version description: git describe --tags --dirty
162 # wireshark-1.8.12-15-g1ddc838
164 # Number of commits in this branch: git rev-list --count HEAD
167 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
170 # Refs: git ls-remote code.wireshark.org:wireshark
171 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
173 if ($version_pref{"git_client"}) {
178 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
179 if ($? == 0 && length($line) > 1) {
180 $last_change = $line;
183 # Commits since last annotated tag.
184 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --long --always --match "v*"});
185 if ($? == 0 && length($line) > 1) {
186 my @parts = split(/-/, $line);
187 $git_description = $line;
188 $num_commits = $parts[-2];
189 $commit_id = $parts[-1];
192 # This will break in some cases. Hopefully not during
193 # official package builds.
194 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
195 if ($? == 0 && length($line) > 1) {
196 $repo_branch = basename($line);
202 if ($last_change && $num_commits && $repo_branch) {
205 } elsif ($version_pref{"svn_client"}) {
206 my $repo_root = undef;
207 my $repo_url = undef;
211 $line = qx{$info_cmd};
212 if (defined($line)) {
213 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
214 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
216 if ($line =~ /Last Changed Rev: (\d+)/) {
219 if ($line =~ /URL: (\S+)/) {
222 if ($line =~ /Repository Root: (\S+)/) {
230 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
231 $repo_branch = substr($repo_url, length($repo_root));
234 if ($last_change && $num_commits && $repo_url && $repo_root) {
237 } elsif ($version_pref{"tortoise_svn"}) {
238 # Dynamically generic template file needed by TortoiseSVN
239 open(TORTOISE, ">$tortoise_file");
240 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
241 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
244 $info_source = "Command line (SubWCRev)";
245 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
246 my $tortoise = system($info_cmd);
247 if ($tortoise == 0) {
252 #clean up the template file
253 unlink($tortoise_file);
256 if ($num_commits == 0) {
257 # Fall back to config.nmake
258 $info_source = "Prodding config.nmake";
259 my $filepath = "$srcdir/config.nmake";
260 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
261 while ($line = <CFGNMAKE>) {
262 if ($line =~ /^VCS_REVISION=(\d+)/) {
270 if ($num_commits == 0 and -d "$srcdir/.git") {
276 # If someone had properly tagged 1.9.0 we could also use
277 # "git describe --abbrev=1 --tags HEAD"
279 $info_cmd = "(cd $srcdir; $git_executable log --format='%b' -n 1)";
280 $line = qx{$info_cmd};
281 if (defined($line)) {
282 if ($line =~ /svn path=.*; revision=(\d+)/) {
286 $info_cmd = "(cd $srcdir; $git_executable log --format='%ad' -n 1 --date=iso)";
287 $line = qx{$info_cmd};
288 if (defined($line)) {
289 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
290 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
293 $info_cmd = "(cd $srcdir; $git_executable branch)";
294 $line = qx{$info_cmd};
295 if (defined($line)) {
296 if ($line =~ /\* (\S+)/) {
303 if ($num_commits == 0 and -d "$srcdir/.bzr") {
309 $info_cmd = "(cd $srcdir; bzr log -l 1)";
310 $line = qx{$info_cmd};
311 if (defined($line)) {
312 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
313 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
315 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
326 # 'svn info' failed or the user really wants us to dig around in .svn/entries
328 # Start of ugly internal SVN file hack
329 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
330 print STDERR "Unable to open $srcdir/.svn/entries\n";
332 $info_source = "Prodding .svn";
333 # We need to find out whether our parser can handle the entries file
336 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
337 $repo_version = "pre1.4";
338 } elsif ($line =~ /^8$/) {
339 $repo_version = "1.4";
341 $repo_version = "unknown";
344 if ($repo_version eq "pre1.4") {
345 # The entries schema is flat, so we can use regexes to parse its contents.
346 while ($line = <ENTRIES>) {
347 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
352 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
353 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
354 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
356 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
358 if ($line =~ /\/>/) {
359 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
360 $last_change && $num_commits) {
365 # XXX - Fetch the repository root & URL
372 # If we picked up the revision and modification time,
373 # generate our strings.
374 if ($version_pref{"pkg_enable"}) {
375 $version_format =~ s/%#/$num_commits/;
376 $package_format =~ s/%#/$num_commits-$commit_id/;
377 $package_string = strftime($package_format, gmtime($last_change));
382 Commit distance : $num_commits
383 Commit ID : $commit_id
384 Revision source : $info_source
385 Release stamp : $package_string
387 } elsif ($print_vcs) {
388 print new_version_h();
393 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
395 # set(GIT_REVISION 999)
396 # set(PROJECT_MAJOR_VERSION 1)
397 # set(PROJECT_MINOR_VERSION 99)
398 # set(PROJECT_PATCH_VERSION 0)
399 # set(PROJECT_VERSION_EXTENSION "-rc5")
400 sub update_cmakelists_txt
405 my $filepath = "$srcdir/CMakeLists.txt";
406 my $cmake_package_string = "\$ENV{WIRESHARK_VERSION_EXTRA}";
408 if ($package_string ne "") { $cmake_package_string = $package_string; }
410 return if (!$set_version && $package_string eq "");
412 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
413 while ($line = <CFGIN>) {
414 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
415 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
416 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
417 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
418 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
419 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
420 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
421 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
422 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
423 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $cmake_package_string);
428 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
429 print(CFGIN $contents);
431 print "$filepath has been updated.\n";
434 # Read configure.ac, then write it back out with an updated
436 sub update_configure_ac
441 my $filepath = "$srcdir/configure.ac";
443 return if (!$set_version && $package_string eq "");
445 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
446 while ($line = <CFGIN>) {
447 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
448 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
449 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
450 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
451 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
452 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
453 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
454 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
459 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
460 print(CFGIN $contents);
462 print "$filepath has been updated.\n";
465 # Read config.nmake, then write it back out with an updated
467 sub update_config_nmake
472 my $filepath = "$srcdir/config.nmake";
473 my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
475 if ($package_string ne "") { $win_package_string = $package_string; }
478 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
479 while ($line = <CFGNMAKE>) {
480 if ($line =~ /^VCS_REVISION=.*([\r\n]+)$/) {
481 $line = sprintf("VCS_REVISION=%d$1", $num_commits);
482 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
483 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
484 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
485 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
486 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
487 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
488 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
489 $line = "VERSION_EXTRA=$win_package_string$1";
494 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
495 print(CFGNMAKE $contents);
497 print "$filepath has been updated.\n";
500 # Read docbook/asciidoc.conf, then write it back out with an updated
501 # wireshark-version replacement line.
502 sub update_release_notes
507 my $filepath = "$srcdir/docbook/asciidoc.conf";
509 return if (!$set_version);
511 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
512 while ($line = <ADOC_CONF>) {
513 # wireshark-version:\[\]=1.9.1
515 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
516 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
517 $version_pref{"version_major"},
518 $version_pref{"version_minor"},
519 $version_pref{"version_micro"},
525 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
526 print(ADOC_CONF $contents);
528 print "$filepath has been updated.\n";
531 # Read debian/changelog, then write back out an updated version.
532 sub update_debian_changelog
537 my $filepath = "$srcdir/debian/changelog";
539 return if ($set_version == 0);
541 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
542 while ($line = <CHANGELOG>) {
543 if ($set_version && CHANGELOG->input_line_number() == 1) {
544 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
545 $version_pref{"version_major"},
546 $version_pref{"version_minor"},
547 $version_pref{"version_micro"},
553 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
554 print(CHANGELOG $contents);
556 print "$filepath has been updated.\n";
559 # Read Makefile.am for each library, then write back out an updated version.
560 sub update_automake_lib_releases
568 return if (!$set_version);
570 # The Libtool manual says
571 # "If the library source code has changed at all since the last
572 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
573 # epan changes with each minor release, almost by definition. wiretap
574 # changes with *most* releases.
576 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
577 for $filedir ("epan", "wiretap") { # "wsutil"
579 $filepath = $filedir . "/Makefile.am";
580 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
581 while ($line = <MAKEFILE_AM>) {
582 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
584 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
585 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
590 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
591 print(MAKEFILE_AM $contents);
593 print "$filepath has been updated.\n";
597 # Read CMakeLists.txt for each library, then write back out an updated version.
598 sub update_cmake_lib_releases
606 return if (!$set_version);
608 for $filedir ("epan", "wiretap") { # "wsutil"
610 $filepath = $filedir . "/CMakeLists.txt";
611 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
612 while ($line = <CMAKELISTS_TXT>) {
613 # set(FULL_SO_VERSION "0.0.0")
615 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
616 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
621 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
622 print(CMAKELISTS_TXT $contents);
623 close(CMAKELISTS_TXT);
624 print "$filepath has been updated.\n";
628 # Update distributed files that contain any version information
629 sub update_versioned_files
631 &update_cmakelists_txt;
632 &update_configure_ac;
633 &update_config_nmake;
634 &update_release_notes;
635 &update_debian_changelog;
636 &update_automake_lib_releases;
637 &update_cmake_lib_releases;
644 if ($git_description) {
645 $VCS_REVISION = "#define VCSVERSION \"" .
646 $git_description . "\"\n" .
647 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
648 } elsif ($last_change && $num_commits) {
649 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name . " Rev " .
650 $num_commits . "\"\n" .
651 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
653 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name .
655 "#define VCSBRANCH \"unknown\"\n";
658 return $VCS_REVISION;
661 # Print the version control system's version to $version_file.
662 # Don't change the file if it is not needed.
663 sub print_VCS_REVISION
665 my $VCS_REVISION = new_version_h();
666 my $needs_update = 1;
667 if (open(OLDREV, "<$version_file")) {
668 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
669 if ($old_VCS_REVISION eq $VCS_REVISION) {
675 if (! $set_vcs) { return; }
678 # print "Updating $version_file so it contains:\n$VCS_REVISION";
679 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
680 print VER "$VCS_REVISION";
682 print "$version_file has been updated.\n";
684 print "$version_file unchanged.\n";
688 # Read values from the configuration file, if it exists.
693 # Get our command-line args
694 # XXX - Do we need an option to undo --set-release?
696 "help|h", \$show_help,
697 "get-vcs|get-svn|g", \$get_vcs,
698 "set-vcs|set-svn|s", \$set_vcs,
699 "git-bin", \$git_executable,
700 "print-vcs", \$print_vcs,
701 "set-version|v", \$set_version,
702 "set-release|r|package-version|p", \$set_release,
706 if ($show_help) { pod2usage(1); }
708 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
716 if (! open(FILE, "<$vconf_file")) {
717 print_diag "Version configuration file $vconf_file not "
718 . "found. Using defaults.\n";
723 s/^\s+|\s+$//g; # chomp() may not handle CR
725 next unless (/^(\w+)(:|=)\s*(\S.*)/);
726 $version_pref{$1} = $3;
742 if ($set_version || $set_release) {
744 print "Generating version information\n";
747 if ($version_pref{"enable"} == 0) {
748 print "Release information disabled in $vconf_file.\n";
753 print "Generating release information\n";
755 print "Resetting release information\n";
757 $package_string = "";
760 &update_versioned_files;
767 make-version.pl - Get and set build-time version information for Wireshark
771 make-version.pl [options] [source directory]
775 --help, -h This help message
776 --get-vcs, -g Print the VCS revision and source.
777 --set-vcs, -s Set the information in version.h
778 --print-vcs Print the vcs version to standard output
779 --set-version, -v Set the major, minor, and micro versions in
780 configure.ac, config.nmake, debian/changelog,
781 and docbook/asciidoc.conf.
782 Resets the release information when used by
784 --set-release, -r Set the release information in configure.ac
786 --package-version, -p Deprecated. Same as --set-release.
787 --verbose Print diagnostic messages to STDERR.
789 Options can be used in any combination. If none are specified B<--set-svn>
795 # Editor modelines - http://www.wireshark.org/tools/modelines.html
800 # indent-tabs-mode: t
803 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
804 # :indentSize=8:tabSize=8:noTabs=false: