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 SVN revision number.
36 # pkg_enable - Enable or disable local package versioning.
37 # pkg_format - Like "format", but used for the local package version.
39 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
40 # configure.ac and the VERSION macro in config.nmake will have the
41 # pkg_format template appended to the version number. version.h will
42 # _not_ be generated if either argument is present.
44 # Default configuration:
49 # format: git %Y%m%d%H%M%S
53 # XXX - We're pretty dumb about the "%#" substitution, and about having
54 # spaces in the package format.
60 use POSIX qw(strftime);
66 my $version_file = 'version.h';
67 my $package_string = "";
68 my $vconf_file = 'version.conf';
69 my $tortoise_file = "tortoise_template";
73 my $repo_branch = "unknown";
74 my $git_description = undef;
81 "version_minor" => 99,
86 "git_client" => 0, # set if .git found and .git/svn not found
89 "format" => "git %Y%m%d%H%M%S",
92 # Normal development builds
94 "pkg_format" => "-%#",
96 # Development releases
103 # Ensure we run with correct locale
106 $ENV{GIT_PAGER} = "";
108 # Run "svn info". Parse out the most recent modification time and the
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+)/) {
219 if ($last_change && $num_commits && $repo_url && $repo_root) {
222 } elsif ($version_pref{"tortoise_svn"}) {
223 # Dynamically generic template file needed by TortoiseSVN
224 open(TORTOISE, ">$tortoise_file");
225 print TORTOISE "#define GITVERSION \"\$WCREV\$\"\r\n";
226 print TORTOISE "#define GITBRANCH \"\$WCURL\$\"\r\n";
229 $info_source = "Command line (SubWCRev)";
230 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
231 my $tortoise = system($info_cmd);
232 if ($tortoise == 0) {
236 #clean up the template file
237 unlink($tortoise_file);
240 if ($num_commits == 0) {
241 # Fall back to config.nmake
242 $info_source = "Prodding config.nmake";
243 my $filepath = "$srcdir/config.nmake";
244 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
245 while ($line = <CFGNMAKE>) {
246 if ($line =~ /^GIT_REVISION=(\d+)/) {
254 if ($num_commits == 0 and -d "$srcdir/.git") {
260 # If someone had properly tagged 1.9.0 we could also use
261 # "git describe --abbrev=1 --tags HEAD"
263 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
264 $line = qx{$info_cmd};
265 if (defined($line)) {
266 if ($line =~ /svn path=.*; revision=(\d+)/) {
270 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
271 $line = qx{$info_cmd};
272 if (defined($line)) {
273 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
274 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
277 $info_cmd = "(cd $srcdir; git branch)";
278 $line = qx{$info_cmd};
279 if (defined($line)) {
280 if ($line =~ /\* (\S+)/) {
287 if ($num_commits == 0 and -d "$srcdir/.bzr") {
293 $info_cmd = "(cd $srcdir; bzr log -l 1)";
294 $line = qx{$info_cmd};
295 if (defined($line)) {
296 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
297 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
299 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
309 # 'svn info' failed or the user really wants us to dig around in .svn/entries
311 # Start of ugly internal SVN file hack
312 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
313 print ("Unable to open $srcdir/.svn/entries\n");
315 $info_source = "Prodding .svn";
316 # We need to find out whether our parser can handle the entries file
319 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
320 $repo_version = "pre1.4";
321 } elsif ($line =~ /^8$/) {
322 $repo_version = "1.4";
324 $repo_version = "unknown";
327 if ($repo_version eq "pre1.4") {
328 # The entries schema is flat, so we can use regexes to parse its contents.
329 while ($line = <ENTRIES>) {
330 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
335 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
336 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
337 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
339 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
341 if ($line =~ /\/>/) {
342 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
343 $last_change && $num_commits) {
348 # XXX - Fetch the repository root & URL
355 # If we picked up the revision and modification time,
356 # generate our strings.
357 if ($version_pref{"pkg_enable"}) {
358 $version_format =~ s/%#/$num_commits/;
359 $package_format =~ s/%#/$num_commits-$commit_id/;
360 $package_string = strftime($package_format, gmtime($last_change));
363 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
364 $repo_branch = substr($repo_url, length($repo_root));
369 Commit distance : $num_commits
370 Commit ID : $commit_id
371 Revision source : $info_source
372 Release stamp : $package_string
378 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
380 # set(PROJECT_MAJOR_VERSION 1)
381 # set(PROJECT_MINOR_VERSION 99)
382 # set(PROJECT_PATCH_VERSION 0)
383 # set(PROJECT_VERSION_EXTENSION "-rc5")
384 sub update_cmakelists_txt
389 my $filepath = "$srcdir/CMakeLists.txt";
391 return if (!$set_version && $package_string eq "");
393 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
394 while ($line = <CFGIN>) {
395 if ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
396 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
397 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
398 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
399 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
400 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
401 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
402 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
407 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
408 print(CFGIN $contents);
410 print "$filepath has been updated.\n";
413 # Read configure.ac, then write it back out with an updated
415 sub update_configure_ac
420 my $filepath = "$srcdir/configure.ac";
422 return if (!$set_version && $package_string eq "");
424 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
425 while ($line = <CFGIN>) {
426 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
427 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
428 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
429 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
430 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
431 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
432 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
433 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
438 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
439 print(CFGIN $contents);
441 print "$filepath has been updated.\n";
444 # Read config.nmake, then write it back out with an updated
446 sub update_config_nmake
451 my $filepath = "$srcdir/config.nmake";
452 my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
454 if ($package_string ne "") { $win_package_string = $package_string; }
457 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
458 while ($line = <CFGNMAKE>) {
459 if ($line =~ /^GIT_REVISION=.*([\r\n]+)$/) {
460 $line = sprintf("GIT_REVISION=%d$1", $num_commits);
461 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
462 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
463 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
464 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
465 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
466 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
467 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
468 $line = "VERSION_EXTRA=$win_package_string$1";
473 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
474 print(CFGNMAKE $contents);
476 print "$filepath has been updated.\n";
479 # Read docbook/asciidoc.conf, then write it back out with an updated
480 # wireshark-version replacement line.
481 sub update_release_notes
486 my $filepath = "$srcdir/docbook/asciidoc.conf";
488 return if (!$set_version);
490 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
491 while ($line = <ADOC_CONF>) {
492 # wireshark-version:\[\]=1.9.1
494 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
495 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
496 $version_pref{"version_major"},
497 $version_pref{"version_minor"},
498 $version_pref{"version_micro"},
504 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
505 print(ADOC_CONF $contents);
507 print "$filepath has been updated.\n";
510 # Read debian/changelog, then write back out an updated version.
511 sub update_debian_changelog
516 my $filepath = "$srcdir/debian/changelog";
518 return if ($set_version == 0);
520 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
521 while ($line = <CHANGELOG>) {
522 if ($set_version && CHANGELOG->input_line_number() == 1) {
523 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
524 $version_pref{"version_major"},
525 $version_pref{"version_minor"},
526 $version_pref{"version_micro"},
532 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
533 print(CHANGELOG $contents);
535 print "$filepath has been updated.\n";
538 # Read Makefile.am for each library, then write back out an updated version.
539 sub update_lib_releases
547 return if (!$set_version);
549 # The Libtool manual says
550 # "If the library source code has changed at all since the last
551 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
552 # epan changes with each minor release, almost by definition. wiretap
553 # changes with *most* releases.
555 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
556 for $filedir ("epan", "wiretap") { # "wsutil"
558 $filepath = $filedir . "/Makefile.am";
559 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
560 while ($line = <MAKEFILE_AM>) {
561 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
563 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
564 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
569 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
570 print(MAKEFILE_AM $contents);
572 print "$filepath has been updated.\n";
576 # Update distributed files that contain any version information
577 sub update_versioned_files
579 &update_cmakelists_txt;
580 &update_configure_ac;
581 &update_config_nmake;
582 &update_release_notes;
583 &update_debian_changelog;
584 &update_lib_releases;
587 # Print the version control system's version to $version_file.
588 # Don't change the file if it is not needed.
589 sub print_GIT_REVISION
592 my $needs_update = 1;
594 if ($git_description) {
595 $GIT_REVISION = "#define GITVERSION \"" .
596 $git_description . "\"\n" .
597 "#define GITBRANCH \"" . $repo_branch . "\"\n";
598 } elsif ($last_change && $num_commits) {
599 $GIT_REVISION = "#define GITVERSION \"Git Rev " .
600 $num_commits . "\"\n" .
601 "#define GITBRANCH \"" . $repo_branch . "\"\n";
603 $GIT_REVISION = "#define GITVERSION \"Git Rev Unknown\"\n" .
604 "#define GITBRANCH \"unknown\"\n";
606 if (open(OLDREV, "<$version_file")) {
607 my $old_GIT_REVISION = <OLDREV> . <OLDREV>;
608 if ($old_GIT_REVISION eq $GIT_REVISION) {
614 if (! $set_svn) { return; }
617 # print "Updating $version_file so it contains:\n$GIT_REVISION";
618 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
619 print VER "$GIT_REVISION";
621 print "$version_file has been updated.\n";
623 print "$version_file unchanged.\n";
627 # Read values from the configuration file, if it exists.
632 # Get our command-line args
633 # XXX - Do we need an option to undo --set-release?
635 "help|h", \$show_help,
636 "get-svn|g", \$get_svn,
637 "set-svn|s", \$set_svn,
638 "set-version|v", \$set_version,
639 "set-release|r|package-version|p", \$set_release
642 if ($show_help) { pod2usage(1); }
644 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
652 if (! open(FILE, "<$vconf_file")) {
653 print STDERR "Version configuration file $vconf_file not "
654 . "found. Using defaults.\n";
659 s/^\s+|\s+$//g; # chomp() may not handle CR
661 next unless (/^(\w+)(:|=)\s*(\S.*)/);
662 $version_pref{$1} = $3;
678 if ($set_version || $set_release) {
680 print "Generating version information\n";
683 if ($version_pref{"enable"} == 0) {
684 print "Release information disabled in $vconf_file.\n";
689 print "Generating release information\n";
691 print "Resetting release information\n";
693 $package_string = "";
696 &update_versioned_files;
703 make-version.pl - Get and set build-time version information for Wireshark
707 make-version.pl [options] [source directory]
711 --help, -h This help message
712 --get-svn, -g Print the SVN revision and source.
713 --set-svn, -s Set the information in version.h
714 --set-version, -v Set the major, minor, and micro versions in
715 configure.ac, config.nmake, debian/changelog,
716 and docbook/asciidoc.conf.
717 Resets the release information when used by
719 --set-release, -r Set the release information in configure.ac
721 --package-version, -p Deprecated. Same as --set-release.
723 Options can be used in any combination. If none are specified B<--set-svn>
729 # Editor modelines - http://www.wireshark.org/tools/modelines.html
734 # indent-tabs-mode: t
737 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
738 # :indentSize=8:tabSize=8:noTabs=false: