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:
50 # format: git %Y%m%d%H%M%S
54 # XXX - We're pretty dumb about the "%#" substitution, and about having
55 # spaces in the package format.
61 use POSIX qw(strftime);
67 my $version_file = 'version.h';
68 my $package_string = "";
69 my $vconf_file = 'version.conf';
71 my $tortoise_file = "tortoise_template";
75 my $repo_branch = "unknown";
76 my $git_description = undef;
84 "version_minor" => 99,
85 "version_micro" => 10,
89 "git_client" => 0, # set if .git found and .git/svn not found
92 "format" => "git %Y%m%d%H%M%S",
94 # Normal development builds
96 "pkg_format" => "-%#",
98 # Development releases
105 # Ensure we run with correct locale
108 $ENV{GIT_PAGER} = "";
110 # Attempt to get revision information from the repository.
113 my $version_format = $version_pref{"format"};
114 my $package_format = "";
118 my $repo_root = undef;
119 my $repo_url = undef;
121 my $info_source = "Unknown";
123 if ($version_pref{"pkg_enable"} > 0) {
124 $package_format = $version_pref{"pkg_format"};
127 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
128 $info_source = "Command line (git)";
129 $version_pref{"git_client"} = 1;
130 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
131 $info_source = "Command line (svn info)";
132 $info_cmd = "svn info $srcdir";
133 } elsif (-d "$srcdir/.git/svn") {
134 $info_source = "Command line (git-svn)";
135 $info_cmd = "(cd $srcdir; git svn info)";
140 # A big ugly hash: git rev-parse HEAD
141 # 1ddc83849075addb0cac69a6fe3782f4325337b9
143 # A small ugly hash: git rev-parse --short HEAD
146 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
149 # A version description: git describe --tags --dirty
150 # wireshark-1.8.12-15-g1ddc838
152 # Number of commits in this branch: git rev-list --count HEAD
155 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
158 # Refs: git ls-remote code.wireshark.org:wireshark
159 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
161 if ($version_pref{"git_client"}) {
166 chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
167 if ($? == 0 && length($line) > 1) {
168 $last_change = $line;
171 # Commits since last annotated tag.
172 chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always --match "v*"});
173 if ($? == 0 && length($line) > 1) {
174 my @parts = split(/-/, $line);
175 $git_description = $line;
176 $num_commits = $parts[-2];
177 $commit_id = $parts[-1];
180 chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
181 if (defined($line)) {
185 # This will break in some cases. Hopefully not during
186 # official package builds.
187 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
188 if ($? == 0 && length($line) > 1) {
189 $repo_branch = basename($line);
195 if ($last_change && $num_commits && $repo_url && $repo_branch) {
198 } elsif ($version_pref{"svn_client"}) {
202 $line = qx{$info_cmd};
203 if (defined($line)) {
204 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
205 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
207 if ($line =~ /Last Changed Rev: (\d+)/) {
210 if ($line =~ /URL: (\S+)/) {
213 if ($line =~ /Repository Root: (\S+)/) {
221 if ($last_change && $num_commits && $repo_url && $repo_root) {
224 } elsif ($version_pref{"tortoise_svn"}) {
225 # Dynamically generic template file needed by TortoiseSVN
226 open(TORTOISE, ">$tortoise_file");
227 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
228 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
231 $info_source = "Command line (SubWCRev)";
232 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
233 my $tortoise = system($info_cmd);
234 if ($tortoise == 0) {
239 #clean up the template file
240 unlink($tortoise_file);
243 if ($num_commits == 0) {
244 # Fall back to config.nmake
245 $info_source = "Prodding config.nmake";
246 my $filepath = "$srcdir/config.nmake";
247 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
248 while ($line = <CFGNMAKE>) {
249 if ($line =~ /^VCS_REVISION=(\d+)/) {
257 if ($num_commits == 0 and -d "$srcdir/.git") {
263 # If someone had properly tagged 1.9.0 we could also use
264 # "git describe --abbrev=1 --tags HEAD"
266 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
267 $line = qx{$info_cmd};
268 if (defined($line)) {
269 if ($line =~ /svn path=.*; revision=(\d+)/) {
273 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
274 $line = qx{$info_cmd};
275 if (defined($line)) {
276 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
277 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
280 $info_cmd = "(cd $srcdir; git branch)";
281 $line = qx{$info_cmd};
282 if (defined($line)) {
283 if ($line =~ /\* (\S+)/) {
290 if ($num_commits == 0 and -d "$srcdir/.bzr") {
296 $info_cmd = "(cd $srcdir; bzr log -l 1)";
297 $line = qx{$info_cmd};
298 if (defined($line)) {
299 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
300 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
302 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
313 # 'svn info' failed or the user really wants us to dig around in .svn/entries
315 # Start of ugly internal SVN file hack
316 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
317 print ("Unable to open $srcdir/.svn/entries\n");
319 $info_source = "Prodding .svn";
320 # We need to find out whether our parser can handle the entries file
323 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
324 $repo_version = "pre1.4";
325 } elsif ($line =~ /^8$/) {
326 $repo_version = "1.4";
328 $repo_version = "unknown";
331 if ($repo_version eq "pre1.4") {
332 # The entries schema is flat, so we can use regexes to parse its contents.
333 while ($line = <ENTRIES>) {
334 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
339 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
340 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
341 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
343 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
345 if ($line =~ /\/>/) {
346 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
347 $last_change && $num_commits) {
352 # XXX - Fetch the repository root & URL
359 # If we picked up the revision and modification time,
360 # generate our strings.
361 if ($version_pref{"pkg_enable"}) {
362 $version_format =~ s/%#/$num_commits/;
363 $package_format =~ s/%#/$num_commits-$commit_id/;
364 $package_string = strftime($package_format, gmtime($last_change));
367 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
368 $repo_branch = substr($repo_url, length($repo_root));
373 Commit distance : $num_commits
374 Commit ID : $commit_id
375 Revision source : $info_source
376 Release stamp : $package_string
378 } elsif ($print_vcs) {
379 print new_version_h();
384 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
386 # set(GIT_REVISION 999)
387 # set(PROJECT_MAJOR_VERSION 1)
388 # set(PROJECT_MINOR_VERSION 99)
389 # set(PROJECT_PATCH_VERSION 0)
390 # set(PROJECT_VERSION_EXTENSION "-rc5")
391 sub update_cmakelists_txt
396 my $filepath = "$srcdir/CMakeLists.txt";
397 my $cmake_package_string = "\$ENV{WIRESHARK_VERSION_EXTRA}";
399 if ($package_string ne "") { $cmake_package_string = $package_string; }
401 return if (!$set_version && $package_string eq "");
403 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
404 while ($line = <CFGIN>) {
405 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
406 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
407 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
408 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
409 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
410 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
411 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
412 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
413 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
414 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $cmake_package_string);
419 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
420 print(CFGIN $contents);
422 print "$filepath has been updated.\n";
425 # Read configure.ac, then write it back out with an updated
427 sub update_configure_ac
432 my $filepath = "$srcdir/configure.ac";
434 return if (!$set_version && $package_string eq "");
436 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
437 while ($line = <CFGIN>) {
438 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
439 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
440 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
441 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
442 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
443 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
444 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
445 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
450 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
451 print(CFGIN $contents);
453 print "$filepath has been updated.\n";
456 # Read config.nmake, then write it back out with an updated
458 sub update_config_nmake
463 my $filepath = "$srcdir/config.nmake";
464 my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
466 if ($package_string ne "") { $win_package_string = $package_string; }
469 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
470 while ($line = <CFGNMAKE>) {
471 if ($line =~ /^VCS_REVISION=.*([\r\n]+)$/) {
472 $line = sprintf("VCS_REVISION=%d$1", $num_commits);
473 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
474 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
475 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
476 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
477 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
478 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
479 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
480 $line = "VERSION_EXTRA=$win_package_string$1";
485 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
486 print(CFGNMAKE $contents);
488 print "$filepath has been updated.\n";
491 # Read docbook/asciidoc.conf, then write it back out with an updated
492 # wireshark-version replacement line.
493 sub update_release_notes
498 my $filepath = "$srcdir/docbook/asciidoc.conf";
500 return if (!$set_version);
502 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
503 while ($line = <ADOC_CONF>) {
504 # wireshark-version:\[\]=1.9.1
506 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
507 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
508 $version_pref{"version_major"},
509 $version_pref{"version_minor"},
510 $version_pref{"version_micro"},
516 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
517 print(ADOC_CONF $contents);
519 print "$filepath has been updated.\n";
522 # Read debian/changelog, then write back out an updated version.
523 sub update_debian_changelog
528 my $filepath = "$srcdir/debian/changelog";
530 return if ($set_version == 0);
532 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
533 while ($line = <CHANGELOG>) {
534 if ($set_version && CHANGELOG->input_line_number() == 1) {
535 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
536 $version_pref{"version_major"},
537 $version_pref{"version_minor"},
538 $version_pref{"version_micro"},
544 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
545 print(CHANGELOG $contents);
547 print "$filepath has been updated.\n";
550 # Read Makefile.am for each library, then write back out an updated version.
551 sub update_automake_lib_releases
559 return if (!$set_version);
561 # The Libtool manual says
562 # "If the library source code has changed at all since the last
563 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
564 # epan changes with each minor release, almost by definition. wiretap
565 # changes with *most* releases.
567 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
568 for $filedir ("epan", "wiretap") { # "wsutil"
570 $filepath = $filedir . "/Makefile.am";
571 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
572 while ($line = <MAKEFILE_AM>) {
573 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
575 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
576 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
581 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
582 print(MAKEFILE_AM $contents);
584 print "$filepath has been updated.\n";
588 # Read CMakeLists.txt for each library, then write back out an updated version.
589 sub update_cmake_lib_releases
597 return if (!$set_version);
599 for $filedir ("epan", "wiretap") { # "wsutil"
601 $filepath = $filedir . "/CMakeLists.txt";
602 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
603 while ($line = <CMAKELISTS_TXT>) {
604 # set(FULL_SO_VERSION "0.0.0")
606 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
607 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
612 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
613 print(CMAKELISTS_TXT $contents);
614 close(CMAKELISTS_TXT);
615 print "$filepath has been updated.\n";
619 # Update distributed files that contain any version information
620 sub update_versioned_files
622 &update_cmakelists_txt;
623 &update_configure_ac;
624 &update_config_nmake;
625 &update_release_notes;
626 &update_debian_changelog;
627 &update_automake_lib_releases;
628 &update_cmake_lib_releases;
635 if ($git_description) {
636 $VCS_REVISION = "#define VCSVERSION \"" .
637 $git_description . "\"\n" .
638 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
639 } elsif ($last_change && $num_commits) {
640 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name . " Rev " .
641 $num_commits . "\"\n" .
642 "#define VCSBRANCH \"" . $repo_branch . "\"\n";
644 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name .
646 "#define VCSBRANCH \"unknown\"\n";
649 return $VCS_REVISION;
652 # Print the version control system's version to $version_file.
653 # Don't change the file if it is not needed.
654 sub print_VCS_REVISION
656 my $VCS_REVISION = new_version_h();
657 my $needs_update = 1;
658 if (open(OLDREV, "<$version_file")) {
659 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
660 if ($old_VCS_REVISION eq $VCS_REVISION) {
666 if (! $set_vcs) { return; }
669 # print "Updating $version_file so it contains:\n$VCS_REVISION";
670 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
671 print VER "$VCS_REVISION";
673 print "$version_file has been updated.\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 "print-vcs", \$print_vcs,
691 "set-version|v", \$set_version,
692 "set-release|r|package-version|p", \$set_release
695 if ($show_help) { pod2usage(1); }
697 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
705 if (! open(FILE, "<$vconf_file")) {
706 print STDERR "Version configuration file $vconf_file not "
707 . "found. Using defaults.\n";
712 s/^\s+|\s+$//g; # chomp() may not handle CR
714 next unless (/^(\w+)(:|=)\s*(\S.*)/);
715 $version_pref{$1} = $3;
731 if ($set_version || $set_release) {
733 print "Generating version information\n";
736 if ($version_pref{"enable"} == 0) {
737 print "Release information disabled in $vconf_file.\n";
742 print "Generating release information\n";
744 print "Resetting release information\n";
746 $package_string = "";
749 &update_versioned_files;
756 make-version.pl - Get and set build-time version information for Wireshark
760 make-version.pl [options] [source directory]
764 --help, -h This help message
765 --get-vcs, -g Print the VCS revision and source.
766 --set-vcs, -s Set the information in version.h
767 --print-vcs Print the vcs version to standard output
768 --set-version, -v Set the major, minor, and micro versions in
769 configure.ac, config.nmake, debian/changelog,
770 and docbook/asciidoc.conf.
771 Resets the release information when used by
773 --set-release, -r Set the release information in configure.ac
775 --package-version, -p Deprecated. Same as --set-release.
777 Options can be used in any combination. If none are specified B<--set-svn>
783 # Editor modelines - http://www.wireshark.org/tools/modelines.html
788 # indent-tabs-mode: t
791 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
792 # :indentSize=8:tabSize=8:noTabs=false: