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;
83 "version_minor" => 99,
88 "git_client" => 0, # set if .git found and .git/svn not found
91 "format" => "git %Y%m%d%H%M%S",
93 # Normal development builds
95 "pkg_format" => "-%#",
97 # Development releases
104 # Ensure we run with correct locale
107 $ENV{GIT_PAGER} = "";
109 # Attempt to get revision information from the repository.
112 my $version_format = $version_pref{"format"};
113 my $package_format = "";
117 my $repo_root = undef;
118 my $repo_url = undef;
120 my $info_source = "Unknown";
122 if ($version_pref{"pkg_enable"} > 0) {
123 $package_format = $version_pref{"pkg_format"};
126 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
127 $info_source = "Command line (git)";
128 $version_pref{"git_client"} = 1;
129 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
130 $info_source = "Command line (svn info)";
131 $info_cmd = "svn info $srcdir";
132 } elsif (-d "$srcdir/.git/svn") {
133 $info_source = "Command line (git-svn)";
134 $info_cmd = "(cd $srcdir; git svn info)";
139 # A big ugly hash: git rev-parse HEAD
140 # 1ddc83849075addb0cac69a6fe3782f4325337b9
142 # A small ugly hash: git rev-parse --short HEAD
145 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
148 # A version description: git describe --tags --dirty
149 # wireshark-1.8.12-15-g1ddc838
151 # Number of commits in this branch: git rev-list --count HEAD
154 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
157 # Refs: git ls-remote code.wireshark.org:wireshark
158 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
160 if ($version_pref{"git_client"}) {
165 chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
166 if ($? == 0 && length($line) > 1) {
167 $last_change = $line;
170 # Commits since last annotated tag.
171 chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always --match "v*"});
172 if ($? == 0 && length($line) > 1) {
173 my @parts = split(/-/, $line);
174 $git_description = $line;
175 $num_commits = $parts[-2];
176 $commit_id = $parts[-1];
179 chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
180 if (defined($line)) {
184 # This will break in some cases. Hopefully not during
185 # official package builds.
186 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
187 if ($? == 0 && length($line) > 1) {
188 $repo_branch = basename($line);
194 if ($last_change && $num_commits && $repo_url && $repo_branch) {
197 } elsif ($version_pref{"svn_client"}) {
201 $line = qx{$info_cmd};
202 if (defined($line)) {
203 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
204 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
206 if ($line =~ /Last Changed Rev: (\d+)/) {
209 if ($line =~ /URL: (\S+)/) {
212 if ($line =~ /Repository Root: (\S+)/) {
220 if ($last_change && $num_commits && $repo_url && $repo_root) {
223 } elsif ($version_pref{"tortoise_svn"}) {
224 # Dynamically generic template file needed by TortoiseSVN
225 open(TORTOISE, ">$tortoise_file");
226 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
227 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
230 $info_source = "Command line (SubWCRev)";
231 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
232 my $tortoise = system($info_cmd);
233 if ($tortoise == 0) {
238 #clean up the template file
239 unlink($tortoise_file);
242 if ($num_commits == 0) {
243 # Fall back to config.nmake
244 $info_source = "Prodding config.nmake";
245 my $filepath = "$srcdir/config.nmake";
246 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
247 while ($line = <CFGNMAKE>) {
248 if ($line =~ /^VCS_REVISION=(\d+)/) {
256 if ($num_commits == 0 and -d "$srcdir/.git") {
262 # If someone had properly tagged 1.9.0 we could also use
263 # "git describe --abbrev=1 --tags HEAD"
265 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
266 $line = qx{$info_cmd};
267 if (defined($line)) {
268 if ($line =~ /svn path=.*; revision=(\d+)/) {
272 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
273 $line = qx{$info_cmd};
274 if (defined($line)) {
275 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
276 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
279 $info_cmd = "(cd $srcdir; git branch)";
280 $line = qx{$info_cmd};
281 if (defined($line)) {
282 if ($line =~ /\* (\S+)/) {
289 if ($num_commits == 0 and -d "$srcdir/.bzr") {
295 $info_cmd = "(cd $srcdir; bzr log -l 1)";
296 $line = qx{$info_cmd};
297 if (defined($line)) {
298 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
299 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
301 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
312 # 'svn info' failed or the user really wants us to dig around in .svn/entries
314 # Start of ugly internal SVN file hack
315 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
316 print ("Unable to open $srcdir/.svn/entries\n");
318 $info_source = "Prodding .svn";
319 # We need to find out whether our parser can handle the entries file
322 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
323 $repo_version = "pre1.4";
324 } elsif ($line =~ /^8$/) {
325 $repo_version = "1.4";
327 $repo_version = "unknown";
330 if ($repo_version eq "pre1.4") {
331 # The entries schema is flat, so we can use regexes to parse its contents.
332 while ($line = <ENTRIES>) {
333 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
338 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
339 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
340 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
342 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
344 if ($line =~ /\/>/) {
345 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
346 $last_change && $num_commits) {
351 # XXX - Fetch the repository root & URL
358 # If we picked up the revision and modification time,
359 # generate our strings.
360 if ($version_pref{"pkg_enable"}) {
361 $version_format =~ s/%#/$num_commits/;
362 $package_format =~ s/%#/$num_commits-$commit_id/;
363 $package_string = strftime($package_format, gmtime($last_change));
366 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
367 $repo_branch = substr($repo_url, length($repo_root));
372 Commit distance : $num_commits
373 Commit ID : $commit_id
374 Revision source : $info_source
375 Release stamp : $package_string
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";
394 my $cmake_package_string = "\$ENV{WIRESHARK_VERSION_EXTRA}";
396 if ($package_string ne "") { $cmake_package_string = $package_string; }
398 return if (!$set_version && $package_string eq "");
400 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
401 while ($line = <CFGIN>) {
402 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
403 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
404 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
405 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
406 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
407 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
408 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
409 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
410 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
411 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $cmake_package_string);
416 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
417 print(CFGIN $contents);
419 print "$filepath has been updated.\n";
422 # Read configure.ac, then write it back out with an updated
424 sub update_configure_ac
429 my $filepath = "$srcdir/configure.ac";
431 return if (!$set_version && $package_string eq "");
433 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
434 while ($line = <CFGIN>) {
435 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
436 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
437 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
438 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
439 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
440 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
441 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
442 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
447 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
448 print(CFGIN $contents);
450 print "$filepath has been updated.\n";
453 # Read config.nmake, then write it back out with an updated
455 sub update_config_nmake
460 my $filepath = "$srcdir/config.nmake";
461 my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
463 if ($package_string ne "") { $win_package_string = $package_string; }
466 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
467 while ($line = <CFGNMAKE>) {
468 if ($line =~ /^VCS_REVISION=.*([\r\n]+)$/) {
469 $line = sprintf("VCS_REVISION=%d$1", $num_commits);
470 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
471 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
472 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
473 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
474 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
475 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
476 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
477 $line = "VERSION_EXTRA=$win_package_string$1";
482 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
483 print(CFGNMAKE $contents);
485 print "$filepath has been updated.\n";
488 # Read docbook/asciidoc.conf, then write it back out with an updated
489 # wireshark-version replacement line.
490 sub update_release_notes
495 my $filepath = "$srcdir/docbook/asciidoc.conf";
497 return if (!$set_version);
499 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
500 while ($line = <ADOC_CONF>) {
501 # wireshark-version:\[\]=1.9.1
503 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
504 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
505 $version_pref{"version_major"},
506 $version_pref{"version_minor"},
507 $version_pref{"version_micro"},
513 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
514 print(ADOC_CONF $contents);
516 print "$filepath has been updated.\n";
519 # Read debian/changelog, then write back out an updated version.
520 sub update_debian_changelog
525 my $filepath = "$srcdir/debian/changelog";
527 return if ($set_version == 0);
529 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
530 while ($line = <CHANGELOG>) {
531 if ($set_version && CHANGELOG->input_line_number() == 1) {
532 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
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 return if (!$set_version);
558 # The Libtool manual says
559 # "If the library source code has changed at all since the last
560 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
561 # epan changes with each minor release, almost by definition. wiretap
562 # changes with *most* releases.
564 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
565 for $filedir ("epan", "wiretap") { # "wsutil"
567 $filepath = $filedir . "/Makefile.am";
568 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
569 while ($line = <MAKEFILE_AM>) {
570 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
572 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
573 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
578 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
579 print(MAKEFILE_AM $contents);
581 print "$filepath has been updated.\n";
585 # Read CMakeLists.txt for each library, then write back out an updated version.
586 sub update_cmake_lib_releases
594 return if (!$set_version);
596 for $filedir ("epan", "wiretap") { # "wsutil"
598 $filepath = $filedir . "/CMakeLists.txt";
599 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
600 while ($line = <CMAKELISTS_TXT>) {
601 # set(FULL_SO_VERSION "0.0.0")
603 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
604 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
609 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
610 print(CMAKELISTS_TXT $contents);
611 close(CMAKELISTS_TXT);
612 print "$filepath has been updated.\n";
616 # Update distributed files that contain any version information
617 sub update_versioned_files
619 &update_cmakelists_txt;
620 &update_configure_ac;
621 &update_config_nmake;
622 &update_release_notes;
623 &update_debian_changelog;
624 &update_automake_lib_releases;
625 &update_cmake_lib_releases;
628 # Print the version control system's version to $version_file.
629 # Don't change the file if it is not needed.
630 sub print_VCS_REVISION
633 my $needs_update = 1;
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";
648 if (open(OLDREV, "<$version_file")) {
649 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
650 if ($old_VCS_REVISION eq $VCS_REVISION) {
656 if (! $set_vcs) { return; }
659 # print "Updating $version_file so it contains:\n$VCS_REVISION";
660 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
661 print VER "$VCS_REVISION";
663 print "$version_file has been updated.\n";
665 print "$version_file unchanged.\n";
669 # Read values from the configuration file, if it exists.
674 # Get our command-line args
675 # XXX - Do we need an option to undo --set-release?
677 "help|h", \$show_help,
678 "get-vcs|get-svn|g", \$get_vcs,
679 "set-vcs|set-svn|s", \$set_vcs,
680 "set-version|v", \$set_version,
681 "set-release|r|package-version|p", \$set_release
684 if ($show_help) { pod2usage(1); }
686 if ( !( $show_help || $get_vcs || $set_vcs || $set_version || $set_release ) ) {
694 if (! open(FILE, "<$vconf_file")) {
695 print STDERR "Version configuration file $vconf_file not "
696 . "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 --set-version, -v Set the major, minor, and micro versions in
757 configure.ac, config.nmake, debian/changelog,
758 and docbook/asciidoc.conf.
759 Resets the release information when used by
761 --set-release, -r Set the release information in configure.ac
763 --package-version, -p Deprecated. Same as --set-release.
765 Options can be used in any combination. If none are specified B<--set-svn>
771 # Editor modelines - http://www.wireshark.org/tools/modelines.html
776 # indent-tabs-mode: t
779 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
780 # :indentSize=8:tabSize=8:noTabs=false: