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();
109 my $enable_vcsversion = 1;
111 # Ensure we run with correct locale
114 $ENV{GIT_PAGER} = "";
117 print STDERR @_ if $verbose;
120 # Attempt to get revision information from the repository.
123 my $version_format = $version_pref{"format"};
124 my $package_format = "";
129 my $info_source = "Unknown";
134 if ($version_pref{"pkg_enable"} > 0) {
135 $package_format = $version_pref{"pkg_format"};
138 # For tarball releases, do not invoke git at all and instead rely on
139 # versioning information that was provided at tarball creation time.
140 if ($version_pref{"git_description"}) {
141 $info_source = "version.conf file";
142 } elsif (-e "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
143 $info_source = "Command line (git)";
144 $version_pref{"git_client"} = 1;
146 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
147 $info_source = "Command line (svn info)";
148 $info_cmd = "cd $srcdir; svn info";
149 $version_pref{"svn_client"} = 1;
150 } elsif (-d "$srcdir/.git/svn") {
151 $info_source = "Command line (git-svn)";
152 $info_cmd = "(cd $srcdir; $git_executable svn info)";
156 # Make sure git is available.
157 if ($is_git_repo && !`$git_executable --version`) {
158 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
162 # Check whether to include VCS version information in version.h
164 chomp($git_cdir = qx{git --git-dir="$srcdir/.git" rev-parse --git-common-dir 2> $devnull});
165 if ($git_cdir && -f "$git_cdir/wireshark-disable-versioning") {
166 print_diag "Header versioning disabled using git override.\n";
167 $enable_vcsversion = 0;
173 # A big ugly hash: git rev-parse HEAD
174 # 1ddc83849075addb0cac69a6fe3782f4325337b9
176 # A small ugly hash: git rev-parse --short HEAD
179 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
182 # A version description: git describe --tags --dirty
183 # wireshark-1.8.12-15-g1ddc838
185 # Number of commits in this branch: git rev-list --count HEAD
188 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
191 # Refs: git ls-remote code.wireshark.org:wireshark
192 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
194 if ($version_pref{"git_description"}) {
195 $git_description = $version_pref{"git_description"};
197 # Assume format like v2.3.0rc0-1342-g7bdcf75
198 $commit_id = ($git_description =~ /([0-9a-f]+)$/)[0];
199 } elsif ($version_pref{"git_client"}) {
204 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
205 if ($? == 0 && length($line) > 1) {
206 $last_change = $line;
209 # Commits since last annotated tag.
210 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --long --always --match "v*"});
211 if ($? == 0 && length($line) > 1) {
212 my @parts = split(/-/, $line);
213 $git_description = $line;
214 $num_commits = $parts[-2];
215 $commit_id = $parts[-1];
218 # This will break in some cases. Hopefully not during
219 # official package builds.
220 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\} 2> $devnull});
221 if ($? == 0 && length($line) > 1) {
222 $repo_branch = basename($line);
228 if ($last_change && $num_commits && $repo_branch) {
231 } elsif ($version_pref{"svn_client"}) {
232 my $repo_root = undef;
233 my $repo_url = undef;
237 $line = qx{$info_cmd};
238 if (defined($line)) {
239 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
240 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
242 if ($line =~ /Last Changed Rev: (\d+)/) {
245 if ($line =~ /URL: (\S+)/) {
248 if ($line =~ /Repository Root: (\S+)/) {
256 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
257 $repo_branch = substr($repo_url, length($repo_root));
260 if ($last_change && $num_commits && $repo_url && $repo_root) {
263 } elsif ($version_pref{"tortoise_svn"}) {
264 # Dynamically generic template file needed by TortoiseSVN
265 open(TORTOISE, ">$tortoise_file");
266 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
267 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
270 $info_source = "Command line (SubWCRev)";
271 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
272 my $tortoise = system($info_cmd);
273 if ($tortoise == 0) {
278 #clean up the template file
279 unlink($tortoise_file);
282 if ($num_commits == 0 and -e "$srcdir/.git") {
288 # If someone had properly tagged 1.9.0 we could also use
289 # "git describe --abbrev=1 --tags HEAD"
291 $info_cmd = "(cd $srcdir; $git_executable log --format='%b' -n 1)";
292 $line = qx{$info_cmd};
293 if (defined($line)) {
294 if ($line =~ /svn path=.*; revision=(\d+)/) {
298 $info_cmd = "(cd $srcdir; $git_executable log --format='%ad' -n 1 --date=iso)";
299 $line = qx{$info_cmd};
300 if (defined($line)) {
301 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
302 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
305 $info_cmd = "(cd $srcdir; $git_executable branch)";
306 $line = qx{$info_cmd};
307 if (defined($line)) {
308 if ($line =~ /\* (\S+)/) {
315 if ($num_commits == 0 and -d "$srcdir/.bzr") {
321 $info_cmd = "(cd $srcdir; bzr log -l 1)";
322 $line = qx{$info_cmd};
323 if (defined($line)) {
324 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
325 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
327 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
338 # 'svn info' failed or the user really wants us to dig around in .svn/entries
340 # Start of ugly internal SVN file hack
341 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
342 print STDERR "Unable to open $srcdir/.svn/entries\n";
344 $info_source = "Prodding .svn";
345 # We need to find out whether our parser can handle the entries file
348 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
349 $repo_version = "pre1.4";
350 } elsif ($line =~ /^8$/) {
351 $repo_version = "1.4";
353 $repo_version = "unknown";
356 if ($repo_version eq "pre1.4") {
357 # The entries schema is flat, so we can use regexes to parse its contents.
358 while ($line = <ENTRIES>) {
359 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
364 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
365 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
366 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
368 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
370 if ($line =~ /\/>/) {
371 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
372 $last_change && $num_commits) {
377 # XXX - Fetch the repository root & URL
384 # If we picked up the revision and modification time,
385 # generate our strings.
386 if ($version_pref{"pkg_enable"}) {
387 $version_format =~ s/%#/$num_commits/;
388 $package_format =~ s/%#/$num_commits-$commit_id/;
389 $package_string = strftime($package_format, gmtime($last_change));
394 Commit distance : $num_commits
395 Commit ID : $commit_id
396 Revision source : $info_source
397 Release stamp : $package_string
399 } elsif ($print_vcs) {
400 print new_version_h();
405 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
407 # set(GIT_REVISION 999)
408 # set(PROJECT_MAJOR_VERSION 1)
409 # set(PROJECT_MINOR_VERSION 99)
410 # set(PROJECT_PATCH_VERSION 0)
411 # set(PROJECT_VERSION_EXTENSION "-rc5")
412 sub update_cmakelists_txt
417 my $filepath = "$srcdir/CMakeLists.txt";
419 return if (!$set_version && $package_string eq "");
421 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
422 while ($line = <CFGIN>) {
423 if ($line =~ /^set *\( *GIT_REVISION .*?([\r\n]+)$/) {
424 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
425 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*?([\r\n]+)$/) {
426 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
427 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*?([\r\n]+)$/) {
428 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
429 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*?([\r\n]+)$/) {
430 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
431 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION .*?([\r\n]+)$/) {
432 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
437 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
438 print(CFGIN $contents);
440 print "$filepath has been updated.\n";
443 # Read configure.ac, then write it back out with an updated
445 sub update_configure_ac
450 my $filepath = "$srcdir/configure.ac";
452 return if (!$set_version && $package_string eq "");
454 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
455 while ($line = <CFGIN>) {
456 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*?([\r\n]+)$/) {
457 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
458 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*?([\r\n]+)$/) {
459 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
460 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*?([\r\n]+)$/) {
461 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
462 } elsif ($line =~ /^m4_define\( *\[?version_extra\]? *,.*?([\r\n]+)$/) {
463 $line = sprintf("m4_define([version_extra], [%s])$1", $package_string);
468 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
469 print(CFGIN $contents);
471 print "$filepath has been updated.\n";
474 # Read docbook/attributes.asciidoc, then write it back out with an updated
475 # wireshark-version replacement line.
476 sub update_attributes_asciidoc
481 my $filepath = "$srcdir/docbook/attributes.asciidoc";
483 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
484 while ($line = <ADOC_CONF>) {
485 # :wireshark-version: 2.3.1
487 if ($line =~ /^:wireshark-version:.*?([\r\n]+)$/) {
488 $line = sprintf(":wireshark-version: %d.%d.%d$1",
489 $version_pref{"version_major"},
490 $version_pref{"version_minor"},
491 $version_pref{"version_micro"},
497 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
498 print(ADOC_CONF $contents);
500 print "$filepath has been updated.\n";
503 # Read debian/changelog, then write back out an updated version.
504 sub update_debian_changelog
509 my $filepath = "$srcdir/debian/changelog";
511 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
512 while ($line = <CHANGELOG>) {
513 if ($set_version && CHANGELOG->input_line_number() == 1) {
514 $line =~ /^.*?([\r\n]+)$/;
515 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low$1",
516 $version_pref{"version_major"},
517 $version_pref{"version_minor"},
518 $version_pref{"version_micro"},
524 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
525 print(CHANGELOG $contents);
527 print "$filepath has been updated.\n";
530 # Read Makefile.am for each library, then write back out an updated version.
531 sub update_automake_lib_releases
539 # The Libtool manual says
540 # "If the library source code has changed at all since the last
541 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
542 # epan changes with each minor release, almost by definition. wiretap
543 # changes with *most* releases.
545 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
546 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
548 $filepath = $filedir . "/Makefile.am";
549 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
550 while ($line = <MAKEFILE_AM>) {
551 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
553 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*[\r\n]+)$/) {
554 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
559 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
560 print(MAKEFILE_AM $contents);
562 print "$filepath has been updated.\n";
566 # Read CMakeLists.txt for each library, then write back out an updated version.
567 sub update_cmake_lib_releases
575 for $filedir ("$srcdir/epan", "$srcdir/wiretap") { # "$srcdir/wsutil"
577 $filepath = $filedir . "/CMakeLists.txt";
578 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
579 while ($line = <CMAKELISTS_TXT>) {
580 # set(FULL_SO_VERSION "0.0.0")
582 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*[\r\n]+)$/) {
583 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
588 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
589 print(CMAKELISTS_TXT $contents);
590 close(CMAKELISTS_TXT);
591 print "$filepath has been updated.\n";
595 # Update distributed files that contain any version information
596 sub update_versioned_files
598 # Matches CMakeLists.txt
599 printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
600 $num_commits, $version_pref{"version_major"},
601 $version_pref{"version_minor"}, $version_pref{"version_micro"},
603 &update_cmakelists_txt;
604 &update_configure_ac;
606 &update_attributes_asciidoc;
607 &update_debian_changelog;
608 &update_automake_lib_releases;
609 &update_cmake_lib_releases;
615 if (!$enable_vcsversion) {
616 return "/* #undef VCSVERSION */\n";
619 if ($git_description) {
620 # Do not bother adding the git branch, the git describe output
621 # normally contains the base tag and commit ID which is more
622 # than sufficient to determine the actual source tree.
623 return "#define VCSVERSION \"$git_description\"\n";
626 if ($last_change && $num_commits) {
627 return "#define VCSVERSION \"$vcs_name Rev $num_commits from $repo_branch\"\n";
630 return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
633 # Print the version control system's version to $version_file.
634 # Don't change the file if it is not needed.
635 sub print_VCS_REVISION
638 my $needs_update = 1;
640 $VCS_REVISION = new_version_h();
641 if (open(OLDREV, "<$version_file")) {
642 my $old_VCS_REVISION = <OLDREV>;
643 if ($old_VCS_REVISION eq $VCS_REVISION) {
649 if (! $set_vcs) { return; }
652 # print "Updating $version_file so it contains:\n$VCS_REVISION";
653 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
654 print VER "$VCS_REVISION";
656 print "$version_file has been updated.\n";
657 } elsif (!$enable_vcsversion) {
658 print "$version_file disabled.\n";
660 print "$version_file unchanged.\n";
664 # Read values from the configuration file, if it exists.
669 # Get our command-line args
670 # XXX - Do we need an option to undo --set-release?
672 "help|h", \$show_help,
673 "get-vcs|get-svn|g", \$get_vcs,
674 "set-vcs|set-svn|s", \$set_vcs,
675 "git-bin", \$git_executable,
676 "print-vcs", \$print_vcs,
677 "set-version|v", \$set_version,
678 "set-release|r|package-version|p", \$set_release,
682 if ($show_help) { pod2usage(1); }
684 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
692 if (! open(FILE, "<$vconf_file")) {
693 if (! open(FILE, "<$srcdir/$vconf_file")) {
694 print_diag "Version configuration file $vconf_file not "
695 . "found. Using defaults.\n";
701 s/^\s+|\s+$//g; # chomp() may not handle CR
703 next unless (/^(\w+)(:|=)\s*(\S.*)/);
704 $version_pref{$1} = $3;
720 if ($set_version || $set_release) {
722 print "Generating version information.\n";
725 if ($version_pref{"enable"} == 0) {
726 print "Release information disabled in $vconf_file.\n";
731 print "Generating release information.\n";
733 print "Resetting release information\n";
735 $package_string = "";
738 &update_versioned_files;
745 make-version.pl - Get and set build-time version information for Wireshark
749 make-version.pl [options] [source directory]
753 --help, -h This help message
754 --get-vcs, -g Print the VCS revision and source.
755 --set-vcs, -s Set the information in version.h
756 --print-vcs Print the vcs version to standard output
757 --set-version, -v Set the major, minor, and micro versions in
758 the top-level CMakeLists.txt, configure.ac,
759 docbook/attributes.asciidoc, debian/changelog,
760 the Makefile.am for all libraries, and the
761 CMakeLists.txt for all libraries.
762 Resets the release information when used by
764 --set-release, -r Set the release information in the top-level
765 CMakeLists.txt, configure.ac
766 --package-version, -p Deprecated. Same as --set-release.
767 --verbose Print diagnostic messages to STDERR.
769 Options can be used in any combination. If none are specified B<--set-vcs>
775 # Editor modelines - http://www.wireshark.org/tools/modelines.html
780 # indent-tabs-mode: t
783 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
784 # :indentSize=8:tabSize=8:noTabs=false: