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