3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 1998 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 # If "version.conf" is present, it is parsed for configuration values.
28 # Possible values are:
30 # enable - Enable or disable versioning. Zero (0) disables, nonzero
32 # svn_client - Use svn client i.s.o. ugly internal SVN file hack
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:
48 # format: SVN %Y%m%d%H%M%S
52 # XXX - We're pretty dumb about the "%#" substitution, and about having
53 # spaces in the package format.
59 use POSIX qw(strftime);
65 my $version_file = 'version.h';
66 my $package_string = "";
67 my $vconf_file = 'version.conf';
68 my $tortoise_file = "tortoise_template";
72 my $repo_branch = "unknown";
73 my $git_description = undef;
80 "version_minor" => 11,
88 "format" => "git %Y%m%d%H%M%S",
91 # Normal development builds
93 "pkg_format" => "-%#",
95 # Development releases
102 # Ensure we run with correct locale
105 $ENV{GIT_PAGER} = "";
107 # Run "svn info". Parse out the most recent modification time and the
111 my $version_format = $version_pref{"format"};
112 my $package_format = "";
116 my $repo_root = undef;
117 my $repo_url = undef;
119 my $info_source = "Unknown";
121 if ($version_pref{"pkg_enable"}) {
122 $package_format = $version_pref{"pkg_format"};
125 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
126 $info_source = "Command line (git)";
127 $version_pref{"git_client"} = 1;
128 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
129 $info_source = "Command line (svn info)";
130 $info_cmd = "svn info $srcdir";
131 } elsif (-d "$srcdir/.git/svn") {
132 $info_source = "Command line (git-svn)";
133 $info_cmd = "(cd $srcdir; git svn info)";
138 # A big ugly hash: git rev-parse HEAD
139 # 1ddc83849075addb0cac69a6fe3782f4325337b9
141 # A small ugly hash: git rev-parse --short HEAD
144 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name origin
147 # A version description: git describe --tags --dirty
148 # wireshark-1.8.12-15-g1ddc838
150 # Number of commits in this branch: git rev-list --count HEAD
153 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
156 # Refs: git ls-remote code.wireshark.org:wireshark
157 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
159 if ($version_pref{"git_client"}) {
164 chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
165 if ($? == 0 && length($line) > 1) {
166 $last_change = $line;
169 # Commits since last annotated tag.
170 chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always});
171 if ($? == 0 && length($line) > 1) {
172 my @parts = split(/-/, $line);
173 $num_commits = $parts[-2];
174 $commit_id = $parts[-1];
177 # Current short hash prefixed with "g"
178 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --short HEAD});
179 if ($? == 0 && length($line) > 1) {
182 chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
183 if ($? == 0 && length($line) > 1) {
187 # Probably not quite what we're looking for
188 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name origin});
189 if ($? == 0 && length($line) > 1) {
190 $repo_branch = basename($line);
193 chomp($line = qx{git --git-dir=$srcdir/.git describe --dirty --match "v*"});
194 if ($? == 0 && length($line) > 1) {
195 $git_description = "wireshark-" . substr($line, 1);
201 if ($last_change && $num_commits && $repo_url && $repo_branch) {
204 } elsif ($version_pref{"svn_client"}) {
208 $line = qx{$info_cmd};
209 if (defined($line)) {
210 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
211 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
213 if ($line =~ /Last Changed Rev: (\d+)/) {
216 if ($line =~ /URL: (\S+)/) {
219 if ($line =~ /Repository Root: (\S+)/) {
226 if ($last_change && $num_commits && $repo_url && $repo_root) {
229 } elsif ($version_pref{"tortoise_svn"}) {
230 # Dynamically generic template file needed by TortoiseSVN
231 open(TORTOISE, ">$tortoise_file");
232 print TORTOISE "#define GITVERSION \"\$WCREV\$\"\r\n";
233 print TORTOISE "#define GITBRANCH \"\$WCURL\$\"\r\n";
236 $info_source = "Command line (SubWCRev)";
237 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
238 my $tortoise = system($info_cmd);
239 if ($tortoise == 0) {
243 #clean up the template file
244 unlink($tortoise_file);
247 if ($num_commits == 0) {
248 # Fall back to config.nmake
249 $info_source = "Prodding config.nmake";
250 my $filepath = "$srcdir/config.nmake";
251 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
252 while ($line = <CFGNMAKE>) {
253 if ($line =~ /^GIT_REVISION=(\d+)/) {
261 if ($num_commits == 0 and -d "$srcdir/.git") {
267 # If someone had properly tagged 1.9.0 we could also use
268 # "git describe --abbrev=1 --tags HEAD"
270 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
271 $line = qx{$info_cmd};
272 if (defined($line)) {
273 if ($line =~ /svn path=.*; revision=(\d+)/) {
277 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
278 $line = qx{$info_cmd};
279 if (defined($line)) {
280 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
281 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
284 $info_cmd = "(cd $srcdir; git branch)";
285 $line = qx{$info_cmd};
286 if (defined($line)) {
287 if ($line =~ /\* (\S+)/) {
294 if ($num_commits == 0 and -d "$srcdir/.bzr") {
300 $info_cmd = "(cd $srcdir; bzr log -l 1)";
301 $line = qx{$info_cmd};
302 if (defined($line)) {
303 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
304 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
306 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
316 # 'svn info' failed or the user really wants us to dig around in .svn/entries
318 # Start of ugly internal SVN file hack
319 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
320 print ("Unable to open $srcdir/.svn/entries\n");
322 $info_source = "Prodding .svn";
323 # We need to find out whether our parser can handle the entries file
326 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
327 $repo_version = "pre1.4";
328 } elsif ($line =~ /^8$/) {
329 $repo_version = "1.4";
331 $repo_version = "unknown";
334 if ($repo_version eq "pre1.4") {
335 # The entries schema is flat, so we can use regexes to parse its contents.
336 while ($line = <ENTRIES>) {
337 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
342 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
343 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
344 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
346 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
348 if ($line =~ /\/>/) {
349 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
350 $last_change && $num_commits) {
355 # XXX - Fetch the repository root & URL
362 # If we picked up the revision and modification time,
363 # generate our strings.
364 if ($num_commits && $last_change) {
365 $version_format =~ s/%#/$num_commits/;
366 $package_format =~ s/%#/$num_commits-$commit_id/;
367 $package_string = strftime($package_format, gmtime($last_change));
370 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
371 $repo_branch = substr($repo_url, length($repo_root));
376 Commit distance : $num_commits
377 Commit ID : $commit_id
378 Revision source : $info_source
379 Release stamp : $package_string
385 # Read configure.ac, then write it back out with an updated
387 sub update_configure_ac
392 my $filepath = "$srcdir/configure.ac";
394 return if (!$set_version && $package_string eq "");
396 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
397 while ($line = <CFGIN>) {
398 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
399 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
400 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
401 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
402 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
403 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
404 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
405 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
410 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
411 print(CFGIN $contents);
413 print "$filepath has been updated.\n";
416 # Read config.nmake, then write it back out with an updated
418 sub update_config_nmake
423 my $filepath = "$srcdir/config.nmake";
425 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
426 while ($line = <CFGNMAKE>) {
427 if ($line =~ /^GIT_REVISION=.*([\r\n]+)$/) {
428 $line = sprintf("GIT_REVISION=%d$1", $num_commits);
429 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
430 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
431 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
432 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
433 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
434 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
435 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
436 $line = "VERSION_EXTRA=$package_string$1";
441 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
442 print(CFGNMAKE $contents);
444 print "$filepath has been updated.\n";
447 # Read docbook/asciidoc.conf, then write it back out with an updated
448 # wireshark-version replacement line.
449 sub update_release_notes
454 my $filepath = "$srcdir/docbook/asciidoc.conf";
456 return if (!$set_version);
458 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
459 while ($line = <ADOC_CONF>) {
460 # wireshark-version:\[\]=1.9.1
462 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
463 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
464 $version_pref{"version_major"},
465 $version_pref{"version_minor"},
466 $version_pref{"version_micro"},
472 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
473 print(ADOC_CONF $contents);
475 print "$filepath has been updated.\n";
478 # Read debian/changelog, then write back out an updated version.
479 sub update_debian_changelog
484 my $filepath = "$srcdir/debian/changelog";
486 return if ($set_version == 0);
488 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
489 while ($line = <CHANGELOG>) {
490 if ($set_version && CHANGELOG->input_line_number() == 1) {
491 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
492 $version_pref{"version_major"},
493 $version_pref{"version_minor"},
494 $version_pref{"version_micro"},
500 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
501 print(CHANGELOG $contents);
503 print "$filepath has been updated.\n";
506 # Read debian/wireshark-common.files, then write back out an updated version.
507 # The libraries updated here MUST match the updates made by update_lib_releases
508 # below. We should do this automatically.
509 sub update_debian_wcf
514 my $filepath = "$srcdir/debian/wireshark-common.files";
516 return if (!$set_version);
518 open(DWCF, "< $filepath") || die "Can't read $filepath!";
519 while ($line = <DWCF>) {
520 # /usr/lib/wireshark/libwireshark.so.1.1.0
522 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap|filetap).so\.\d+\.\d+\.)\d+$}) {
523 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
528 open(DWCF, "> $filepath") || die "Can't write $filepath!";
529 print(DWCF $contents);
531 print "$filepath has been updated.\n";
534 # Read Makefile.am for each library, then write back out an updated version.
535 sub update_lib_releases
543 return if (!$set_version);
545 # The Libtool manual says
546 # "If the library source code has changed at all since the last
547 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
548 # epan changes with each minor release, almost by definition. wiretap
549 # and filetap changes with *most* releases.
551 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
552 for $filedir ("epan", "wiretap", "filetap") { # "wsutil"
554 $filepath = $filedir . "/Makefile.am";
555 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
556 while ($line = <MAKEFILE_AM>) {
557 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
559 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
560 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
565 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
566 print(MAKEFILE_AM $contents);
568 print "$filepath has been updated.\n";
572 # Update distributed files that contain any version information
573 sub update_versioned_files
575 &update_configure_ac;
576 &update_config_nmake;
577 &update_release_notes;
578 &update_debian_changelog;
580 &update_lib_releases;
583 # Print the SVN version to $version_file.
584 # Don't change the file if it is not needed.
585 sub print_GIT_REVISION
588 my $needs_update = 1;
590 if ($git_description) {
591 $GIT_REVISION = "#define GITVERSION \"" .
592 $git_description . "\"\n" .
593 "#define GITBRANCH \"" . $repo_branch . "\"\n";
594 } elsif ($last_change && $num_commits) {
595 $GIT_REVISION = "#define GITVERSION \"Git Rev " .
596 $num_commits . "\"\n" .
597 "#define GITBRANCH \"" . $repo_branch . "\"\n";
599 $GIT_REVISION = "#define GITVERSION \"Git Rev Unknown\"\n" .
600 "#define GITBRANCH \"unknown\"\n";
602 if (open(OLDREV, "<$version_file")) {
603 my $old_GIT_REVISION = <OLDREV> . <OLDREV>;
604 if ($old_GIT_REVISION eq $GIT_REVISION) {
610 if (! $set_svn) { return; }
613 # print "Updating $version_file so it contains:\n$GIT_REVISION";
614 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
615 print VER "$GIT_REVISION";
617 print "$version_file has been updated.\n";
619 print "$version_file unchanged.\n";
623 # Read values from the configuration file, if it exists.
628 # Get our command-line args
629 # XXX - Do we need an option to undo --set-release?
631 "help|h", \$show_help,
632 "get-svn|g", \$get_svn,
633 "set-svn|s", \$set_svn,
634 "set-version|v", \$set_version,
635 "set-release|r|package-version|p", \$set_release
638 if ($show_help) { pod2usage(1); }
640 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
648 if (! open(FILE, "<$vconf_file")) {
649 print STDERR "Version configuration file $vconf_file not "
650 . "found. Using defaults.\n";
657 next unless (/^(\w+)(:|=)\s*(\S.*)/);
658 $version_pref{$1} = $3;
674 if ($set_version || $set_release) {
676 print "Generating version information\n";
679 if ($version_pref{"enable"} == 0) {
680 print "Release information disabled in $vconf_file.\n";
685 print "Generating release information\n";
687 print "Resetting release information\n";
689 $package_string = "";
692 &update_versioned_files;
699 make-version.pl - Get and set build-time version information for Wireshark
703 make-version.pl [options] [source directory]
707 --help, -h This help message
708 --get-svn, -g Print the SVN revision and source.
709 --set-svn, -s Set the information in version.h
710 --set-version, -v Set the major, minor, and micro versions in
711 configure.ac, config.nmake, debian/changelog,
712 and docbook/asciidoc.conf.
713 Resets the release information when used by
715 --set-release, -r Set the release information in configure.ac
717 --package-version, -p Deprecated. Same as --set-release.
719 Options can be used in any combination. If none are specified B<--set-svn>
723 # Editor modelines - http://www.wireshark.org/tools/modelines.html
728 # indent-tabs-mode: t
731 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
732 # :indentSize=8:tabSize=8:noTabs=false: