Address to str: Missing break in switch (CID 1262416 & 1262417)
[metze/wireshark/wip.git] / make-version.pl
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 #   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.
36 #
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.
41 #
42 # Default configuration:
43 #
44 # enable: 1
45 # svn_client: 1
46 # format: SVN %Y%m%d%H%M%S
47 # pkg_enable: 1
48 # pkg_format: -%#
49
50 # XXX - We're pretty dumb about the "%#" substitution, and about having
51 # spaces in the package format.
52
53 use strict;
54
55 use Time::Local;
56 use File::Basename;
57 use POSIX qw(strftime);
58 use Getopt::Long;
59 use Pod::Usage;
60 use IO::Handle;
61 use English;
62
63 my $version_file = 'version.h';
64 my $package_string = "";
65 my $vconf_file = 'version.conf';
66 my $tortoise_file = "tortoise_template";
67 my $last_change = 0;
68 my $num_commits = 0;
69 my $commit_id = '';
70 my $repo_branch = "unknown";
71 my $git_description = undef;
72 my $get_svn = 0;
73 my $set_svn = 0;
74 my $set_version = 0;
75 my $set_release = 0;
76 my %version_pref = (
77         "version_major" => 1,
78         "version_minor" => 99,
79         "version_micro" => 2,
80         "version_build" => 0,
81
82         "enable"        => 1,
83         "git_client"    => 0,
84         "svn_client"    => 1,
85         "tortoise_svn"  => 0,
86         "format"        => "git %Y%m%d%H%M%S",
87         "is_release"    => 0,
88
89         # Normal development builds
90         "pkg_enable" => 1,
91         "pkg_format" => "-%#",
92
93         # Development releases
94         #"pkg_enable" => 0,
95         #"pkg_format" => "",
96         );
97 my $srcdir = ".";
98 my $info_cmd = "";
99
100 # Ensure we run with correct locale
101 $ENV{LANG} = "C";
102 $ENV{LC_ALL} = "C";
103 $ENV{GIT_PAGER} = "";
104
105 # Run "svn info".  Parse out the most recent modification time and the
106 # revision number.
107 sub read_repo_info {
108         my $line;
109         my $version_format = $version_pref{"format"};
110         my $package_format = "";
111         my $in_entries = 0;
112         my $svn_name;
113         my $repo_version;
114         my $repo_root = undef;
115         my $repo_url = undef;
116         my $do_hack = 1;
117         my $info_source = "Unknown";
118
119         if ($version_pref{"pkg_enable"} > 0) {
120                 $package_format = $version_pref{"pkg_format"};
121         }
122
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)";
132         }
133
134         #Git can give us:
135         #
136         # A big ugly hash: git rev-parse HEAD
137         # 1ddc83849075addb0cac69a6fe3782f4325337b9
138         #
139         # A small ugly hash: git rev-parse --short HEAD
140         # 1ddc838
141         #
142         # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
143         # origin/master
144         #
145         # A version description: git describe --tags --dirty
146         # wireshark-1.8.12-15-g1ddc838
147         #
148         # Number of commits in this branch: git rev-list --count HEAD
149         # 48879
150         #
151         # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
152         # 320
153         #
154         # Refs: git ls-remote code.wireshark.org:wireshark
155         # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
156
157         if ($version_pref{"git_client"}) {
158                 eval {
159                         use warnings "all";
160                         no warnings "all";
161
162                         chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
163                         if ($? == 0 && length($line) > 1) {
164                                 $last_change = $line;
165                         }
166
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];
174                         }
175
176                         chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
177                         if (defined($line)) {
178                                 $repo_url = $line;
179                         }
180
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);
186                         }
187
188                         1;
189                 };
190
191                 if ($last_change && $num_commits && $repo_url && $repo_branch) {
192                         $do_hack = 0;
193                 }
194         } elsif ($version_pref{"svn_client"}) {
195                 eval {
196                         use warnings "all";
197                         no warnings "all";
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);
202                                 }
203                                 if ($line =~ /Last Changed Rev: (\d+)/) {
204                                         $num_commits = $1;
205                                 }
206                                 if ($line =~ /URL: (\S+)/) {
207                                         $repo_url = $1;
208                                 }
209                                 if ($line =~ /Repository Root: (\S+)/) {
210                                         $repo_root = $1;
211                                 }
212                         }
213                         1;
214                 };
215
216                 if ($last_change && $num_commits && $repo_url && $repo_root) {
217                         $do_hack = 0;
218                 }
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";
224                 close(TORTOISE);
225
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) {
230                         $do_hack = 0;
231                 }
232
233                 #clean up the template file
234                 unlink($tortoise_file);
235         }
236
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+)/) {
244                                 $num_commits = $1;
245                                 $do_hack = 0;
246                                 last;
247                         }
248                 }
249                 close (CFGNMAKE);
250         }
251         if ($num_commits == 0 and -d "$srcdir/.git") {
252
253                 # Try git...
254                 eval {
255                         use warnings "all";
256                         no warnings "all";
257                         # If someone had properly tagged 1.9.0 we could also use
258                         # "git describe --abbrev=1 --tags HEAD"
259
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+)/) {
264                                         $num_commits = $1;
265                                 }
266                         }
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);
272                                 }
273                         }
274                         $info_cmd = "(cd $srcdir; git branch)";
275                         $line = qx{$info_cmd};
276                         if (defined($line)) {
277                                 if ($line =~ /\* (\S+)/) {
278                                         $repo_branch = $1;
279                                 }
280                         }
281                         1;
282                         };
283         }
284         if ($num_commits == 0 and -d "$srcdir/.bzr") {
285
286                 # Try bzr...
287                 eval {
288                         use warnings "all";
289                         no warnings "all";
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);
295                                 }
296                                 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
297                                         $num_commits = $1;
298                                         $repo_branch = $2;
299                                 }
300                         }
301                         1;
302                         };
303         }
304
305
306         # 'svn info' failed or the user really wants us to dig around in .svn/entries
307         if ($do_hack) {
308                 # Start of ugly internal SVN file hack
309                 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
310                         print ("Unable to open $srcdir/.svn/entries\n");
311                 } else {
312                         $info_source = "Prodding .svn";
313                         # We need to find out whether our parser can handle the entries file
314                         $line = <ENTRIES>;
315                         chomp $line;
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";
320                         } else {
321                                 $repo_version = "unknown";
322                         }
323
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/) {
328                                                 $in_entries = 1;
329                                                 $svn_name = "";
330                                         }
331                                         if ($in_entries) {
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);
335                                                 }
336                                                 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
337                                         }
338                                         if ($line =~ /\/>/) {
339                                                 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
340                                                                 $last_change && $num_commits) {
341                                                         $in_entries = 0;
342                                                         last;
343                                                 }
344                                         }
345                                         # XXX - Fetch the repository root & URL
346                                 }
347                         }
348                         close ENTRIES;
349                 }
350         }
351
352         # If we picked up the revision and modification time,
353         # generate our strings.
354         if ($version_pref{"pkg_enable"}) {
355                 $version_format =~ s/%#/$num_commits/;
356                 $package_format =~ s/%#/$num_commits-$commit_id/;
357                 $package_string = strftime($package_format, gmtime($last_change));
358         }
359
360         if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
361                 $repo_branch = substr($repo_url, length($repo_root));
362         }
363
364         if ($get_svn) {
365                 print <<"Fin";
366 Commit distance : $num_commits
367 Commit ID       : $commit_id
368 Revision source : $info_source
369 Release stamp   : $package_string
370 Fin
371         }
372 }
373
374
375 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
376 # lines
377 # set(PROJECT_MAJOR_VERSION 1)
378 # set(PROJECT_MINOR_VERSION 99)
379 # set(PROJECT_PATCH_VERSION 0)
380 # set(PROJECT_VERSION_EXTENSION "-rc5")
381 sub update_cmakelists_txt
382 {
383         my $line;
384         my $contents = "";
385         my $version = "";
386         my $filepath = "$srcdir/CMakeLists.txt";
387
388         return if (!$set_version && $package_string eq "");
389
390         open(CFGIN, "< $filepath") || die "Can't read $filepath!";
391         while ($line = <CFGIN>) {
392                 if ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*([\r\n]+)$/) {
393                         $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
394                 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*([\r\n]+)$/) {
395                         $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
396                 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*([\r\n]+)$/) {
397                         $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
398                 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION.*([\r\n]+)$/) {
399                         $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
400                 }
401                 $contents .= $line
402         }
403
404         open(CFGIN, "> $filepath") || die "Can't write $filepath!";
405         print(CFGIN $contents);
406         close(CFGIN);
407         print "$filepath has been updated.\n";
408 }
409
410 # Read configure.ac, then write it back out with an updated
411 # "AC_INIT" line.
412 sub update_configure_ac
413 {
414         my $line;
415         my $contents = "";
416         my $version = "";
417         my $filepath = "$srcdir/configure.ac";
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 =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
424                         $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
425                 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
426                         $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
427                 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
428                         $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
429                 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
430                         $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
431                 }
432                 $contents .= $line
433         }
434
435         open(CFGIN, "> $filepath") || die "Can't write $filepath!";
436         print(CFGIN $contents);
437         close(CFGIN);
438         print "$filepath has been updated.\n";
439 }
440
441 # Read config.nmake, then write it back out with an updated
442 # "VERSION" line.
443 sub update_config_nmake
444 {
445         my $line;
446         my $contents = "";
447         my $version = "";
448         my $filepath = "$srcdir/config.nmake";
449         my $win_package_string = "\$(WIRESHARK_VERSION_EXTRA)";
450
451         if ($package_string ne "") { $win_package_string = $package_string; }
452
453
454         open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
455         while ($line = <CFGNMAKE>) {
456                 if ($line =~ /^GIT_REVISION=.*([\r\n]+)$/) {
457                         $line = sprintf("GIT_REVISION=%d$1", $num_commits);
458                 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
459                         $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
460                 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
461                         $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
462                 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
463                         $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
464                 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
465                         $line = "VERSION_EXTRA=$win_package_string$1";
466                 }
467                 $contents .= $line
468         }
469
470         open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
471         print(CFGNMAKE $contents);
472         close(CFGNMAKE);
473         print "$filepath has been updated.\n";
474 }
475
476 # Read docbook/asciidoc.conf, then write it back out with an updated
477 # wireshark-version replacement line.
478 sub update_release_notes
479 {
480         my $line;
481         my $contents = "";
482         my $version = "";
483         my $filepath = "$srcdir/docbook/asciidoc.conf";
484
485         return if (!$set_version);
486
487         open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
488         while ($line = <ADOC_CONF>) {
489                 # wireshark-version:\[\]=1.9.1
490
491                 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
492                         $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
493                                         $version_pref{"version_major"},
494                                         $version_pref{"version_minor"},
495                                         $version_pref{"version_micro"},
496                                        );
497                 }
498                 $contents .= $line
499         }
500
501         open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
502         print(ADOC_CONF $contents);
503         close(ADOC_CONF);
504         print "$filepath has been updated.\n";
505 }
506
507 # Read debian/changelog, then write back out an updated version.
508 sub update_debian_changelog
509 {
510         my $line;
511         my $contents = "";
512         my $version = "";
513         my $filepath = "$srcdir/debian/changelog";
514
515         return if ($set_version == 0);
516
517         open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
518         while ($line = <CHANGELOG>) {
519                 if ($set_version && CHANGELOG->input_line_number() == 1) {
520                         $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
521                                         $version_pref{"version_major"},
522                                         $version_pref{"version_minor"},
523                                         $version_pref{"version_micro"},
524                                        );
525                 }
526                 $contents .= $line
527         }
528
529         open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
530         print(CHANGELOG $contents);
531         close(CHANGELOG);
532         print "$filepath has been updated.\n";
533 }
534
535 # Read Makefile.am for each library, then write back out an updated version.
536 sub update_lib_releases
537 {
538         my $line;
539         my $contents = "";
540         my $version = "";
541         my $filedir;
542         my $filepath;
543
544         return if (!$set_version);
545
546         # The Libtool manual says
547         #   "If the library source code has changed at all since the last
548         #    update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
549         # epan changes with each minor release, almost by definition. wiretap
550         # changes with *most* releases.
551         #
552         # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
553         for $filedir ("epan", "wiretap") {      # "wsutil"
554                 $contents = "";
555                 $filepath = $filedir . "/Makefile.am";
556                 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
557                 while ($line = <MAKEFILE_AM>) {
558                         # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
559
560                         if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
561                                 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
562                         }
563                         $contents .= $line
564                 }
565
566                 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
567                 print(MAKEFILE_AM $contents);
568                 close(MAKEFILE_AM);
569                 print "$filepath has been updated.\n";
570         }
571 }
572
573 # Update distributed files that contain any version information
574 sub update_versioned_files
575 {
576         &update_cmakelists_txt;
577         &update_configure_ac;
578         &update_config_nmake;
579         &update_release_notes;
580         &update_debian_changelog;
581         &update_lib_releases;
582 }
583
584 # Print the SVN version to $version_file.
585 # Don't change the file if it is not needed.
586 sub print_GIT_REVISION
587 {
588         my $GIT_REVISION;
589         my $needs_update = 1;
590
591         if ($git_description) {
592                 $GIT_REVISION = "#define GITVERSION \"" .
593                         $git_description . "\"\n" .
594                         "#define GITBRANCH \"" . $repo_branch . "\"\n";
595         } elsif ($last_change && $num_commits) {
596                 $GIT_REVISION = "#define GITVERSION \"Git Rev " .
597                         $num_commits . "\"\n" .
598                         "#define GITBRANCH \"" . $repo_branch . "\"\n";
599         } else {
600                 $GIT_REVISION = "#define GITVERSION \"Git Rev Unknown\"\n" .
601                         "#define GITBRANCH \"unknown\"\n";
602         }
603         if (open(OLDREV, "<$version_file")) {
604                 my $old_GIT_REVISION = <OLDREV> . <OLDREV>;
605                 if ($old_GIT_REVISION eq $GIT_REVISION) {
606                         $needs_update = 0;
607                 }
608                 close OLDREV;
609         }
610
611         if (! $set_svn) { return; }
612
613         if ($needs_update) {
614                 # print "Updating $version_file so it contains:\n$GIT_REVISION";
615                 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
616                 print VER "$GIT_REVISION";
617                 close VER;
618                 print "$version_file has been updated.\n";
619         } else {
620                 print "$version_file unchanged.\n";
621         }
622 }
623
624 # Read values from the configuration file, if it exists.
625 sub get_config {
626         my $arg;
627         my $show_help = 0;
628
629         # Get our command-line args
630         # XXX - Do we need an option to undo --set-release?
631         GetOptions(
632                    "help|h", \$show_help,
633                    "get-svn|g", \$get_svn,
634                    "set-svn|s", \$set_svn,
635                    "set-version|v", \$set_version,
636                    "set-release|r|package-version|p", \$set_release
637                    ) || pod2usage(2);
638
639         if ($show_help) { pod2usage(1); }
640
641         if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
642                 $set_svn = 1;
643         }
644
645         if ($#ARGV >= 0) {
646                 $srcdir = $ARGV[0]
647         }
648
649         if (! open(FILE, "<$vconf_file")) {
650                 print STDERR "Version configuration file $vconf_file not "
651                 . "found.  Using defaults.\n";
652                 return 1;
653         }
654
655         while (<FILE>) {
656                 s/^\s+|\s+$//g; # chomp() may not handle CR
657                 next if (/^#/);
658                 next unless (/^(\w+)(:|=)\s*(\S.*)/);
659                 $version_pref{$1} = $3;
660         }
661         close FILE;
662         return 1;
663 }
664
665 ##
666 ## Start of code
667 ##
668
669 &get_config();
670
671 &read_repo_info();
672
673 &print_GIT_REVISION;
674
675 if ($set_version || $set_release) {
676         if ($set_version) {
677                 print "Generating version information\n";
678         }
679
680         if ($version_pref{"enable"} == 0) {
681                 print "Release information disabled in $vconf_file.\n";
682                 $set_release = 0;
683         }
684
685         if ($set_release) {
686                 print "Generating release information\n";
687         } else {
688                 print "Resetting release information\n";
689                 $num_commits = 0;
690                 $package_string = "";
691         }
692
693         &update_versioned_files;
694 }
695
696 __END__
697
698 =head1 NAM
699
700 make-version.pl - Get and set build-time version information for Wireshark
701
702 =head1 SYNOPSIS
703
704 make-version.pl [options] [source directory]
705
706   Options:
707
708     --help, -h                 This help message
709     --get-svn, -g              Print the SVN revision and source.
710     --set-svn, -s              Set the information in version.h
711     --set-version, -v          Set the major, minor, and micro versions in
712                                configure.ac, config.nmake, debian/changelog,
713                                and docbook/asciidoc.conf.
714                                Resets the release information when used by
715                                itself.
716     --set-release, -r          Set the release information in configure.ac
717                                and config.nmake
718     --package-version, -p      Deprecated. Same as --set-release.
719
720 Options can be used in any combination. If none are specified B<--set-svn>
721 is assumed.
722
723 =cut
724
725 #
726 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
727 #
728 # Local variables:
729 # c-basic-offset: 8
730 # tab-width: 8
731 # indent-tabs-mode: t
732 # End:
733 #
734 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
735 # :indentSize=8:tabSize=8:noTabs=false:
736 #
737 #