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 # SPDX-License-Identifier: GPL-2.0-or-later
13 # If "version.conf" is present, it is parsed for configuration values.
14 # Possible values are:
16 # enable - Enable or disable versioning. Zero (0) disables, nonzero
18 # svn_client - Use svn client i.s.o. ugly internal SVN file hack
19 # tortoise_svn - Use TortoiseSVN client instead of ugly internal SVN
21 # format - A strftime() formatted string to use as a template for
22 # the version string. The sequence "%#" will substitute
23 # the number of commits for Git or the revision number
25 # pkg_enable - Enable or disable local package versioning.
26 # pkg_format - Like "format", but used for the local package version.
28 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
29 # configure.ac and the VERSION macro in CMakeLists.txt will have the
30 # pkg_format template appended to the version number. version.h will
31 # _not_ be generated if either argument is present.
33 # Default configuration:
40 # format: git %Y%m%d%H%M%S
44 # XXX - We're pretty dumb about the "%#" substitution, and about having
45 # spaces in the package format.
52 use POSIX qw(strftime);
58 my $version_file = 'version.h';
59 my $package_string = "";
60 my $vconf_file = 'version.conf';
62 my $tortoise_file = "tortoise_template";
66 my $repo_branch = "unknown";
67 my $git_executable = "git";
68 my $git_description = undef;
81 "git_client" => 0, # set if .git found and .git/svn not found
82 "svn_client" => 0, # set if .svn found
83 "git_svn" => 0, # set if both .git and .git/svn are found
85 "format" => "git %Y%m%d%H%M%S",
87 # Normal development builds
89 "pkg_format" => "-%#",
91 # Development releases
98 my $devnull = File::Spec->devnull();
99 my $enable_vcsversion = 1;
101 # Ensure we run with correct locale
104 $ENV{GIT_PAGER} = "";
107 print STDERR @_ if $verbose;
110 # Attempt to get revision information from the repository.
113 my $version_format = $version_pref{"format"};
114 my $package_format = "";
119 my $info_source = "Unknown";
124 if ($version_pref{"pkg_enable"} > 0) {
125 $package_format = $version_pref{"pkg_format"};
128 # For tarball releases, do not invoke git at all and instead rely on
129 # versioning information that was provided at tarball creation time.
130 if ($version_pref{"git_description"}) {
131 $info_source = "version.conf file";
132 } elsif (-e "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
133 $info_source = "Command line (git)";
134 $version_pref{"git_client"} = 1;
136 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
137 $info_source = "Command line (svn info)";
138 $info_cmd = "cd $srcdir; svn info";
139 $version_pref{"svn_client"} = 1;
140 } elsif (-d "$srcdir/.git/svn") {
141 $info_source = "Command line (git-svn)";
142 $info_cmd = "(cd $srcdir; $git_executable svn info)";
144 $version_pref{"git_svn"} = 1;
147 # Make sure git is available.
148 if ($is_git_repo && !`$git_executable --version`) {
149 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
153 # Check whether to include VCS version information in version.h
155 chomp($git_cdir = qx{git --git-dir="$srcdir/.git" rev-parse --git-common-dir 2> $devnull});
156 if ($git_cdir && -f "$git_cdir/wireshark-disable-versioning") {
157 print_diag "Header versioning disabled using git override.\n";
158 $enable_vcsversion = 0;
164 # A big ugly hash: git rev-parse HEAD
165 # 1ddc83849075addb0cac69a6fe3782f4325337b9
167 # A small ugly hash: git rev-parse --short HEAD
170 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
173 # A version description: git describe --tags --dirty
174 # wireshark-1.8.12-15-g1ddc838
176 # Number of commits in this branch: git rev-list --count HEAD
179 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
182 # Refs: git ls-remote code.wireshark.org:wireshark
183 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
185 if ($version_pref{"git_description"}) {
186 $git_description = $version_pref{"git_description"};
188 # Assume format like v2.3.0rc0-1342-g7bdcf75
189 $commit_id = ($git_description =~ /([0-9a-f]+)$/)[0];
190 } elsif ($version_pref{"git_client"}) {
195 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
196 if ($? == 0 && length($line) > 1) {
197 $last_change = $line;
200 # Commits since last annotated tag.
201 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --abbrev=8 --long --always --match "v[1-9]*"});
202 if ($? == 0 && length($line) > 1) {
203 my @parts = split(/-/, $line);
204 $git_description = $line;
205 $num_commits = $parts[-2];
206 $commit_id = $parts[-1];
209 # This will break in some cases. Hopefully not during
210 # official package builds.
211 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\} 2> $devnull});
212 if ($? == 0 && length($line) > 1) {
213 $repo_branch = basename($line);
219 if ($last_change && $num_commits && $repo_branch) {
222 } elsif ($version_pref{"svn_client"} || $version_pref{"git_svn"}) {
223 my $repo_root = undef;
224 my $repo_url = undef;
228 $line = qx{$info_cmd};
229 if (defined($line)) {
230 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
231 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
233 if ($line =~ /Last Changed Rev: (\d+)/) {
236 if ($line =~ /URL: (\S+)/) {
239 if ($line =~ /Repository Root: (\S+)/) {
247 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
248 $repo_branch = substr($repo_url, length($repo_root));
251 if ($last_change && $num_commits && $repo_url && $repo_root) {
254 } elsif ($version_pref{"tortoise_svn"}) {
255 # Dynamically generic template file needed by TortoiseSVN
256 open(TORTOISE, ">$tortoise_file");
257 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
258 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
261 $info_source = "Command line (SubWCRev)";
262 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
263 my $tortoise = system($info_cmd);
264 if ($tortoise == 0) {
269 #clean up the template file
270 unlink($tortoise_file);
273 if ($num_commits == 0 and -e "$srcdir/.git") {
279 # If someone had properly tagged 1.9.0 we could also use
280 # "git describe --abbrev=1 --tags HEAD"
282 $info_cmd = "(cd $srcdir; $git_executable log --format='%b' -n 1)";
283 $line = qx{$info_cmd};
284 if (defined($line)) {
285 if ($line =~ /svn path=.*; revision=(\d+)/) {
289 $info_cmd = "(cd $srcdir; $git_executable log --format='%ad' -n 1 --date=iso)";
290 $line = qx{$info_cmd};
291 if (defined($line)) {
292 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
293 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
296 $info_cmd = "(cd $srcdir; $git_executable branch)";
297 $line = qx{$info_cmd};
298 if (defined($line)) {
299 if ($line =~ /\* (\S+)/) {
306 if ($num_commits == 0 and -d "$srcdir/.bzr") {
312 $info_cmd = "(cd $srcdir; bzr log -l 1)";
313 $line = qx{$info_cmd};
314 if (defined($line)) {
315 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
316 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
318 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
329 # 'svn info' failed or the user really wants us to dig around in .svn/entries
331 # Start of ugly internal SVN file hack
332 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
333 print STDERR "Unable to open $srcdir/.svn/entries\n";
335 $info_source = "Prodding .svn";
336 # We need to find out whether our parser can handle the entries file
339 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
340 $repo_version = "pre1.4";
341 } elsif ($line =~ /^8$/) {
342 $repo_version = "1.4";
344 $repo_version = "unknown";
347 if ($repo_version eq "pre1.4") {
348 # The entries schema is flat, so we can use regexes to parse its contents.
349 while ($line = <ENTRIES>) {
350 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
355 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
356 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
357 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
359 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
361 if ($line =~ /\/>/) {
362 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
363 $last_change && $num_commits) {
368 # XXX - Fetch the repository root & URL
375 # If we picked up the revision and modification time,
376 # generate our strings.
377 if ($version_pref{"pkg_enable"}) {
378 $version_format =~ s/%#/$num_commits/;
379 $package_format =~ s/%#/$num_commits-$commit_id/;
380 $package_string = strftime($package_format, gmtime($last_change));
385 Commit distance : $num_commits
386 Commit ID : $commit_id
387 Revision source : $info_source
388 Release stamp : $package_string
390 } elsif ($print_vcs) {
391 print new_version_h();
396 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
398 # set(GIT_REVISION 999)
399 # set(PROJECT_MAJOR_VERSION 1)
400 # set(PROJECT_MINOR_VERSION 99)
401 # set(PROJECT_PATCH_VERSION 0)
402 # set(PROJECT_VERSION_EXTENSION "-rc5")
403 sub update_cmakelists_txt
408 my $filepath = "$srcdir/CMakeLists.txt";
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", $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_define\( *\[?version_extra\]? *,.*?([\r\n]+)$/) {
454 $line = sprintf("m4_define([version_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 docbook/attributes.asciidoc, then write it back out with an updated
466 # wireshark-version replacement line.
467 sub update_attributes_asciidoc
472 my $filepath = "$srcdir/docbook/attributes.asciidoc";
474 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
475 while ($line = <ADOC_CONF>) {
476 # :wireshark-version: 2.3.1
478 if ($line =~ /^:wireshark-version:.*?([\r\n]+)$/) {
479 $line = sprintf(":wireshark-version: %d.%d.%d$1",
480 $version_pref{"version_major"},
481 $version_pref{"version_minor"},
482 $version_pref{"version_micro"},
488 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
489 print(ADOC_CONF $contents);
491 print "$filepath has been updated.\n";
494 sub update_docinfo_asciidoc
497 my @paths = ("$srcdir/docbook/developer-guide-docinfo.xml",
498 "$srcdir/docbook/user-guide-docinfo.xml");
500 foreach my $filepath (@paths) {
502 open(DOCINFO_XML, "< $filepath") || die "Can't read $filepath!";
503 while ($line = <DOCINFO_XML>) {
504 if ($line =~ /^<subtitle>For Wireshark \d.\d+<\/subtitle>([\r\n]+)$/) {
505 $line = sprintf("<subtitle>For Wireshark %d.%d</subtitle>$1",
506 $version_pref{"version_major"},
507 $version_pref{"version_minor"},
513 open(DOCINFO_XML, "> $filepath") || die "Can't write $filepath!";
514 print(DOCINFO_XML $contents);
516 print "$filepath has been updated.\n";
520 # Read debian/changelog, then write back out an updated version.
521 sub update_debian_changelog
526 my $filepath = "$srcdir/debian/changelog";
528 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
529 while ($line = <CHANGELOG>) {
530 if ($set_version && CHANGELOG->input_line_number() == 1) {
531 $line =~ /^.*?([\r\n]+)$/;
532 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low$1",
533 $version_pref{"version_major"},
534 $version_pref{"version_minor"},
535 $version_pref{"version_micro"},
541 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
542 print(CHANGELOG $contents);
544 print "$filepath has been updated.\n";
547 # Read Makefile.am for each library, then write back out an updated version.
548 sub update_automake_lib_releases
556 # The Libtool manual says
557 # "If the library source code has changed at all since the last
558 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
559 # epan changes with each minor release, almost by definition. wiretap
560 # changes with *most* releases.
562 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
563 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
565 $filepath = $filedir . "/Makefile.am";
566 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
567 while ($line = <MAKEFILE_AM>) {
568 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
570 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*[\r\n]+)$/) {
571 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
576 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
577 print(MAKEFILE_AM $contents);
579 print "$filepath has been updated.\n";
583 # Read CMakeLists.txt for each library, then write back out an updated version.
584 sub update_cmake_lib_releases
592 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
594 $filepath = $filedir . "/CMakeLists.txt";
595 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
596 while ($line = <CMAKELISTS_TXT>) {
597 # set(FULL_SO_VERSION "0.0.0")
599 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*[\r\n]+)$/) {
600 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
605 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
606 print(CMAKELISTS_TXT $contents);
607 close(CMAKELISTS_TXT);
608 print "$filepath has been updated.\n";
612 # Update distributed files that contain any version information
613 sub update_versioned_files
615 # Matches CMakeLists.txt
616 printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
617 $num_commits, $version_pref{"version_major"},
618 $version_pref{"version_minor"}, $version_pref{"version_micro"},
620 &update_cmakelists_txt;
621 &update_configure_ac;
623 &update_attributes_asciidoc;
624 &update_docinfo_asciidoc;
625 &update_debian_changelog;
626 &update_automake_lib_releases;
627 &update_cmake_lib_releases;
633 if (!$enable_vcsversion) {
634 return "/* #undef VCSVERSION */\n";
637 if ($git_description) {
638 # Do not bother adding the git branch, the git describe output
639 # normally contains the base tag and commit ID which is more
640 # than sufficient to determine the actual source tree.
641 return "#define VCSVERSION \"$git_description\"\n";
644 if ($last_change && $num_commits) {
645 return "#define VCSVERSION \"$vcs_name Rev $num_commits from $repo_branch\"\n";
648 return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
651 # Print the version control system's version to $version_file.
652 # Don't change the file if it is not needed.
653 sub print_VCS_REVISION
656 my $needs_update = 1;
658 $VCS_REVISION = new_version_h();
659 if (open(OLDREV, "<$version_file")) {
660 my $old_VCS_REVISION = <OLDREV>;
661 if ($old_VCS_REVISION eq $VCS_REVISION) {
667 if (! $set_vcs) { return; }
670 # print "Updating $version_file so it contains:\n$VCS_REVISION";
671 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
672 print VER "$VCS_REVISION";
674 print "$version_file has been updated.\n";
675 } elsif (!$enable_vcsversion) {
676 print "$version_file disabled.\n";
678 print "$version_file unchanged.\n";
682 # Read values from the configuration file, if it exists.
687 # Get our command-line args
688 # XXX - Do we need an option to undo --set-release?
690 "help|h", \$show_help,
691 "get-vcs|get-svn|g", \$get_vcs,
692 "set-vcs|set-svn|s", \$set_vcs,
693 "git-bin", \$git_executable,
694 "print-vcs", \$print_vcs,
695 "set-version|v", \$set_version,
696 "set-release|r|package-version|p", \$set_release,
700 if ($show_help) { pod2usage(1); }
702 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
710 if (! open(FILE, "<$vconf_file")) {
711 if (! open(FILE, "<$srcdir/$vconf_file")) {
712 print_diag "Version configuration file $vconf_file not "
713 . "found. Using defaults.\n";
719 s/^\s+|\s+$//g; # chomp() may not handle CR
721 next unless (/^(\w+)(:|=)\s*(\S.*)/);
722 $version_pref{$1} = $3;
738 if ($set_version || $set_release) {
740 print "Generating version information.\n";
743 if ($version_pref{"enable"} == 0) {
744 print "Release information disabled in $vconf_file.\n";
749 print "Generating release information.\n";
751 print "Resetting release information\n";
753 $package_string = "";
756 &update_versioned_files;
763 make-version.pl - Get and set build-time version information for Wireshark
767 make-version.pl [options] [source directory]
771 --help, -h This help message
772 --get-vcs, -g Print the VCS revision and source.
773 --set-vcs, -s Set the information in version.h
774 --print-vcs Print the vcs version to standard output
775 --set-version, -v Set the major, minor, and micro versions in
776 the top-level CMakeLists.txt, configure.ac,
777 docbook/attributes.asciidoc, debian/changelog,
778 the Makefile.am for all libraries, and the
779 CMakeLists.txt for all libraries.
780 Resets the release information when used by
782 --set-release, -r Set the release information in the top-level
783 CMakeLists.txt, configure.ac
784 --package-version, -p Deprecated. Same as --set-release.
785 --verbose Print diagnostic messages to STDERR.
787 Options can be used in any combination. If none are specified B<--set-vcs>
793 # Editor modelines - http://www.wireshark.org/tools/modelines.html
798 # indent-tabs-mode: t
801 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
802 # :indentSize=8:tabSize=8:noTabs=false: