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";
84 "format" => "SVN %Y%m%d%H%M%S",
87 # Normal development builds
89 "pkg_format" => "-SVN-%#",
91 # Development releases
96 my $svn_info_cmd = "";
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") {
121 $info_source = "Command line (svn info)";
122 $svn_info_cmd = "svn info $srcdir";
123 } elsif (-d "$srcdir/.git/svn") {
124 $info_source = "Command line (git-svn)";
125 $svn_info_cmd = "(cd $srcdir; git svn info)";
128 if ($version_pref{"svn_client"}) {
132 $line = qx{$svn_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 $svn_info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
162 my $tortoise = system($svn_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 $svn_info_cmd = "(cd $srcdir; git log --format='commit: %h%ndate: %ad' -n 1 --date=iso)";
192 $line = qx{$svn_info_cmd};
193 if (defined($line)) {
194 if ($line =~ /date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
195 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
197 if ($line =~ /commit: (\S+)/) {
201 $svn_info_cmd = "(cd $srcdir; git branch)";
202 $line = qx{$svn_info_cmd};
203 if (defined($line)) {
204 if ($line =~ /\* (\S+)/) {
211 if ($revision == 0 and -d "$srcdir/.bzr") {
217 $svn_info_cmd = "(cd $srcdir; bzr log -l 1)";
218 $line = qx{$svn_info_cmd};
219 if (defined($line)) {
220 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
221 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
223 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
233 # 'svn info' failed or the user really wants us to dig around in .svn/entries
235 # Start of ugly internal SVN file hack
236 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
237 print ("Unable to open $srcdir/.svn/entries\n");
239 $info_source = "Prodding .svn";
240 # We need to find out whether our parser can handle the entries file
243 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
244 $repo_version = "pre1.4";
245 } elsif ($line =~ /^8$/) {
246 $repo_version = "1.4";
248 $repo_version = "unknown";
251 if ($repo_version eq "pre1.4") {
252 # The entries schema is flat, so we can use regexes to parse its contents.
253 while ($line = <ENTRIES>) {
254 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
259 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
260 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
261 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
263 if ($line =~ /revision="(\d+)"/) { $revision = $1; }
265 if ($line =~ /\/>/) {
266 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
267 $last_change && $revision) {
272 # XXX - Fetch the repository root & URL
279 # If we picked up the revision and modification time,
280 # generate our strings.
281 if ($revision && $last_change) {
282 $version_format =~ s/%#/$revision/;
283 $package_format =~ s/%#/$revision/;
284 $package_string = strftime($package_format, gmtime($last_change));
287 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
288 $repo_path = substr($repo_url, length($repo_root));
293 SVN revision : $revision
294 Revision source : $info_source
295 Release stamp : $package_string
301 # Read configure.ac, then write it back out with an updated
303 sub update_configure_ac
308 my $filepath = "$srcdir/configure.ac";
310 return if (!$set_version && $package_string eq "");
312 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
313 while ($line = <CFGIN>) {
314 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
315 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
316 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
317 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
318 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
319 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
320 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
321 $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
326 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
327 print(CFGIN $contents);
329 print "$filepath has been updated.\n";
332 # Read config.nmake, then write it back out with an updated
334 sub update_config_nmake
339 my $filepath = "$srcdir/config.nmake";
341 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
342 while ($line = <CFGNMAKE>) {
343 if ($line =~ /^SVN_REVISION=.*([\r\n]+)$/) {
344 $line = sprintf("SVN_REVISION=%d$1", $revision);
345 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
346 $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
347 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
348 $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
349 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
350 $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
351 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
352 $line = "VERSION_EXTRA=$package_string$1";
357 open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
358 print(CFGNMAKE $contents);
360 print "$filepath has been updated.\n";
363 # Read docbook/release_notes.xml, then write it back out with an updated
364 # "WiresharkCurrentVersion" line.
365 sub update_release_notes
370 my $filepath = "$srcdir/docbook/release-notes.xml";
372 return if (!$set_version);
374 open(RELNOTES, "< $filepath") || die "Can't read $filepath!";
375 while ($line = <RELNOTES>) {
376 # <!ENTITY WiresharkCurrentVersion "1.7.1">
378 if ($line =~ /<\!ENTITY\s+WiresharkCurrentVersion\s+.*([\r\n]+)$/) {
379 $line = sprintf("<!ENTITY WiresharkCurrentVersion \"%d.%d.%d\">$1",
380 $version_pref{"version_major"},
381 $version_pref{"version_minor"},
382 $version_pref{"version_micro"},
388 open(RELNOTES, "> $filepath") || die "Can't write $filepath!";
389 print(RELNOTES $contents);
391 print "$filepath has been updated.\n";
394 # Read debian/changelog, then write back out an updated version.
395 sub update_debian_changelog
400 my $filepath = "$srcdir/debian/changelog";
402 return if ($set_version == 0);
404 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
405 while ($line = <CHANGELOG>) {
406 if ($set_version && CHANGELOG->input_line_number() == 1) {
407 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
408 $version_pref{"version_major"},
409 $version_pref{"version_minor"},
410 $version_pref{"version_micro"},
416 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
417 print(CHANGELOG $contents);
419 print "$filepath has been updated.\n";
422 # Read debian/wireshark-common.files, then write back out an updated version.
423 # The libraries updated here MUST match the updates made by update_lib_releases
424 # below. We should do this automatically.
425 sub update_debian_wcf
430 my $filepath = "$srcdir/debian/wireshark-common.files";
432 return if (!$set_version);
434 open(DWCF, "< $filepath") || die "Can't read $filepath!";
435 while ($line = <DWCF>) {
436 # /usr/lib/wireshark/libwireshark.so.1.1.0
438 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap).so\.\d+\.\d+\.)\d+$}) {
439 $line = sprintf("$1%d\n", $version_pref{"version_micro"});
444 open(DWCF, "> $filepath") || die "Can't write $filepath!";
445 print(DWCF $contents);
447 print "$filepath has been updated.\n";
450 # Read Makefile.am for each library, then write back out an updated version.
451 sub update_lib_releases
459 return if (!$set_version);
461 # The Libtool manual says
462 # "If the library source code has changed at all since the last
463 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
464 # epan changes with each minor release, almost by definition. wiretap
465 # changes with *most* releases.
467 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
468 for $filedir ("epan", "wiretap") { # "wsutil"
470 $filepath = $filedir . "/Makefile.am";
471 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
472 while ($line = <MAKEFILE_AM>) {
473 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
475 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
476 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
481 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
482 print(MAKEFILE_AM $contents);
484 print "$filepath has been updated.\n";
488 # Update distributed files that contain any version information
489 sub update_versioned_files
491 &update_configure_ac;
492 &update_config_nmake;
493 &update_release_notes;
494 &update_debian_changelog;
496 &update_lib_releases;
499 # Print the SVN version to $version_file.
500 # Don't change the file if it is not needed.
501 sub print_svn_revision
504 my $needs_update = 1;
506 if ($last_change && $revision) {
507 $svn_revision = "#define SVNVERSION \"SVN Rev " .
509 "#define SVNPATH \"" . $repo_path . "\"\n";
511 $svn_revision = "#define SVNVERSION \"SVN Rev Unknown\"\n" .
512 "#define SVNPATH \"unknown\"\n";
514 if (open(OLDREV, "<$version_file")) {
515 my $old_svn_revision = <OLDREV> . <OLDREV>;
516 if ($old_svn_revision eq $svn_revision) {
522 if (! $set_svn) { return; }
525 # print "Updating $version_file so it contains:\n$svn_revision";
526 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
527 print VER "$svn_revision";
529 print "$version_file has been updated.\n";
531 print "$version_file unchanged.\n";
535 # Read values from the configuration file, if it exists.
540 # Get our command-line args
541 # XXX - Do we need an option to undo --set-release?
543 "help|h", \$show_help,
544 "get-svn|g", \$get_svn,
545 "set-svn|s", \$set_svn,
546 "set-version|v", \$set_version,
547 "set-release|r|package-version|p", \$set_release
550 if ($show_help) { pod2usage(1); }
552 if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
560 if (! open(FILE, "<$vconf_file")) {
561 print STDERR "Version configuration file $vconf_file not "
562 . "found. Using defaults.\n";
569 next unless (/^(\w+)(:|=)\s*(\S.*)/);
570 $version_pref{$1} = $3;
586 if ($set_version || $set_release) {
588 print "Generating version information\n";
591 if ($version_pref{"enable"} == 0) {
592 print "Release information disabled in $vconf_file.\n";
597 print "Generating release information\n";
599 print "Resetting release information\n";
601 $package_string = "";
604 &update_versioned_files;
611 make-version.pl - Get and set build-time version information for Wireshark
615 make-version.pl [options] [source directory]
619 --help, -h This help message
620 --get-svn, -g Print the SVN revision and source.
621 --set-svn, -s Set the information in svnversion.h
622 --set-version, -v Set the major, minor, and micro versions in
623 configure.ac, config.nmake, debian/changelog,
624 and docbook/release_notes.xml.
625 Resets the release information when used by
627 --set-release, -r Set the release information in configure.ac
629 --package-version, -p Deprecated. Same as --set-release.
631 Options can be used in any combination. If none are specified B<--set-svn>
635 # Editor modelines - http://www.wireshark.org/tools/modelines.html
640 # indent-tabs-mode: t
643 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
644 # :indentSize=8:tabSize=8:noTabs=false: