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 # format - A strftime() formatted string to use as a template for
32 # the version string. The sequence "%#" will substitute
33 # the SVN revision number.
34 # pkg_enable - Enable or disable local package versioning.
35 # pkg_format - Like "format", but used for the local package version.
37 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
38 # configure.ac and the VERSION macro in config.nmake will have the
39 # pkg_format template appended to the version number. version.h will
40 # _not_ be generated if either argument is present.
42 # Default configuration:
46 # format: SVN %Y%m%d%H%M%S
50 # XXX - We're pretty dumb about the "%#" substitution, and about having
51 # spaces in the package format.
57 use POSIX qw(strftime);
63 my $version_file = 'version.h';
64 my $package_string = "";
65 my $vconf_file = 'version.conf';
66 my $tortoise_file = "tortoise_template";
70 my $repo_branch = "unknown";
71 my $git_description = undef;
78 "version_minor" => 99,
86 "format" => "git %Y%m%d%H%M%S",
89 # Normal development builds
91 "pkg_format" => "-%#",
93 # Development releases
100 # Ensure we run with correct locale
103 $ENV{GIT_PAGER} = "";
105 # Run "svn info". Parse out the most recent modification time and the
109 my $version_format = $version_pref{"format"};
110 my $package_format = "";
114 my $repo_root = undef;
115 my $repo_url = undef;
117 my $info_source = "Unknown";
119 if ($version_pref{"pkg_enable"} > 0) {
120 $package_format = $version_pref{"pkg_format"};
123 if (-d "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
124 $info_source = "Command line (git)";
125 $version_pref{"git_client"} = 1;
126 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
127 $info_source = "Command line (svn info)";
128 $info_cmd = "svn info $srcdir";
129 } elsif (-d "$srcdir/.git/svn") {
130 $info_source = "Command line (git-svn)";
131 $info_cmd = "(cd $srcdir; git svn info)";
136 # A big ugly hash: git rev-parse HEAD
137 # 1ddc83849075addb0cac69a6fe3782f4325337b9
139 # A small ugly hash: git rev-parse --short HEAD
142 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
145 # A version description: git describe --tags --dirty
146 # wireshark-1.8.12-15-g1ddc838
148 # Number of commits in this branch: git rev-list --count HEAD
151 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
154 # Refs: git ls-remote code.wireshark.org:wireshark
155 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
157 if ($version_pref{"git_client"}) {
162 chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
163 if ($? == 0 && length($line) > 1) {
164 $last_change = $line;
167 # Commits since last annotated tag.
168 chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always --match "v*"});
169 if ($? == 0 && length($line) > 1) {
170 my @parts = split(/-/, $line);
171 $git_description = $line;
172 $num_commits = $parts[-2];
173 $commit_id = $parts[-1];
176 chomp($line = qx{git ls-remote --get-url origin});
177 if (defined($line)) {
181 # This will break in some cases. Hopefully not during
182 # official package builds.
183 chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
184 if ($? == 0 && length($line) > 1) {
185 $repo_branch = basename($line);
191 if ($last_change && $num_commits && $repo_url && $repo_branch) {
194 } elsif ($version_pref{"svn_client"}) {
198 $line = qx{$info_cmd};
199 if (defined($line)) {
200 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
201 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
203 if ($line =~ /Last Changed Rev: (\d+)/) {
206 if ($line =~ /URL: (\S+)/) {
209 if ($line =~ /Repository Root: (\S+)/) {
216 if ($last_change && $num_commits && $repo_url && $repo_root) {
219 } elsif ($version_pref{"tortoise_svn"}) {
220 # Dynamically generic template file needed by TortoiseSVN
221 open(TORTOISE, ">$tortoise_file");
222 print TORTOISE "#define GITVERSION \"\$WCREV\$\"\r\n";
223 print TORTOISE "#define GITBRANCH \"\$WCURL\$\"\r\n";
226 $info_source = "Command line (SubWCRev)";
227 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
228 my $tortoise = system($info_cmd);
229 if ($tortoise == 0) {
233 #clean up the template file
234 unlink($tortoise_file);
237 if ($num_commits == 0) {
238 # Fall back to config.nmake
239 $info_source = "Prodding config.nmake";
240 my $filepath = "$srcdir/config.nmake";
241 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
242 while ($line = <CFGNMAKE>) {
243 if ($line =~ /^GIT_REVISION=(\d+)/) {
251 if ($num_commits == 0 and -d "$srcdir/.git") {
257 # If someone had properly tagged 1.9.0 we could also use
258 # "git describe --abbrev=1 --tags HEAD"
260 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
261 $line = qx{$info_cmd};
262 if (defined($line)) {
263 if ($line =~ /svn path=.*; revision=(\d+)/) {
267 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
268 $line = qx{$info_cmd};
269 if (defined($line)) {
270 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
271 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
274 $info_cmd = "(cd $srcdir; git branch)";
275 $line = qx{$info_cmd};
276 if (defined($line)) {
277 if ($line =~ /\* (\S+)/) {
284 if ($num_commits == 0 and -d "$srcdir/.bzr") {
290 $info_cmd = "(cd $srcdir; bzr log -l 1)";
291 $line = qx{$info_cmd};
292 if (defined($line)) {
293 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
294 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
296 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
306 # 'svn info' failed or the user really wants us to dig around in .svn/entries
308 # Start of ugly internal SVN file hack
309 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
310 print ("Unable to open $srcdir/.svn/entries\n");
312 $info_source = "Prodding .svn";
313 # We need to find out whether our parser can handle the entries file
316 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
317 $repo_version = "pre1.4";
318 } elsif ($line =~ /^8$/) {
319 $repo_version = "1.4";
321 $repo_version = "unknown";
324 if ($repo_version eq "pre1.4") {
325 # The entries schema is flat, so we can use regexes to parse its contents.
326 while ($line = <ENTRIES>) {
327 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
332 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
333 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
334 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
336 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
338 if ($line =~ /\/>/) {
339 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
340 $last_change && $num_commits) {
345 # XXX - Fetch the repository root & URL
352 # If we picked up the revision and modification time,
353 # generate our strings.
354 if ($num_commits && $last_change) {
355 $version_format =~ s/%#/$num_commits/;
356 $package_format =~ s/%#/$num_commits-$commit_id/;
357 $package_string = strftime($package_format, gmtime($last_change));
360 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
361 $repo_branch = substr($repo_url, length($repo_root));
366 Commit distance : $num_commits
367 Commit ID : $commit_id
368 Revision source : $info_source
369 Release stamp : $package_string
375 # Read configure.ac, then write it back out with an updated
377 sub update_configure_ac
382 my $filepath = "$srcdir/configure.ac";
384 return if (!$set_version && $package_string eq "");
386 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
387 while ($line = <CFGIN>) {
388 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
389 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
390 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
391 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
392 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
393 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
394 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
395 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
400 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
401 print(CFGIN $contents);
403 print "$filepath has been updated.\n";
406 # Read config.nmake, then write it back out with an updated
408 sub update_config_nmake
413 my $filepath = "$srcdir/config.nmake";
415 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
416 while ($line = <CFGNMAKE>) {
417 if ($line =~ /^GIT_REVISION=.*([\r\n]+)$/) {
418 $line = sprintf("GIT_REVISION=%d$1", $num_commits);
419 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
420 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
421 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
422 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
423 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
424 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
425 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
426 $line = "VERSION_EXTRA=$package_string$1";
431 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
432 print(CFGNMAKE $contents);
434 print "$filepath has been updated.\n";
437 # Read docbook/asciidoc.conf, then write it back out with an updated
438 # wireshark-version replacement line.
439 sub update_release_notes
444 my $filepath = "$srcdir/docbook/asciidoc.conf";
446 return if (!$set_version);
448 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
449 while ($line = <ADOC_CONF>) {
450 # wireshark-version:\[\]=1.9.1
452 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
453 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
454 $version_pref{"version_major"},
455 $version_pref{"version_minor"},
456 $version_pref{"version_micro"},
462 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
463 print(ADOC_CONF $contents);
465 print "$filepath has been updated.\n";
468 # Read debian/changelog, then write back out an updated version.
469 sub update_debian_changelog
474 my $filepath = "$srcdir/debian/changelog";
476 return if ($set_version == 0);
478 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
479 while ($line = <CHANGELOG>) {
480 if ($set_version && CHANGELOG->input_line_number() == 1) {
481 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
482 $version_pref{"version_major"},
483 $version_pref{"version_minor"},
484 $version_pref{"version_micro"},
490 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
491 print(CHANGELOG $contents);
493 print "$filepath has been updated.\n";
496 # Read debian/wireshark-common.files, then write back out an updated version.
497 # The libraries updated here MUST match the updates made by update_lib_releases
498 # below. We should do this automatically.
499 sub update_debian_wcf
504 my $filepath = "$srcdir/debian/wireshark-common.files";
506 return if (!$set_version);
508 open(DWCF, "< $filepath") || die "Can't read $filepath!";
509 while ($line = <DWCF>) {
510 # /usr/lib/wireshark/libwireshark.so.1.1.0
512 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap|filetap).so\.\d+\.\d+\.)\d+$}) {
513 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
518 open(DWCF, "> $filepath") || die "Can't write $filepath!";
519 print(DWCF $contents);
521 print "$filepath has been updated.\n";
524 # Read Makefile.am for each library, then write back out an updated version.
525 sub update_lib_releases
533 return if (!$set_version);
535 # The Libtool manual says
536 # "If the library source code has changed at all since the last
537 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
538 # epan changes with each minor release, almost by definition. wiretap
539 # and filetap changes with *most* releases.
541 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
542 for $filedir ("epan", "wiretap", "filetap") { # "wsutil"
544 $filepath = $filedir . "/Makefile.am";
545 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
546 while ($line = <MAKEFILE_AM>) {
547 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
549 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
550 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
555 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
556 print(MAKEFILE_AM $contents);
558 print "$filepath has been updated.\n";
562 # Update distributed files that contain any version information
563 sub update_versioned_files
565 &update_configure_ac;
566 &update_config_nmake;
567 &update_release_notes;
568 &update_debian_changelog;
570 &update_lib_releases;
573 # Print the SVN version to $version_file.
574 # Don't change the file if it is not needed.
575 sub print_GIT_REVISION
578 my $needs_update = 1;
580 if ($git_description) {
581 $GIT_REVISION = "#define GITVERSION \"" .
582 $git_description . "\"\n" .
583 "#define GITBRANCH \"" . $repo_branch . "\"\n";
584 } elsif ($last_change && $num_commits) {
585 $GIT_REVISION = "#define GITVERSION \"Git Rev " .
586 $num_commits . "\"\n" .
587 "#define GITBRANCH \"" . $repo_branch . "\"\n";
589 $GIT_REVISION = "#define GITVERSION \"Git Rev Unknown\"\n" .
590 "#define GITBRANCH \"unknown\"\n";
592 if (open(OLDREV, "<$version_file")) {
593 my $old_GIT_REVISION = <OLDREV> . <OLDREV>;
594 if ($old_GIT_REVISION eq $GIT_REVISION) {
600 if (! $set_svn) { return; }
603 # print "Updating $version_file so it contains:\n$GIT_REVISION";
604 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
605 print VER "$GIT_REVISION";
607 print "$version_file has been updated.\n";
609 print "$version_file unchanged.\n";
613 # Read values from the configuration file, if it exists.
618 # Get our command-line args
619 # XXX - Do we need an option to undo --set-release?
621 "help|h", \$show_help,
622 "get-svn|g", \$get_svn,
623 "set-svn|s", \$set_svn,
624 "set-version|v", \$set_version,
625 "set-release|r|package-version|p", \$set_release
628 if ($show_help) { pod2usage(1); }
630 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
638 if (! open(FILE, "<$vconf_file")) {
639 print STDERR "Version configuration file $vconf_file not "
640 . "found. Using defaults.\n";
645 s/^\s+|\s+$//g; # chomp() may not handle CR
647 next unless (/^(\w+)(:|=)\s*(\S.*)/);
648 $version_pref{$1} = $3;
664 if ($set_version || $set_release) {
666 print "Generating version information\n";
669 if ($version_pref{"enable"} == 0) {
670 print "Release information disabled in $vconf_file.\n";
675 print "Generating release information\n";
677 print "Resetting release information\n";
679 $package_string = "";
682 &update_versioned_files;
689 make-version.pl - Get and set build-time version information for Wireshark
693 make-version.pl [options] [source directory]
697 --help, -h This help message
698 --get-svn, -g Print the SVN revision and source.
699 --set-svn, -s Set the information in version.h
700 --set-version, -v Set the major, minor, and micro versions in
701 configure.ac, config.nmake, debian/changelog,
702 and docbook/asciidoc.conf.
703 Resets the release information when used by
705 --set-release, -r Set the release information in configure.ac
707 --package-version, -p Deprecated. Same as --set-release.
709 Options can be used in any combination. If none are specified B<--set-svn>
715 # Editor modelines - http://www.wireshark.org/tools/modelines.html
720 # indent-tabs-mode: t
723 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
724 # :indentSize=8:tabSize=8:noTabs=false: