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 CMakeLists.txt 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.
63 use POSIX qw(strftime);
69 my $version_file = 'version.h';
70 my $package_string = "";
71 my $vconf_file = 'version.conf';
73 my $tortoise_file = "tortoise_template";
77 my $repo_branch = "unknown";
78 my $git_executable = "git";
79 my $git_description = undef;
92 "git_client" => 0, # set if .git found and .git/svn not found
93 "svn_client" => 0, # set if .svn found
95 "format" => "git %Y%m%d%H%M%S",
97 # Normal development builds
99 "pkg_format" => "-%#",
101 # Development releases
108 my $devnull = File::Spec->devnull();
110 # Ensure we run with correct locale
113 $ENV{GIT_PAGER} = "";
116 print STDERR @_ if $verbose;
119 # Attempt to get revision information from the repository.
122 my $version_format = $version_pref{"format"};
123 my $package_format = "";
128 my $info_source = "Unknown";
130 # Make sure git is available.
131 if (!`$git_executable --version`) {
132 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
136 if ($version_pref{"pkg_enable"} > 0) {
137 $package_format = $version_pref{"pkg_format"};
140 if (-e "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
141 $info_source = "Command line (git)";
142 $version_pref{"git_client"} = 1;
143 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
144 $info_source = "Command line (svn info)";
145 $info_cmd = "cd $srcdir; svn info";
146 $version_pref{"svn_client"} = 1;
147 } elsif (-d "$srcdir/.git/svn") {
148 $info_source = "Command line (git-svn)";
149 $info_cmd = "(cd $srcdir; $git_executable svn info)";
154 # A big ugly hash: git rev-parse HEAD
155 # 1ddc83849075addb0cac69a6fe3782f4325337b9
157 # A small ugly hash: git rev-parse --short HEAD
160 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
163 # A version description: git describe --tags --dirty
164 # wireshark-1.8.12-15-g1ddc838
166 # Number of commits in this branch: git rev-list --count HEAD
169 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
172 # Refs: git ls-remote code.wireshark.org:wireshark
173 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
175 if ($version_pref{"git_client"}) {
180 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
181 if ($? == 0 && length($line) > 1) {
182 $last_change = $line;
185 # Commits since last annotated tag.
186 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --long --always --match "v*"});
187 if ($? == 0 && length($line) > 1) {
188 my @parts = split(/-/, $line);
189 $git_description = $line;
190 $num_commits = $parts[-2];
191 $commit_id = $parts[-1];
194 # This will break in some cases. Hopefully not during
195 # official package builds.
196 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\} 2> $devnull});
197 if ($? == 0 && length($line) > 1) {
198 $repo_branch = basename($line);
204 if ($last_change && $num_commits && $repo_branch) {
207 } elsif ($version_pref{"svn_client"}) {
208 my $repo_root = undef;
209 my $repo_url = undef;
213 $line = qx{$info_cmd};
214 if (defined($line)) {
215 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
216 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
218 if ($line =~ /Last Changed Rev: (\d+)/) {
221 if ($line =~ /URL: (\S+)/) {
224 if ($line =~ /Repository Root: (\S+)/) {
232 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
233 $repo_branch = substr($repo_url, length($repo_root));
236 if ($last_change && $num_commits && $repo_url && $repo_root) {
239 } elsif ($version_pref{"tortoise_svn"}) {
240 # Dynamically generic template file needed by TortoiseSVN
241 open(TORTOISE, ">$tortoise_file");
242 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
243 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
246 $info_source = "Command line (SubWCRev)";
247 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
248 my $tortoise = system($info_cmd);
249 if ($tortoise == 0) {
254 #clean up the template file
255 unlink($tortoise_file);
258 if ($num_commits == 0 and -e "$srcdir/.git") {
264 # If someone had properly tagged 1.9.0 we could also use
265 # "git describe --abbrev=1 --tags HEAD"
267 $info_cmd = "(cd $srcdir; $git_executable log --format='%b' -n 1)";
268 $line = qx{$info_cmd};
269 if (defined($line)) {
270 if ($line =~ /svn path=.*; revision=(\d+)/) {
274 $info_cmd = "(cd $srcdir; $git_executable log --format='%ad' -n 1 --date=iso)";
275 $line = qx{$info_cmd};
276 if (defined($line)) {
277 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
278 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
281 $info_cmd = "(cd $srcdir; $git_executable branch)";
282 $line = qx{$info_cmd};
283 if (defined($line)) {
284 if ($line =~ /\* (\S+)/) {
291 if ($num_commits == 0 and -d "$srcdir/.bzr") {
297 $info_cmd = "(cd $srcdir; bzr log -l 1)";
298 $line = qx{$info_cmd};
299 if (defined($line)) {
300 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
301 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
303 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
314 # 'svn info' failed or the user really wants us to dig around in .svn/entries
316 # Start of ugly internal SVN file hack
317 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
318 print STDERR "Unable to open $srcdir/.svn/entries\n";
320 $info_source = "Prodding .svn";
321 # We need to find out whether our parser can handle the entries file
324 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
325 $repo_version = "pre1.4";
326 } elsif ($line =~ /^8$/) {
327 $repo_version = "1.4";
329 $repo_version = "unknown";
332 if ($repo_version eq "pre1.4") {
333 # The entries schema is flat, so we can use regexes to parse its contents.
334 while ($line = <ENTRIES>) {
335 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
340 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
341 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
342 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
344 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
346 if ($line =~ /\/>/) {
347 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
348 $last_change && $num_commits) {
353 # XXX - Fetch the repository root & URL
360 # If we picked up the revision and modification time,
361 # generate our strings.
362 if ($version_pref{"pkg_enable"}) {
363 $version_format =~ s/%#/$num_commits/;
364 $package_format =~ s/%#/$num_commits-$commit_id/;
365 $package_string = strftime($package_format, gmtime($last_change));
370 Commit distance : $num_commits
371 Commit ID : $commit_id
372 Revision source : $info_source
373 Release stamp : $package_string
375 } elsif ($print_vcs) {
376 print new_version_h();
381 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
383 # set(GIT_REVISION 999)
384 # set(PROJECT_MAJOR_VERSION 1)
385 # set(PROJECT_MINOR_VERSION 99)
386 # set(PROJECT_PATCH_VERSION 0)
387 # set(PROJECT_VERSION_EXTENSION "-rc5")
388 sub update_cmakelists_txt
393 my $filepath = "$srcdir/CMakeLists.txt";
395 return if (!$set_version && $package_string eq "");
397 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
398 while ($line = <CFGIN>) {
399 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
400 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
401 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
402 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
403 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
404 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
405 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
406 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
407 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION .*([\r\n]+)$/) {
408 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
413 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
414 print(CFGIN $contents);
416 print "$filepath has been updated.\n";
419 # Read configure.ac, then write it back out with an updated
421 sub update_configure_ac
426 my $filepath = "$srcdir/configure.ac";
428 return if (!$set_version && $package_string eq "");
430 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
431 while ($line = <CFGIN>) {
432 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
433 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
434 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
435 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
436 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
437 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
438 } elsif ($line =~ /^m4_define\( *\[?version_extra\]? *,.*([\r\n]+)$/) {
439 $line = sprintf("m4_define([version_extra], [%s])$1", $package_string);
444 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
445 print(CFGIN $contents);
447 print "$filepath has been updated.\n";
450 # Read docbook/asciidoc.conf, then write it back out with an updated
451 # wireshark-version replacement line.
452 sub update_release_notes
457 my $filepath = "$srcdir/docbook/asciidoc.conf";
459 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
460 while ($line = <ADOC_CONF>) {
461 # wireshark-version:\[\]=1.9.1
463 if ($line =~ /^wireshark-version=.*([\r\n]+)$/) {
464 $line = sprintf("wireshark-version=%d.%d.%d$1",
465 $version_pref{"version_major"},
466 $version_pref{"version_minor"},
467 $version_pref{"version_micro"},
473 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
474 print(ADOC_CONF $contents);
476 print "$filepath has been updated.\n";
479 # Read debian/changelog, then write back out an updated version.
480 sub update_debian_changelog
485 my $filepath = "$srcdir/debian/changelog";
487 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
488 while ($line = <CHANGELOG>) {
489 if ($set_version && CHANGELOG->input_line_number() == 1) {
490 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
491 $version_pref{"version_major"},
492 $version_pref{"version_minor"},
493 $version_pref{"version_micro"},
499 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
500 print(CHANGELOG $contents);
502 print "$filepath has been updated.\n";
505 # Read Makefile.am for each library, then write back out an updated version.
506 sub update_automake_lib_releases
514 # The Libtool manual says
515 # "If the library source code has changed at all since the last
516 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
517 # epan changes with each minor release, almost by definition. wiretap
518 # changes with *most* releases.
520 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
521 for $filedir ("epan", "wiretap") { # "wsutil"
523 $filepath = $filedir . "/Makefile.am";
524 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
525 while ($line = <MAKEFILE_AM>) {
526 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
528 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
529 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
534 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
535 print(MAKEFILE_AM $contents);
537 print "$filepath has been updated.\n";
541 # Read CMakeLists.txt for each library, then write back out an updated version.
542 sub update_cmake_lib_releases
550 for $filedir ("epan", "wiretap") { # "wsutil"
552 $filepath = $filedir . "/CMakeLists.txt";
553 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
554 while ($line = <CMAKELISTS_TXT>) {
555 # set(FULL_SO_VERSION "0.0.0")
557 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
558 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
563 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
564 print(CMAKELISTS_TXT $contents);
565 close(CMAKELISTS_TXT);
566 print "$filepath has been updated.\n";
570 # Update distributed files that contain any version information
571 sub update_versioned_files
573 # Matches CMakeLists.txt
574 printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
575 $num_commits, $version_pref{"version_major"},
576 $version_pref{"version_minor"}, $version_pref{"version_micro"},
578 &update_cmakelists_txt;
579 &update_configure_ac;
581 &update_release_notes;
582 &update_debian_changelog;
583 &update_automake_lib_releases;
584 &update_cmake_lib_releases;
591 my $set_header = shift @_;
594 $VCS_REVISION = "/* #undef VCSVERSION */\n";
595 $VCS_REVISION .= "/* #undef VCSBRANCH */\n";
596 return $VCS_REVISION;
599 if ($git_description) {
600 $VCS_REVISION = "#define VCSVERSION \"" .
601 $git_description . "\"\n" .
602 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
603 } elsif ($last_change && $num_commits) {
604 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name . " Rev " .
605 $num_commits . "\"\n" .
606 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
608 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name .
610 "#define VCSBRANCH \"unknown\"\n";
613 return $VCS_REVISION;
616 # Print the version control system's version to $version_file.
617 # Don't change the file if it is not needed.
618 sub print_VCS_REVISION
621 my $needs_update = 1;
625 chomp($git_cdir = qx{git --git-dir="$srcdir/.git" rev-parse --git-common-dir 2> $devnull});
626 if ($git_cdir && -f "$git_cdir/wireshark-disable-versioning") {
627 print_diag "Header versioning disabled using git override.\n";
631 $VCS_REVISION = new_version_h($set_header);
632 if (open(OLDREV, "<$version_file")) {
633 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
634 if ($old_VCS_REVISION eq $VCS_REVISION) {
640 if (! $set_vcs) { return; }
643 # print "Updating $version_file so it contains:\n$VCS_REVISION";
644 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
645 print VER "$VCS_REVISION";
647 print "$version_file has been updated.\n";
648 } elsif (!$set_header) {
649 print "$version_file disabled.\n";
651 print "$version_file unchanged.\n";
655 # Read values from the configuration file, if it exists.
660 # Get our command-line args
661 # XXX - Do we need an option to undo --set-release?
663 "help|h", \$show_help,
664 "get-vcs|get-svn|g", \$get_vcs,
665 "set-vcs|set-svn|s", \$set_vcs,
666 "git-bin", \$git_executable,
667 "print-vcs", \$print_vcs,
668 "set-version|v", \$set_version,
669 "set-release|r|package-version|p", \$set_release,
673 if ($show_help) { pod2usage(1); }
675 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
683 if (! open(FILE, "<$vconf_file")) {
684 print_diag "Version configuration file $vconf_file not "
685 . "found. Using defaults.\n";
690 s/^\s+|\s+$//g; # chomp() may not handle CR
692 next unless (/^(\w+)(:|=)\s*(\S.*)/);
693 $version_pref{$1} = $3;
709 if ($set_version || $set_release) {
711 print "Generating version information.\n";
714 if ($version_pref{"enable"} == 0) {
715 print "Release information disabled in $vconf_file.\n";
720 print "Generating release information.\n";
722 print "Resetting release information\n";
724 $package_string = "";
727 &update_versioned_files;
734 make-version.pl - Get and set build-time version information for Wireshark
738 make-version.pl [options] [source directory]
742 --help, -h This help message
743 --get-vcs, -g Print the VCS revision and source.
744 --set-vcs, -s Set the information in version.h
745 --print-vcs Print the vcs version to standard output
746 --set-version, -v Set the major, minor, and micro versions in
747 the top-level CMakeLists.txt, configure.ac,
748 docbook/asciidoc.conf, debian/changelog,
749 the Makefile.am for all libraries, and the
750 CMakeLists.txt for all libraries.
751 Resets the release information when used by
753 --set-release, -r Set the release information in the top-level
754 CMakeLists.txt, configure.ac
755 --package-version, -p Deprecated. Same as --set-release.
756 --verbose Print diagnostic messages to STDERR.
758 Options can be used in any combination. If none are specified B<--set-vcs>
764 # Editor modelines - http://www.wireshark.org/tools/modelines.html
769 # indent-tabs-mode: t
772 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
773 # :indentSize=8:tabSize=8:noTabs=false: