nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #!/usr/bin/perl -w
2 #
3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
4 #
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
8 #
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.
13 #
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.
18 #
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.
22  
23 # See below for usage
24 #
25 # If "version.conf" is present, it is parsed for configuration values.
26 # Possible values are:
27 #
28 # enable - Enable or disable versioning. Zero (0) disables, nonzero
29 # enables.
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
32 # file hack
33 # format - A strftime() formatted string to use as a template for
34 # the version string. The sequence "%#" will substitute
35 # the number of commits for Git or the revision number
36 # for SVN.
37 # pkg_enable - Enable or disable local package versioning.
38 # pkg_format - Like "format", but used for the local package version.
39 #
40 # If run with the "-r" or "--set-release" argument the AC_INIT macro in
41 # configure.ac and the VERSION macro in CMakeLists.txt will have the
42 # pkg_format template appended to the version number. version.h will
43 # _not_ be generated if either argument is present.
44 #
45 # Default configuration:
46 #
47 # enable: 1
48 # git_client: 0
49 # svn_client: 0
50 # tortoise_svn: 0
51 # format: git %Y%m%d%H%M%S
52 # pkg_enable: 1
53 # pkg_format: -%#
54  
55 # XXX - We're pretty dumb about the "%#" substitution, and about having
56 # spaces in the package format.
57  
58 use strict;
59  
60 use Time::Local;
61 use File::Basename;
62 use File::Spec;
63 use POSIX qw(strftime);
64 use Getopt::Long;
65 use Pod::Usage;
66 use IO::Handle;
67 use English;
68  
69 my $version_file = 'version.h';
70 my $package_string = "";
71 my $vconf_file = 'version.conf';
72 my $vcs_name = "Git";
73 my $tortoise_file = "tortoise_template";
74 my $last_change = 0;
75 my $num_commits = 0;
76 my $commit_id = '';
77 my $repo_branch = "unknown";
78 my $git_executable = "git";
79 my $git_description = undef;
80 my $get_vcs = 0;
81 my $set_vcs = 0;
82 my $print_vcs = 0;
83 my $set_version = 0;
84 my $set_release = 0;
85 my %version_pref = (
86 "version_major" => 2,
87 "version_minor" => 2,
88 "version_micro" => 3,
89 "version_build" => 0,
90  
91 "enable" => 1,
92 "git_client" => 0, # set if .git found and .git/svn not found
93 "svn_client" => 0, # set if .svn found
94 "tortoise_svn" => 0,
95 "format" => "git %Y%m%d%H%M%S",
96  
97 # Normal development builds
98 "pkg_enable" => 1,
99 "pkg_format" => "-%#",
100  
101 # Development releases
102 #"pkg_enable" => 0,
103 #"pkg_format" => "",
104 );
105 my $srcdir = ".";
106 my $info_cmd = "";
107 my $verbose = 0;
108 my $devnull = File::Spec->devnull();
109 my $enable_vcsversion = 1;
110  
111 # Ensure we run with correct locale
112 $ENV{LANG} = "C";
113 $ENV{LC_ALL} = "C";
114 $ENV{GIT_PAGER} = "";
115  
116 sub print_diag {
117 print STDERR @_ if $verbose;
118 }
119  
120 # Attempt to get revision information from the repository.
121 sub read_repo_info {
122 my $line;
123 my $version_format = $version_pref{"format"};
124 my $package_format = "";
125 my $in_entries = 0;
126 my $svn_name;
127 my $repo_version;
128 my $do_hack = 1;
129 my $info_source = "Unknown";
130 my $is_git_repo = 0;
131 my $git_cdir;
132  
133  
134 if ($version_pref{"pkg_enable"} > 0) {
135 $package_format = $version_pref{"pkg_format"};
136 }
137  
138 # For tarball releases, do not invoke git at all and instead rely on
139 # versioning information that was provided at tarball creation time.
140 if ($version_pref{"git_description"}) {
141 $info_source = "version.conf file";
142 } elsif (-e "$srcdir/.git" && ! -d "$srcdir/.git/svn") {
143 $info_source = "Command line (git)";
144 $version_pref{"git_client"} = 1;
145 $is_git_repo = 1;
146 } elsif (-d "$srcdir/.svn" or -d "$srcdir/../.svn") {
147 $info_source = "Command line (svn info)";
148 $info_cmd = "cd $srcdir; svn info";
149 $version_pref{"svn_client"} = 1;
150 } elsif (-d "$srcdir/.git/svn") {
151 $info_source = "Command line (git-svn)";
152 $info_cmd = "(cd $srcdir; $git_executable svn info)";
153 $is_git_repo = 1;
154 }
155  
156 # Make sure git is available.
157 if ($is_git_repo && !`$git_executable --version`) {
158 print STDERR "Git unavailable. Git revision will be missing from version string.\n";
159 return;
160 }
161  
162 # Check whether to include VCS version information in version.h
163 if ($is_git_repo) {
164 chomp($git_cdir = qx{git --git-dir="$srcdir/.git" rev-parse --git-common-dir 2> $devnull});
165 if ($git_cdir && -f "$git_cdir/wireshark-disable-versioning") {
166 print_diag "Header versioning disabled using git override.\n";
167 $enable_vcsversion = 0;
168 }
169 }
170  
171 #Git can give us:
172 #
173 # A big ugly hash: git rev-parse HEAD
174 # 1ddc83849075addb0cac69a6fe3782f4325337b9
175 #
176 # A small ugly hash: git rev-parse --short HEAD
177 # 1ddc838
178 #
179 # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
180 # origin/master
181 #
182 # A version description: git describe --tags --dirty
183 # wireshark-1.8.12-15-g1ddc838
184 #
185 # Number of commits in this branch: git rev-list --count HEAD
186 # 48879
187 #
188 # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
189 # 320
190 #
191 # Refs: git ls-remote code.wireshark.org:wireshark
192 # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
193  
194 if ($version_pref{"git_description"}) {
195 $git_description = $version_pref{"git_description"};
196 $do_hack = 0;
197 # Assume format like v2.3.0rc0-1342-g7bdcf75
198 $commit_id = ($git_description =~ /([0-9a-f]+)$/)[0];
199 } elsif ($version_pref{"git_client"}) {
200 eval {
201 use warnings "all";
202 no warnings "all";
203  
204 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git log -1 --pretty=format:%at});
205 if ($? == 0 && length($line) > 1) {
206 $last_change = $line;
207 }
208  
209 # Commits since last annotated tag.
210 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git describe --long --always --match "v*"});
211 if ($? == 0 && length($line) > 1) {
212 my @parts = split(/-/, $line);
213 $git_description = $line;
214 $num_commits = $parts[-2];
215 $commit_id = $parts[-1];
216 }
217  
218 # This will break in some cases. Hopefully not during
219 # official package builds.
220 chomp($line = qx{$git_executable --git-dir="$srcdir"/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\} 2> $devnull});
221 if ($? == 0 && length($line) > 1) {
222 $repo_branch = basename($line);
223 }
224  
225 1;
226 };
227  
228 if ($last_change && $num_commits && $repo_branch) {
229 $do_hack = 0;
230 }
231 } elsif ($version_pref{"svn_client"}) {
232 my $repo_root = undef;
233 my $repo_url = undef;
234 eval {
235 use warnings "all";
236 no warnings "all";
237 $line = qx{$info_cmd};
238 if (defined($line)) {
239 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
240 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
241 }
242 if ($line =~ /Last Changed Rev: (\d+)/) {
243 $num_commits = $1;
244 }
245 if ($line =~ /URL: (\S+)/) {
246 $repo_url = $1;
247 }
248 if ($line =~ /Repository Root: (\S+)/) {
249 $repo_root = $1;
250 }
251 $vcs_name = "SVN";
252 }
253 1;
254 };
255  
256 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
257 $repo_branch = substr($repo_url, length($repo_root));
258 }
259  
260 if ($last_change && $num_commits && $repo_url && $repo_root) {
261 $do_hack = 0;
262 }
263 } elsif ($version_pref{"tortoise_svn"}) {
264 # Dynamically generic template file needed by TortoiseSVN
265 open(TORTOISE, ">$tortoise_file");
266 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
267 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
268 close(TORTOISE);
269  
270 $info_source = "Command line (SubWCRev)";
271 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
272 my $tortoise = system($info_cmd);
273 if ($tortoise == 0) {
274 $do_hack = 0;
275 }
276 $vcs_name = "SVN";
277  
278 #clean up the template file
279 unlink($tortoise_file);
280 }
281  
282 if ($num_commits == 0 and -e "$srcdir/.git") {
283  
284 # Try git...
285 eval {
286 use warnings "all";
287 no warnings "all";
288 # If someone had properly tagged 1.9.0 we could also use
289 # "git describe --abbrev=1 --tags HEAD"
290  
291 $info_cmd = "(cd $srcdir; $git_executable log --format='%b' -n 1)";
292 $line = qx{$info_cmd};
293 if (defined($line)) {
294 if ($line =~ /svn path=.*; revision=(\d+)/) {
295 $num_commits = $1;
296 }
297 }
298 $info_cmd = "(cd $srcdir; $git_executable log --format='%ad' -n 1 --date=iso)";
299 $line = qx{$info_cmd};
300 if (defined($line)) {
301 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
302 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
303 }
304 }
305 $info_cmd = "(cd $srcdir; $git_executable branch)";
306 $line = qx{$info_cmd};
307 if (defined($line)) {
308 if ($line =~ /\* (\S+)/) {
309 $repo_branch = $1;
310 }
311 }
312 1;
313 };
314 }
315 if ($num_commits == 0 and -d "$srcdir/.bzr") {
316  
317 # Try bzr...
318 eval {
319 use warnings "all";
320 no warnings "all";
321 $info_cmd = "(cd $srcdir; bzr log -l 1)";
322 $line = qx{$info_cmd};
323 if (defined($line)) {
324 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
325 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
326 }
327 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
328 $num_commits = $1;
329 $repo_branch = $2;
330 }
331 $vcs_name = "Bzr";
332 }
333 1;
334 };
335 }
336  
337  
338 # 'svn info' failed or the user really wants us to dig around in .svn/entries
339 if ($do_hack) {
340 # Start of ugly internal SVN file hack
341 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
342 print STDERR "Unable to open $srcdir/.svn/entries\n";
343 } else {
344 $info_source = "Prodding .svn";
345 # We need to find out whether our parser can handle the entries file
346 $line = <ENTRIES>;
347 chomp $line;
348 if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
349 $repo_version = "pre1.4";
350 } elsif ($line =~ /^8$/) {
351 $repo_version = "1.4";
352 } else {
353 $repo_version = "unknown";
354 }
355  
356 if ($repo_version eq "pre1.4") {
357 # The entries schema is flat, so we can use regexes to parse its contents.
358 while ($line = <ENTRIES>) {
359 if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
360 $in_entries = 1;
361 $svn_name = "";
362 }
363 if ($in_entries) {
364 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
365 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
366 $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
367 }
368 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
369 }
370 if ($line =~ /\/>/) {
371 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
372 $last_change && $num_commits) {
373 $in_entries = 0;
374 last;
375 }
376 }
377 # XXX - Fetch the repository root & URL
378 }
379 }
380 close ENTRIES;
381 }
382 }
383  
384 # If we picked up the revision and modification time,
385 # generate our strings.
386 if ($version_pref{"pkg_enable"}) {
387 $version_format =~ s/%#/$num_commits/;
388 $package_format =~ s/%#/$num_commits-$commit_id/;
389 $package_string = strftime($package_format, gmtime($last_change));
390 }
391  
392 if ($get_vcs) {
393 print <<"Fin";
394 Commit distance : $num_commits
395 Commit ID : $commit_id
396 Revision source : $info_source
397 Release stamp : $package_string
398 Fin
399 } elsif ($print_vcs) {
400 print new_version_h();
401 }
402 }
403  
404  
405 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
406 # lines
407 # set(GIT_REVISION 999)
408 # set(PROJECT_MAJOR_VERSION 1)
409 # set(PROJECT_MINOR_VERSION 99)
410 # set(PROJECT_PATCH_VERSION 0)
411 # set(PROJECT_VERSION_EXTENSION "-rc5")
412 sub update_cmakelists_txt
413 {
414 my $line;
415 my $contents = "";
416 my $version = "";
417 my $filepath = "$srcdir/CMakeLists.txt";
418  
419 return if (!$set_version && $package_string eq "");
420  
421 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
422 while ($line = <CFGIN>) {
423 if ($line =~ /^set *\( *GIT_REVISION .*([\r\n]+)$/) {
424 $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
425 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
426 $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
427 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
428 $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
429 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
430 $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
431 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION .*([\r\n]+)$/) {
432 $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
433 }
434 $contents .= $line
435 }
436  
437 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
438 print(CFGIN $contents);
439 close(CFGIN);
440 print "$filepath has been updated.\n";
441 }
442  
443 # Read configure.ac, then write it back out with an updated
444 # "AC_INIT" line.
445 sub update_configure_ac
446 {
447 my $line;
448 my $contents = "";
449 my $version = "";
450 my $filepath = "$srcdir/configure.ac";
451  
452 return if (!$set_version && $package_string eq "");
453  
454 open(CFGIN, "< $filepath") || die "Can't read $filepath!";
455 while ($line = <CFGIN>) {
456 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
457 $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
458 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
459 $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
460 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
461 $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
462 } elsif ($line =~ /^m4_define\( *\[?version_extra\]? *,.*([\r\n]+)$/) {
463 $line = sprintf("m4_define([version_extra], [%s])$1", $package_string);
464 }
465 $contents .= $line
466 }
467  
468 open(CFGIN, "> $filepath") || die "Can't write $filepath!";
469 print(CFGIN $contents);
470 close(CFGIN);
471 print "$filepath has been updated.\n";
472 }
473  
474 # Read docbook/asciidoc.conf, then write it back out with an updated
475 # wireshark-version replacement line.
476 sub update_release_notes
477 {
478 my $line;
479 my $contents = "";
480 my $version = "";
481 my $filepath = "$srcdir/docbook/asciidoc.conf";
482  
483 open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
484 while ($line = <ADOC_CONF>) {
485 # wireshark-version:\[\]=1.9.1
486  
487 if ($line =~ /^wireshark-version=.*([\r\n]+)$/) {
488 $line = sprintf("wireshark-version=%d.%d.%d$1",
489 $version_pref{"version_major"},
490 $version_pref{"version_minor"},
491 $version_pref{"version_micro"},
492 );
493 }
494 $contents .= $line
495 }
496  
497 open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
498 print(ADOC_CONF $contents);
499 close(ADOC_CONF);
500 print "$filepath has been updated.\n";
501 }
502  
503 # Read debian/changelog, then write back out an updated version.
504 sub update_debian_changelog
505 {
506 my $line;
507 my $contents = "";
508 my $version = "";
509 my $filepath = "$srcdir/debian/changelog";
510  
511 open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
512 while ($line = <CHANGELOG>) {
513 if ($set_version && CHANGELOG->input_line_number() == 1) {
514 $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
515 $version_pref{"version_major"},
516 $version_pref{"version_minor"},
517 $version_pref{"version_micro"},
518 );
519 }
520 $contents .= $line
521 }
522  
523 open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
524 print(CHANGELOG $contents);
525 close(CHANGELOG);
526 print "$filepath has been updated.\n";
527 }
528  
529 # Read Makefile.am for each library, then write back out an updated version.
530 sub update_automake_lib_releases
531 {
532 my $line;
533 my $contents = "";
534 my $version = "";
535 my $filedir;
536 my $filepath;
537  
538 # The Libtool manual says
539 # "If the library source code has changed at all since the last
540 # update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
541 # epan changes with each minor release, almost by definition. wiretap
542 # changes with *most* releases.
543 #
544 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
545 for $filedir ("epan", "wiretap") { # "wsutil"
546 $contents = "";
547 $filepath = $filedir . "/Makefile.am";
548 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
549 while ($line = <MAKEFILE_AM>) {
550 # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
551  
552 if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
553 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
554 }
555 $contents .= $line
556 }
557  
558 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
559 print(MAKEFILE_AM $contents);
560 close(MAKEFILE_AM);
561 print "$filepath has been updated.\n";
562 }
563 }
564  
565 # Read CMakeLists.txt for each library, then write back out an updated version.
566 sub update_cmake_lib_releases
567 {
568 my $line;
569 my $contents = "";
570 my $version = "";
571 my $filedir;
572 my $filepath;
573  
574 for $filedir ("epan", "wiretap") { # "wsutil"
575 $contents = "";
576 $filepath = $filedir . "/CMakeLists.txt";
577 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
578 while ($line = <CMAKELISTS_TXT>) {
579 # set(FULL_SO_VERSION "0.0.0")
580  
581 if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*)/) {
582 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
583 }
584 $contents .= $line
585 }
586  
587 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
588 print(CMAKELISTS_TXT $contents);
589 close(CMAKELISTS_TXT);
590 print "$filepath has been updated.\n";
591 }
592 }
593  
594 # Update distributed files that contain any version information
595 sub update_versioned_files
596 {
597 # Matches CMakeLists.txt
598 printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
599 $num_commits, $version_pref{"version_major"},
600 $version_pref{"version_minor"}, $version_pref{"version_micro"},
601 $package_string;
602 &update_cmakelists_txt;
603 &update_configure_ac;
604 if ($set_version) {
605 &update_release_notes;
606 &update_debian_changelog;
607 &update_automake_lib_releases;
608 &update_cmake_lib_releases;
609 }
610 }
611  
612 sub new_version_h
613 {
614 if (!$enable_vcsversion) {
615 return "/* #undef VCSVERSION */\n";
616 }
617  
618 if ($git_description) {
619 # Do not bother adding the git branch, the git describe output
620 # normally contains the base tag and commit ID which is more
621 # than sufficient to determine the actual source tree.
622 return "#define VCSVERSION \"$git_description\"\n";
623 }
624  
625 if ($last_change && $num_commits) {
626 return "#define VCSVERSION \"$vcs_name Rev $num_commits from $repo_branch\"\n";
627 }
628  
629 return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
630 }
631  
632 # Print the version control system's version to $version_file.
633 # Don't change the file if it is not needed.
634 sub print_VCS_REVISION
635 {
636 my $VCS_REVISION;
637 my $needs_update = 1;
638  
639 $VCS_REVISION = new_version_h();
640 if (open(OLDREV, "<$version_file")) {
641 my $old_VCS_REVISION = <OLDREV>;
642 if ($old_VCS_REVISION eq $VCS_REVISION) {
643 $needs_update = 0;
644 }
645 close OLDREV;
646 }
647  
648 if (! $set_vcs) { return; }
649  
650 if ($needs_update) {
651 # print "Updating $version_file so it contains:\n$VCS_REVISION";
652 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
653 print VER "$VCS_REVISION";
654 close VER;
655 print "$version_file has been updated.\n";
656 } elsif (!$enable_vcsversion) {
657 print "$version_file disabled.\n";
658 } else {
659 print "$version_file unchanged.\n";
660 }
661 }
662  
663 # Read values from the configuration file, if it exists.
664 sub get_config {
665 my $arg;
666 my $show_help = 0;
667  
668 # Get our command-line args
669 # XXX - Do we need an option to undo --set-release?
670 GetOptions(
671 "help|h", \$show_help,
672 "get-vcs|get-svn|g", \$get_vcs,
673 "set-vcs|set-svn|s", \$set_vcs,
674 "git-bin", \$git_executable,
675 "print-vcs", \$print_vcs,
676 "set-version|v", \$set_version,
677 "set-release|r|package-version|p", \$set_release,
678 "verbose", \$verbose
679 ) || pod2usage(2);
680  
681 if ($show_help) { pod2usage(1); }
682  
683 if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
684 $set_vcs = 1;
685 }
686  
687 if ($#ARGV >= 0) {
688 $srcdir = $ARGV[0]
689 }
690  
691 if (! open(FILE, "<$vconf_file")) {
692 if (! open(FILE, "<$srcdir/$vconf_file")) {
693 print_diag "Version configuration file $vconf_file not "
694 . "found. Using defaults.\n";
695 return 1;
696 }
697 }
698  
699 while (<FILE>) {
700 s/^\s+|\s+$//g; # chomp() may not handle CR
701 next if (/^#/);
702 next unless (/^(\w+)(:|=)\s*(\S.*)/);
703 $version_pref{$1} = $3;
704 }
705 close FILE;
706 return 1;
707 }
708  
709 ##
710 ## Start of code
711 ##
712  
713 &get_config();
714  
715 &read_repo_info();
716  
717 &print_VCS_REVISION;
718  
719 if ($set_version || $set_release) {
720 if ($set_version) {
721 print "Generating version information.\n";
722 }
723  
724 if ($version_pref{"enable"} == 0) {
725 print "Release information disabled in $vconf_file.\n";
726 $set_release = 0;
727 }
728  
729 if ($set_release) {
730 print "Generating release information.\n";
731 } else {
732 print "Resetting release information\n";
733 $num_commits = 0;
734 $package_string = "";
735 }
736  
737 &update_versioned_files;
738 }
739  
740 __END__
741  
742 =head1 NAM
743  
744 make-version.pl - Get and set build-time version information for Wireshark
745  
746 =head1 SYNOPSIS
747  
748 make-version.pl [options] [source directory]
749  
750 Options:
751  
752 --help, -h This help message
753 --get-vcs, -g Print the VCS revision and source.
754 --set-vcs, -s Set the information in version.h
755 --print-vcs Print the vcs version to standard output
756 --set-version, -v Set the major, minor, and micro versions in
757 the top-level CMakeLists.txt, configure.ac,
758 docbook/asciidoc.conf, debian/changelog,
759 the Makefile.am for all libraries, and the
760 CMakeLists.txt for all libraries.
761 Resets the release information when used by
762 itself.
763 --set-release, -r Set the release information in the top-level
764 CMakeLists.txt, configure.ac
765 --package-version, -p Deprecated. Same as --set-release.
766 --verbose Print diagnostic messages to STDERR.
767  
768 Options can be used in any combination. If none are specified B<--set-vcs>
769 is assumed.
770  
771 =cut
772  
773 #
774 # Editor modelines - http://www.wireshark.org/tools/modelines.html
775 #
776 # Local variables:
777 # c-basic-offset: 8
778 # tab-width: 8
779 # indent-tabs-mode: t
780 # End:
781 #
782 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
783 # :indentSize=8:tabSize=8:noTabs=false:
784 #
785 #