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. svnversion.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.
58 use POSIX
qw(strftime);
64 my $version_file = 'svnversion.h';
65 my $package_string = "";
66 my $vconf_file = 'version.conf';
67 my $tortoise_file = "tortoise_template";
70 my $repo_path = "unknown";
77 "version_minor" => 11,
84 "format" => "SVN %Y%m%d%H%M%S",
87 # Normal development builds
89 "pkg_format" => "-SVN-%#",
91 # Development releases
98 # Ensure we run with correct locale
102 # Run "svn info". Parse out the most recent modification time and the
106 my $version_format = $version_pref{"format"};
107 my $package_format = "";
111 my $repo_root = undef;
112 my $repo_url = undef;
114 my $info_source = "Unknown";
116 if ($version_pref{"pkg_enable"}) {
117 $package_format = $version_pref{"pkg_format"};
120 if (-d
"$srcdir/.svn" or -d
"$srcdir/../.svn") {
121 $info_source = "Command line (svn info)";
122 $info_cmd = "svn info $srcdir";
123 } elsif (-d
"$srcdir/.git/svn") {
124 $info_source = "Command line (git-svn)";
125 $info_cmd = "(cd $srcdir; git svn info)";
128 if ($version_pref{"svn_client"}) {
132 $line = qx{$info_cmd};
133 if (defined($line)) {
134 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
135 $last_change = timegm
($6, $5, $4, $3, $2 - 1, $1);
137 if ($line =~ /Last Changed Rev: (\d+)/) {
140 if ($line =~ /URL: (\S+)/) {
143 if ($line =~ /Repository Root: (\S+)/) {
150 if ($last_change && $revision && $repo_url && $repo_root) {
153 } elsif ($version_pref{"tortoise_svn"}) {
154 # Dynamically generic template file needed by TortoiseSVN
155 open(TORTOISE
, ">$tortoise_file");
156 print TORTOISE
"#define SVNVERSION \"\$WCREV\$\"\r\n";
157 print TORTOISE
"#define SVNPATH \"\$WCURL\$\"\r\n";
160 $info_source = "Command line (SubWCRev)";
161 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
162 my $tortoise = system($info_cmd);
163 if ($tortoise == 0) {
167 #clean up the template file
168 unlink($tortoise_file);
171 if ($revision == 0) {
172 # Fall back to config.nmake
173 $info_source = "Prodding config.nmake";
174 my $filepath = "$srcdir/config.nmake";
175 open(CFGNMAKE
, "< $filepath") || die "Can't read $filepath!";
176 while ($line = <CFGNMAKE
>) {
177 if ($line =~ /^SVN_REVISION=(\d+)/) {
185 if ($revision == 0 and -d
"$srcdir/.git") {
191 # If someone had properly tagged 1.9.0 we could also use
192 # "git describe --abbrev=1 --tags HEAD"
194 $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
195 $line = qx{$info_cmd};
196 if (defined($line)) {
197 if ($line =~ /svn path=.*; revision=(\d+)/) {
201 $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
202 $line = qx{$info_cmd};
203 if (defined($line)) {
204 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
205 $last_change = timegm
($6, $5, $4, $3, $2 - 1, $1);
208 $info_cmd = "(cd $srcdir; git branch)";
209 $line = qx{$info_cmd};
210 if (defined($line)) {
211 if ($line =~ /\* (\S+)/) {
218 if ($revision == 0 and -d
"$srcdir/.bzr") {
224 $info_cmd = "(cd $srcdir; bzr log -l 1)";
225 $line = qx{$info_cmd};
226 if (defined($line)) {
227 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
228 $last_change = timegm
($6, $5, $4, $3, $2 - 1, $1);
230 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
240 # 'svn info' failed or the user really wants us to dig around in .svn/entries
242 # Start of ugly internal SVN file hack
243 if (! open (ENTRIES
, "< $srcdir/.svn/entries")) {
244 print ("Unable to open $srcdir/.svn/entries\n");
246 $info_source = "Prodding .svn";
247 # We need to find out whether our parser can handle the entries file
250 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
251 $repo_version = "pre1.4";
252 } elsif ($line =~ /^8$/) {
253 $repo_version = "1.4";
255 $repo_version = "unknown";
258 if ($repo_version eq "pre1.4") {
259 # The entries schema is flat, so we can use regexes to parse its contents.
260 while ($line = <ENTRIES
>) {
261 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
266 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
267 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
268 $last_change = timegm
($6, $5, $4, $3, $2 - 1, $1);
270 if ($line =~ /revision="(\d+)"/) { $revision = $1; }
272 if ($line =~ /\/>/) {
273 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
274 $last_change && $revision) {
279 # XXX - Fetch the repository root & URL
286 # If we picked up the revision and modification time,
287 # generate our strings.
288 if ($revision && $last_change) {
289 $version_format =~ s/%#/$revision/;
290 $package_format =~ s/%#/$revision/;
291 $package_string = strftime
($package_format, gmtime($last_change));
294 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
295 $repo_path = substr($repo_url, length($repo_root));
300 SVN revision : $revision
301 Revision source : $info_source
302 Release stamp : $package_string
308 # Read configure.ac, then write it back out with an updated
310 sub update_configure_ac
315 my $filepath = "$srcdir/configure.ac";
317 return if (!$set_version && $package_string eq "");
319 open(CFGIN
, "< $filepath") || die "Can't read $filepath!";
320 while ($line = <CFGIN
>) {
321 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
322 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
323 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
324 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
325 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
326 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
327 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
328 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
333 open(CFGIN
, "> $filepath") || die "Can't write $filepath!";
334 print(CFGIN
$contents);
336 print "$filepath has been updated.\n";
339 # Read config.nmake, then write it back out with an updated
341 sub update_config_nmake
346 my $filepath = "$srcdir/config.nmake";
348 open(CFGNMAKE
, "< $filepath") || die "Can't read $filepath!";
349 while ($line = <CFGNMAKE
>) {
350 if ($line =~ /^SVN_REVISION=.*([\r\n]+)$/) {
351 $line = sprintf("SVN_REVISION=%d$1", $revision);
352 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
353 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
354 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
355 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
356 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
357 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
358 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
359 $line = "VERSION_EXTRA=$package_string$1";
364 open(CFGNMAKE
, "> $filepath") || die "Can't write $filepath!";
365 print(CFGNMAKE
$contents);
367 print "$filepath has been updated.\n";
370 # Read docbook/asciidoc.conf, then write it back out with an updated
371 # wireshark-version replacement line.
372 sub update_release_notes
377 my $filepath = "$srcdir/docbook/asciidoc.conf";
379 return if (!$set_version);
381 open(ADOC_CONF
, "< $filepath") || die "Can't read $filepath!";
382 while ($line = <ADOC_CONF
>) {
383 # wireshark-version:\[\]=1.9.1
385 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
386 $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
387 $version_pref{"version_major"},
388 $version_pref{"version_minor"},
389 $version_pref{"version_micro"},
395 open(ADOC_CONF
, "> $filepath") || die "Can't write $filepath!";
396 print(ADOC_CONF
$contents);
398 print "$filepath has been updated.\n";
401 # Read debian/changelog, then write back out an updated version.
402 sub update_debian_changelog
407 my $filepath = "$srcdir/debian/changelog";
409 return if ($set_version == 0);
411 open(CHANGELOG
, "< $filepath") || die "Can't read $filepath!";
412 while ($line = <CHANGELOG
>) {
413 if ($set_version && CHANGELOG
->input_line_number() == 1) {
414 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
415 $version_pref{"version_major"},
416 $version_pref{"version_minor"},
417 $version_pref{"version_micro"},
423 open(CHANGELOG
, "> $filepath") || die "Can't write $filepath!";
424 print(CHANGELOG
$contents);
426 print "$filepath has been updated.\n";
429 # Read debian/wireshark-common.files, then write back out an updated version.
430 # The libraries updated here MUST match the updates made by update_lib_releases
431 # below. We should do this automatically.
432 sub update_debian_wcf
437 my $filepath = "$srcdir/debian/wireshark-common.files";
439 return if (!$set_version);
441 open(DWCF
, "< $filepath") || die "Can't read $filepath!";
442 while ($line = <DWCF
>) {
443 # /usr/lib/wireshark/libwireshark.so.1.1.0
445 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap).so\.\d+\.\d+\.)\d+$}) {
446 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
451 open(DWCF
, "> $filepath") || die "Can't write $filepath!";
452 print(DWCF
$contents);
454 print "$filepath has been updated.\n";
457 # Read Makefile.am for each library, then write back out an updated version.
458 sub update_lib_releases
466 return if (!$set_version);
468 # The Libtool manual says
469 # "If the library source code has changed at all since the last
470 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
471 # epan changes with each minor release, almost by definition. wiretap
472 # changes with *most* releases.
474 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
475 for $filedir ("epan", "wiretap") { # "wsutil"
477 $filepath = $filedir . "/Makefile.am";
478 open(MAKEFILE_AM
, "< $filepath") || die "Can't read $filepath!";
479 while ($line = <MAKEFILE_AM
>) {
480 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
482 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
483 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
488 open(MAKEFILE_AM
, "> $filepath") || die "Can't write $filepath!";
489 print(MAKEFILE_AM
$contents);
491 print "$filepath has been updated.\n";
495 # Update distributed files that contain any version information
496 sub update_versioned_files
498 &update_configure_ac
;
499 &update_config_nmake
;
500 &update_release_notes
;
501 &update_debian_changelog
;
503 &update_lib_releases
;
506 # Print the SVN version to $version_file.
507 # Don't change the file if it is not needed.
508 sub print_svn_revision
511 my $needs_update = 1;
513 if ($last_change && $revision) {
514 $svn_revision = "#define SVNVERSION \"SVN Rev " .
516 "#define SVNPATH \"" . $repo_path . "\"\n";
518 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
519 "#define SVNPATH \"unknown\"\n";
521 if (open(OLDREV
, "<$version_file")) {
522 my $old_svn_revision = <OLDREV
> . <OLDREV
>;
523 if ($old_svn_revision eq $svn_revision) {
529 if (! $set_svn) { return; }
532 # print "Updating $version_file so it contains:\n$svn_revision";
533 open(VER
, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
534 print VER
"$svn_revision";
536 print "$version_file has been updated.\n";
538 print "$version_file unchanged.\n";
542 # Read values from the configuration file, if it exists.
547 # Get our command-line args
548 # XXX - Do we need an option to undo --set-release?
550 "help|h", \
$show_help,
551 "get-svn|g", \
$get_svn,
552 "set-svn|s", \
$set_svn,
553 "set-version|v", \
$set_version,
554 "set-release|r|package-version|p", \
$set_release
557 if ($show_help) { pod2usage
(1); }
559 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
567 if (! open(FILE
, "<$vconf_file")) {
568 print STDERR
"Version configuration file $vconf_file not "
569 . "found. Using defaults.\n";
576 next unless (/^(\w+)(:|=)\s*(\S.*)/);
577 $version_pref{$1} = $3;
593 if ($set_version || $set_release) {
595 print "Generating version information\n";
598 if ($version_pref{"enable"} == 0) {
599 print "Release information disabled in $vconf_file.\n";
604 print "Generating release information\n";
606 print "Resetting release information\n";
608 $package_string = "";
611 &update_versioned_files
;
618 make-version.pl - Get and set build-time version information for Wireshark
622 make-version.pl [options] [source directory]
626 --help, -h This help message
627 --get-svn, -g Print the SVN revision and source.
628 --set-svn, -s Set the information in svnversion.h
629 --set-version, -v Set the major, minor, and micro versions in
630 configure.ac, config.nmake, debian/changelog,
631 and docbook/asciidoc.conf.
632 Resets the release information when used by
634 --set-release, -r Set the release information in configure.ac
636 --package-version, -p Deprecated. Same as --set-release.
638 Options can be used in any combination. If none are specified B<--set-svn>
642 # Editor modelines - http://www.wireshark.org/tools/modelines.html
647 # indent-tabs-mode: t
650 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
651 # :indentSize=8:tabSize=8:noTabs=false: