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:
39 # format: git %Y%m%d%H%M%S
43 # XXX - We're pretty dumb about the "%#" substitution, and about having
44 # spaces in the package format.
51 use POSIX qw(strftime);
57 my $version_file = 'version.h';
58 my $package_string = "";
59 my $vconf_file = 'version.conf';
61 my $tortoise_file = "tortoise_template";
65 my $repo_branch = "unknown";
66 my $git_executable = "git";
67 my $git_description = undef;
80 "git_client" => 0, # set if .git found and .git/svn not found
81 "svn_client" => 0, # set if .svn found
83 "format" => "git %Y%m%d%H%M%S",
85 # Normal development builds
87 "pkg_format" => "-%#",
89 # Development releases
96 my $devnull = File::Spec->devnull();
97 my $enable_vcsversion = 1;
99 # Ensure we run with correct locale
102 $ENV{GIT_PAGER} = "";
105 print STDERR @_ if $verbose;
108 # Attempt to get revision information from the repository.
111 my $version_format = $version_pref{"format"};
112 my $package_format = "";
117 my $info_source = "Unknown";
122 if ($version_pref{"pkg_enable"} > 0) {
123 $package_format = $version_pref{"pkg_format"};
126 # For tarball releases, do not invoke git at all and instead rely on
127 # versioning information that was provided at tarball creation time.
128 if ($version_pref{"git_description"}) {
129 $info_source = "version.conf file";
130 } elsif (-e "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
131 $info_source = "Command line (git)";
132 $version_pref{"git_client"} = 1;
134 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
135 $info_source = "Command line (svn info)";
136 $info_cmd = "cd $srcdir; svn info";
137 $version_pref{"svn_client"} = 1;
138 } elsif (-d "$srcdir/.git/svn") {
139 $info_source = "Command line (git-svn)";
140 $info_cmd = "(cd $srcdir; $git_executable svn info)";
144 # Make sure git is available.
145 if ($is_git_repo && !`$git_executable --version`) {
146 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
150 # Check whether to include VCS version information in version.h
152 chomp($git_cdir = qx{git --git-dir="$srcdir/.git" rev-parse --git-common-dir 2> $devnull});
153 if ($git_cdir && -f "$git_cdir/wireshark-disable-versioning") {
154 print_diag "Header versioning disabled using git override.\n";
155 $enable_vcsversion = 0;
161 # A big ugly hash: git rev-parse HEAD
162 # 1ddc83849075addb0cac69a6fe3782f4325337b9
164 # A small ugly hash: git rev-parse --short HEAD
167 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
170 # A version description: git describe --tags --dirty
171 # wireshark-1.8.12-15-g1ddc838
173 # Number of commits in this branch: git rev-list --count HEAD
176 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
179 # Refs: git ls-remote code.wireshark.org:wireshark
180 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
182 if ($version_pref{"git_description"}) {
183 $git_description = $version_pref{"git_description"};
185 # Assume format like v2.3.0rc0-1342-g7bdcf75
186 $commit_id = ($git_description =~ /([0-9a-f]+)$/)[0];
187 } elsif ($version_pref{"git_client"}) {
192 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
193 if ($? == 0 && length($line) > 1) {
194 $last_change = $line;
197 # Commits since last annotated tag.
198 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --abbrev=8 --long --always --match "v[1-9]*"});
199 if ($? == 0 && length($line) > 1) {
200 my @parts = split(/-/, $line);
201 $git_description = $line;
202 $num_commits = $parts[-2];
203 $commit_id = $parts[-1];
206 # This will break in some cases. Hopefully not during
207 # official package builds.
208 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\} 2> $devnull});
209 if ($? == 0 && length($line) > 1) {
210 $repo_branch = basename($line);
216 if ($last_change && $num_commits && $repo_branch) {
219 } elsif ($version_pref{"svn_client"}) {
220 my $repo_root = undef;
221 my $repo_url = undef;
225 $line = qx{$info_cmd};
226 if (defined($line)) {
227 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
228 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
230 if ($line =~ /Last Changed Rev: (\d+)/) {
233 if ($line =~ /URL: (\S+)/) {
236 if ($line =~ /Repository Root: (\S+)/) {
244 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
245 $repo_branch = substr($repo_url, length($repo_root));
248 if ($last_change && $num_commits && $repo_url && $repo_root) {
251 } elsif ($version_pref{"tortoise_svn"}) {
252 # Dynamically generic template file needed by TortoiseSVN
253 open(TORTOISE, ">$tortoise_file");
254 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
255 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
258 $info_source = "Command line (SubWCRev)";
259 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
260 my $tortoise = system($info_cmd);
261 if ($tortoise == 0) {
266 #clean up the template file
267 unlink($tortoise_file);
270 if ($num_commits == 0 and -e "$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";
407 return if (!$set_version && $package_string eq "");
409 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
410 while ($line = <CFGIN>) {
411 if ($line =~ /^set *\( *GIT_REVISION .*?([\r\n]+)$/) {
412 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
413 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*?([\r\n]+)$/) {
414 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
415 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*?([\r\n]+)$/) {
416 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
417 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*?([\r\n]+)$/) {
418 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
419 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION .*?([\r\n]+)$/) {
420 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
425 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
426 print(CFGIN $contents);
428 print "$filepath has been updated.\n";
431 # Read configure.ac, then write it back out with an updated
433 sub update_configure_ac
438 my $filepath = "$srcdir/configure.ac";
440 return if (!$set_version && $package_string eq "");
442 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
443 while ($line = <CFGIN>) {
444 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*?([\r\n]+)$/) {
445 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
446 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*?([\r\n]+)$/) {
447 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
448 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*?([\r\n]+)$/) {
449 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
450 } elsif ($line =~ /^m4_define\( *\[?version_extra\]? *,.*?([\r\n]+)$/) {
451 $line = sprintf("m4_define([version_extra], [%s])$1", $package_string);
456 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
457 print(CFGIN $contents);
459 print "$filepath has been updated.\n";
462 # Read docbook/attributes.asciidoc, then write it back out with an updated
463 # wireshark-version replacement line.
464 sub update_attributes_asciidoc
469 my $filepath = "$srcdir/docbook/attributes.asciidoc";
471 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
472 while ($line = <ADOC_CONF>) {
473 # :wireshark-version: 2.3.1
475 if ($line =~ /^:wireshark-version:.*?([\r\n]+)$/) {
476 $line = sprintf(":wireshark-version: %d.%d.%d$1",
477 $version_pref{"version_major"},
478 $version_pref{"version_minor"},
479 $version_pref{"version_micro"},
485 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
486 print(ADOC_CONF $contents);
488 print "$filepath has been updated.\n";
491 sub update_docinfo_asciidoc
494 my @paths = ("$srcdir/docbook/developer-guide-docinfo.xml",
495 "$srcdir/docbook/user-guide-docinfo.xml");
497 foreach my $filepath (@paths) {
499 open(DOCINFO_XML, "< $filepath") || die "Can't read $filepath!";
500 while ($line = <DOCINFO_XML>) {
501 if ($line =~ /^<subtitle>For Wireshark \d.\d+<\/subtitle>([\r\n]+)$/) {
502 $line = sprintf("<subtitle>For Wireshark %d.%d</subtitle>$1",
503 $version_pref{"version_major"},
504 $version_pref{"version_minor"},
510 open(DOCINFO_XML, "> $filepath") || die "Can't write $filepath!";
511 print(DOCINFO_XML $contents);
513 print "$filepath has been updated.\n";
517 # Read debian/changelog, then write back out an updated version.
518 sub update_debian_changelog
523 my $filepath = "$srcdir/debian/changelog";
525 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
526 while ($line = <CHANGELOG>) {
527 if ($set_version && CHANGELOG->input_line_number() == 1) {
528 $line =~ /^.*?([\r\n]+)$/;
529 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low$1",
530 $version_pref{"version_major"},
531 $version_pref{"version_minor"},
532 $version_pref{"version_micro"},
538 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
539 print(CHANGELOG $contents);
541 print "$filepath has been updated.\n";
544 # Read Makefile.am for each library, then write back out an updated version.
545 sub update_automake_lib_releases
553 # The Libtool manual says
554 # "If the library source code has changed at all since the last
555 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
556 # epan changes with each minor release, almost by definition. wiretap
557 # changes with *most* releases.
559 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
560 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
562 $filepath = $filedir . "/Makefile.am";
563 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
564 while ($line = <MAKEFILE_AM>) {
565 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
567 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*[\r\n]+)$/) {
568 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
573 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
574 print(MAKEFILE_AM $contents);
576 print "$filepath has been updated.\n";
580 # Read CMakeLists.txt for each library, then write back out an updated version.
581 sub update_cmake_lib_releases
589 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
591 $filepath = $filedir . "/CMakeLists.txt";
592 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
593 while ($line = <CMAKELISTS_TXT>) {
594 # set(FULL_SO_VERSION "0.0.0")
596 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*[\r\n]+)$/) {
597 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
602 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
603 print(CMAKELISTS_TXT $contents);
604 close(CMAKELISTS_TXT);
605 print "$filepath has been updated.\n";
609 # Update distributed files that contain any version information
610 sub update_versioned_files
612 # Matches CMakeLists.txt
613 printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
614 $num_commits, $version_pref{"version_major"},
615 $version_pref{"version_minor"}, $version_pref{"version_micro"},
617 &update_cmakelists_txt;
618 &update_configure_ac;
620 &update_attributes_asciidoc;
621 &update_docinfo_asciidoc;
622 &update_debian_changelog;
623 &update_automake_lib_releases;
624 &update_cmake_lib_releases;
630 if (!$enable_vcsversion) {
631 return "/* #undef VCSVERSION */\n";
634 if ($git_description) {
635 # Do not bother adding the git branch, the git describe output
636 # normally contains the base tag and commit ID which is more
637 # than sufficient to determine the actual source tree.
638 return "#define VCSVERSION \"$git_description\"\n";
641 if ($last_change && $num_commits) {
642 return "#define VCSVERSION \"$vcs_name Rev $num_commits from $repo_branch\"\n";
645 return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
648 # Print the version control system's version to $version_file.
649 # Don't change the file if it is not needed.
650 sub print_VCS_REVISION
653 my $needs_update = 1;
655 $VCS_REVISION = new_version_h();
656 if (open(OLDREV, "<$version_file")) {
657 my $old_VCS_REVISION = <OLDREV>;
658 if ($old_VCS_REVISION eq $VCS_REVISION) {
664 if (! $set_vcs) { return; }
667 # print "Updating $version_file so it contains:\n$VCS_REVISION";
668 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
669 print VER "$VCS_REVISION";
671 print "$version_file has been updated.\n";
672 } elsif (!$enable_vcsversion) {
673 print "$version_file disabled.\n";
675 print "$version_file unchanged.\n";
679 # Read values from the configuration file, if it exists.
684 # Get our command-line args
685 # XXX - Do we need an option to undo --set-release?
687 "help|h", \$show_help,
688 "get-vcs|get-svn|g", \$get_vcs,
689 "set-vcs|set-svn|s", \$set_vcs,
690 "git-bin", \$git_executable,
691 "print-vcs", \$print_vcs,
692 "set-version|v", \$set_version,
693 "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 if (! open(FILE, "<$srcdir/$vconf_file")) {
709 print_diag "Version configuration file $vconf_file not "
710 . "found. Using defaults.\n";
716 s/^\s+|\s+$//g; # chomp() may not handle CR
718 next unless (/^(\w+)(:|=)\s*(\S.*)/);
719 $version_pref{$1} = $3;
735 if ($set_version || $set_release) {
737 print "Generating version information.\n";
740 if ($version_pref{"enable"} == 0) {
741 print "Release information disabled in $vconf_file.\n";
746 print "Generating release information.\n";
748 print "Resetting release information\n";
750 $package_string = "";
753 &update_versioned_files;
760 make-version.pl - Get and set build-time version information for Wireshark
764 make-version.pl [options] [source directory]
768 --help, -h This help message
769 --get-vcs, -g Print the VCS revision and source.
770 --set-vcs, -s Set the information in version.h
771 --print-vcs Print the vcs version to standard output
772 --set-version, -v Set the major, minor, and micro versions in
773 the top-level CMakeLists.txt, configure.ac,
774 docbook/attributes.asciidoc, debian/changelog,
775 the Makefile.am for all libraries, and the
776 CMakeLists.txt for all libraries.
777 Resets the release information when used by
779 --set-release, -r Set the release information in the top-level
780 CMakeLists.txt, configure.ac
781 --package-version, -p Deprecated. Same as --set-release.
782 --verbose Print diagnostic messages to STDERR.
784 Options can be used in any combination. If none are specified B<--set-vcs>
790 # Editor modelines - http://www.wireshark.org/tools/modelines.html
795 # indent-tabs-mode: t
798 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
799 # :indentSize=8:tabSize=8:noTabs=false: