Continue to remove $Id$ from top of file
[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" => 11,
79         "version_micro" => 3,
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"}) {
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 origin
143         # origin/master-1.8
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});
169                         if ($? == 0 && length($line) > 1) {
170                                 my @parts = split(/-/, $line);
171                                 $num_commits = $parts[-2];
172                                 $commit_id = $parts[-1];
173                         }
174
175                         # Current short hash prefixed with "g"
176                         chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --short HEAD});
177                         if ($? == 0 && length($line) > 1) {
178                         }
179
180                         chomp($line = qx{git --git-dir=$srcdir/.git ls-remote --get-url origin});
181                         if ($? == 0 && length($line) > 1) {
182                                 $repo_url = $line;
183                         }
184
185                         # Probably not quite what we're looking for
186                         chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name origin});
187                         if ($? == 0 && length($line) > 1) {
188                                 $repo_branch = basename($line);
189                         }
190
191                         chomp($line = qx{git --git-dir=$srcdir/.git describe --dirty --match "v*"});
192                         if ($? == 0 && length($line) > 1) {
193                                 $git_description = "wireshark-" . substr($line, 1);
194                         }
195
196                         1;
197                 };
198
199                 if ($last_change && $num_commits && $repo_url && $repo_branch) {
200                         $do_hack = 0;
201                 }
202         } elsif ($version_pref{"svn_client"}) {
203                 eval {
204                         use warnings "all";
205                         no warnings "all";
206                         $line = qx{$info_cmd};
207                         if (defined($line)) {
208                                 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
209                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
210                                 }
211                                 if ($line =~ /Last Changed Rev: (\d+)/) {
212                                         $num_commits = $1;
213                                 }
214                                 if ($line =~ /URL: (\S+)/) {
215                                         $repo_url = $1;
216                                 }
217                                 if ($line =~ /Repository Root: (\S+)/) {
218                                         $repo_root = $1;
219                                 }
220                         }
221                         1;
222                 };
223
224                 if ($last_change && $num_commits && $repo_url && $repo_root) {
225                         $do_hack = 0;
226                 }
227         } elsif ($version_pref{"tortoise_svn"}) {
228                 # Dynamically generic template file needed by TortoiseSVN
229                 open(TORTOISE, ">$tortoise_file");
230                 print TORTOISE "#define GITVERSION \"\$WCREV\$\"\r\n";
231                 print TORTOISE "#define GITBRANCH \"\$WCURL\$\"\r\n";
232                 close(TORTOISE);
233
234                 $info_source = "Command line (SubWCRev)";
235                 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
236                 my $tortoise = system($info_cmd);
237                 if ($tortoise == 0) {
238                         $do_hack = 0;
239                 }
240
241                 #clean up the template file
242                 unlink($tortoise_file);
243         }
244
245         if ($num_commits == 0) {
246                 # Fall back to config.nmake
247                 $info_source = "Prodding config.nmake";
248                 my $filepath = "$srcdir/config.nmake";
249                 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
250                 while ($line = <CFGNMAKE>) {
251                         if ($line =~ /^GIT_REVISION=(\d+)/) {
252                                 $num_commits = $1;
253                                 $do_hack = 0;
254                                 last;
255                         }
256                 }
257                 close (CFGNMAKE);
258         }
259         if ($num_commits == 0 and -d "$srcdir/.git") {
260
261                 # Try git...
262                 eval {
263                         use warnings "all";
264                         no warnings "all";
265                         # If someone had properly tagged 1.9.0 we could also use
266                         # "git describe --abbrev=1 --tags HEAD"
267                         
268                         $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
269                         $line = qx{$info_cmd};
270                         if (defined($line)) {
271                                 if ($line =~ /svn path=.*; revision=(\d+)/) {
272                                         $num_commits = $1;
273                                 }
274                         }
275                         $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
276                         $line = qx{$info_cmd};
277                         if (defined($line)) {
278                                 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
279                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
280                                 }
281                         }
282                         $info_cmd = "(cd $srcdir; git branch)";
283                         $line = qx{$info_cmd};
284                         if (defined($line)) {
285                                 if ($line =~ /\* (\S+)/) {
286                                         $repo_branch = $1;
287                                 }
288                         }
289                         1;
290                         };
291         }
292         if ($num_commits == 0 and -d "$srcdir/.bzr") {
293
294                 # Try bzr...
295                 eval {
296                         use warnings "all";
297                         no warnings "all";
298                         $info_cmd = "(cd $srcdir; bzr log -l 1)";
299                         $line = qx{$info_cmd};
300                         if (defined($line)) {
301                                 if ($line =~ /timestamp: \S+ (\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                                 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
305                                         $num_commits = $1;
306                                         $repo_branch = $2;
307                                 }
308                         }
309                         1;
310                         };
311         }
312
313
314         # 'svn info' failed or the user really wants us to dig around in .svn/entries
315         if ($do_hack) {
316                 # Start of ugly internal SVN file hack
317                 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
318                         print ("Unable to open $srcdir/.svn/entries\n");
319                 } else {
320                         $info_source = "Prodding .svn";
321                         # We need to find out whether our parser can handle the entries file
322                         $line = <ENTRIES>;
323                         chomp $line;
324                         if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
325                                 $repo_version = "pre1.4";
326                         } elsif ($line =~ /^8$/) {
327                                 $repo_version = "1.4";
328                         } else {
329                                 $repo_version = "unknown";
330                         }
331
332                         if ($repo_version eq "pre1.4") {
333                                 # The entries schema is flat, so we can use regexes to parse its contents.
334                                 while ($line = <ENTRIES>) {
335                                         if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
336                                                 $in_entries = 1;
337                                                 $svn_name = "";
338                                         }
339                                         if ($in_entries) {
340                                                 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
341                                                 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
342                                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
343                                                 }
344                                                 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
345                                         }
346                                         if ($line =~ /\/>/) {
347                                                 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
348                                                                 $last_change && $num_commits) {
349                                                         $in_entries = 0;
350                                                         last;
351                                                 }
352                                         }
353                                         # XXX - Fetch the repository root & URL
354                                 }
355                         }
356                         close ENTRIES;
357                 }
358         }
359
360         # If we picked up the revision and modification time,
361         # generate our strings.
362         if ($num_commits && $last_change) {
363                 $version_format =~ s/%#/$num_commits/;
364                 $package_format =~ s/%#/$num_commits-$commit_id/;
365                 $package_string = strftime($package_format, gmtime($last_change));
366         }
367
368         if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
369                 $repo_branch = substr($repo_url, length($repo_root));
370         }
371
372         if ($get_svn) {
373                 print <<"Fin";
374 Commit distance : $num_commits
375 Commit ID       : $commit_id
376 Revision source : $info_source
377 Release stamp   : $package_string
378 Fin
379         }
380 }
381
382
383 # Read configure.ac, then write it back out with an updated
384 # "AC_INIT" line.
385 sub update_configure_ac
386 {
387         my $line;
388         my $contents = "";
389         my $version = "";
390         my $filepath = "$srcdir/configure.ac";
391
392         return if (!$set_version && $package_string eq "");
393
394         open(CFGIN, "< $filepath") || die "Can't read $filepath!";
395         while ($line = <CFGIN>) {
396                 if ($line =~ /^m4_define\( *\[?version_major\]? *,.*([\r\n]+)$/) {
397                         $line = sprintf("m4_define([version_major], [%d])$1", $version_pref{"version_major"});
398                 } elsif ($line =~ /^m4_define\( *\[?version_minor\]? *,.*([\r\n]+)$/) {
399                         $line = sprintf("m4_define([version_minor], [%d])$1", $version_pref{"version_minor"});
400                 } elsif ($line =~ /^m4_define\( *\[?version_micro\]? *,.*([\r\n]+)$/) {
401                         $line = sprintf("m4_define([version_micro], [%d])$1", $version_pref{"version_micro"});
402                 } elsif ($line =~ /^m4_append\( *\[?version_micro_extra\]? *,.*([\r\n]+)$/) {
403                         $line = sprintf("m4_append([version_micro_extra], [%s])$1", $package_string);
404                 }
405                 $contents .= $line
406         }
407
408         open(CFGIN, "> $filepath") || die "Can't write $filepath!";
409         print(CFGIN $contents);
410         close(CFGIN);
411         print "$filepath has been updated.\n";
412 }
413
414 # Read config.nmake, then write it back out with an updated
415 # "VERSION" line.
416 sub update_config_nmake
417 {
418         my $line;
419         my $contents = "";
420         my $version = "";
421         my $filepath = "$srcdir/config.nmake";
422
423         open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
424         while ($line = <CFGNMAKE>) {
425                 if ($line =~ /^GIT_REVISION=.*([\r\n]+)$/) {
426                         $line = sprintf("GIT_REVISION=%d$1", $num_commits);
427                 } elsif ($set_version && $line =~ /^VERSION_MAJOR=.*([\r\n]+)$/) {
428                         $line = sprintf("VERSION_MAJOR=%d$1", $version_pref{"version_major"});
429                 } elsif ($set_version && $line =~ /^VERSION_MINOR=.*([\r\n]+)$/) {
430                         $line = sprintf("VERSION_MINOR=%d$1", $version_pref{"version_minor"});
431                 } elsif ($set_version && $line =~ /^VERSION_MICRO=.*([\r\n]+)$/) {
432                         $line = sprintf("VERSION_MICRO=%d$1", $version_pref{"version_micro"});
433                 } elsif ($line =~ /^VERSION_EXTRA=.*([\r\n]+)$/) {
434                         $line = "VERSION_EXTRA=$package_string$1";
435                 }
436                 $contents .= $line
437         }
438
439         open(CFGNMAKE, "> $filepath") || die "Can't write $filepath!";
440         print(CFGNMAKE $contents);
441         close(CFGNMAKE);
442         print "$filepath has been updated.\n";
443 }
444
445 # Read docbook/asciidoc.conf, then write it back out with an updated
446 # wireshark-version replacement line.
447 sub update_release_notes
448 {
449         my $line;
450         my $contents = "";
451         my $version = "";
452         my $filepath = "$srcdir/docbook/asciidoc.conf";
453
454         return if (!$set_version);
455
456         open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
457         while ($line = <ADOC_CONF>) {
458                 # wireshark-version:\[\]=1.9.1
459
460                 if ($line =~ /^wireshark-version:\\\[\\\]=.*([\r\n]+)$/) {
461                         $line = sprintf("wireshark-version:\\\[\\\]=%d.%d.%d$1",
462                                         $version_pref{"version_major"},
463                                         $version_pref{"version_minor"},
464                                         $version_pref{"version_micro"},
465                                        );
466                 }
467                 $contents .= $line
468         }
469
470         open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
471         print(ADOC_CONF $contents);
472         close(ADOC_CONF);
473         print "$filepath has been updated.\n";
474 }
475
476 # Read debian/changelog, then write back out an updated version.
477 sub update_debian_changelog
478 {
479         my $line;
480         my $contents = "";
481         my $version = "";
482         my $filepath = "$srcdir/debian/changelog";
483
484         return if ($set_version == 0);
485
486         open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
487         while ($line = <CHANGELOG>) {
488                 if ($set_version && CHANGELOG->input_line_number() == 1) {
489                         $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low\n",
490                                         $version_pref{"version_major"},
491                                         $version_pref{"version_minor"},
492                                         $version_pref{"version_micro"},
493                                        );
494                 }
495                 $contents .= $line
496         }
497
498         open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
499         print(CHANGELOG $contents);
500         close(CHANGELOG);
501         print "$filepath has been updated.\n";
502 }
503
504 # Read debian/wireshark-common.files, then write back out an updated version.
505 # The libraries updated here MUST match the updates made by update_lib_releases
506 # below. We should do this automatically.
507 sub update_debian_wcf
508 {
509         my $line;
510         my $contents = "";
511         my $version = "";
512         my $filepath = "$srcdir/debian/wireshark-common.files";
513
514         return if (!$set_version);
515
516         open(DWCF, "< $filepath") || die "Can't read $filepath!";
517         while ($line = <DWCF>) {
518                 # /usr/lib/wireshark/libwireshark.so.1.1.0
519
520                 if ($line =~ qr{^(/usr/lib/wireshark/lib(wireshark|wiretap|filetap).so\.\d+\.\d+\.)\d+$}) {
521                         $line = sprintf("$1%d\n", $version_pref{"version_micro"});
522                 }
523                 $contents .= $line
524         }
525
526         open(DWCF, "> $filepath") || die "Can't write $filepath!";
527         print(DWCF $contents);
528         close(DWCF);
529         print "$filepath has been updated.\n";
530 }
531
532 # Read Makefile.am for each library, then write back out an updated version.
533 sub update_lib_releases
534 {
535         my $line;
536         my $contents = "";
537         my $version = "";
538         my $filedir;
539         my $filepath;
540
541         return if (!$set_version);
542
543         # The Libtool manual says
544         #   "If the library source code has changed at all since the last
545         #    update, then increment revision (‘c:r:a’ becomes ‘c:r+1:a’)."
546         # epan changes with each minor release, almost by definition. wiretap
547         # and filetap changes with *most* releases.
548         #
549         # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
550         for $filedir ("epan", "wiretap", "filetap") {   # "wsutil"
551                 $contents = "";
552                 $filepath = $filedir . "/Makefile.am";
553                 open(MAKEFILE_AM, "< $filepath") || die "Can't read $filepath!";
554                 while ($line = <MAKEFILE_AM>) {
555                         # libwireshark_la_LDFLAGS = -version-info 2:1:1 -export-symbols
556
557                         if ($line =~ /^(lib\w+_la_LDFLAGS.*version-info\s+\d+:)\d+(:\d+.*)/) {
558                                 $line = sprintf("$1%d$2\n", $version_pref{"version_micro"});
559                         }
560                         $contents .= $line
561                 }
562
563                 open(MAKEFILE_AM, "> $filepath") || die "Can't write $filepath!";
564                 print(MAKEFILE_AM $contents);
565                 close(MAKEFILE_AM);
566                 print "$filepath has been updated.\n";
567         }
568 }
569
570 # Update distributed files that contain any version information
571 sub update_versioned_files
572 {
573         &update_configure_ac;
574         &update_config_nmake;
575         &update_release_notes;
576         &update_debian_changelog;
577         &update_debian_wcf;
578         &update_lib_releases;
579 }
580
581 # Print the SVN version to $version_file.
582 # Don't change the file if it is not needed.
583 sub print_GIT_REVISION
584 {
585         my $GIT_REVISION;
586         my $needs_update = 1;
587
588         if ($git_description) {
589                 $GIT_REVISION = "#define GITVERSION \"" .
590                         $git_description . "\"\n" .
591                         "#define GITBRANCH \"" . $repo_branch . "\"\n";
592         } elsif ($last_change && $num_commits) {
593                 $GIT_REVISION = "#define GITVERSION \"Git Rev " .
594                         $num_commits . "\"\n" .
595                         "#define GITBRANCH \"" . $repo_branch . "\"\n";
596         } else {
597                 $GIT_REVISION = "#define GITVERSION \"Git Rev Unknown\"\n" .
598                         "#define GITBRANCH \"unknown\"\n";
599         }
600         if (open(OLDREV, "<$version_file")) {
601                 my $old_GIT_REVISION = <OLDREV> . <OLDREV>;
602                 if ($old_GIT_REVISION eq $GIT_REVISION) {
603                         $needs_update = 0;
604                 }
605                 close OLDREV;
606         }
607
608         if (! $set_svn) { return; }
609
610         if ($needs_update) {
611                 # print "Updating $version_file so it contains:\n$GIT_REVISION";
612                 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
613                 print VER "$GIT_REVISION";
614                 close VER;
615                 print "$version_file has been updated.\n";
616         } else {
617                 print "$version_file unchanged.\n";
618         }
619 }
620
621 # Read values from the configuration file, if it exists.
622 sub get_config {
623         my $arg;
624         my $show_help = 0;
625
626         # Get our command-line args
627         # XXX - Do we need an option to undo --set-release?
628         GetOptions(
629                    "help|h", \$show_help,
630                    "get-svn|g", \$get_svn,
631                    "set-svn|s", \$set_svn,
632                    "set-version|v", \$set_version,
633                    "set-release|r|package-version|p", \$set_release
634                    ) || pod2usage(2);
635
636         if ($show_help) { pod2usage(1); }
637
638         if ( !( $show_help || $get_svn || $set_svn || $set_version || $set_release ) ) {
639                 $set_svn = 1;
640         }
641
642         if ($#ARGV >= 0) {
643                 $srcdir = $ARGV[0]
644         }
645
646         if (! open(FILE, "<$vconf_file")) {
647                 print STDERR "Version configuration file $vconf_file not "
648                 . "found.  Using defaults.\n";
649                 return 1;
650         }
651
652         while (<FILE>) {
653                 chomp;
654                 next if (/^#/);
655                 next unless (/^(\w+)(:|=)\s*(\S.*)/);
656                 $version_pref{$1} = $3;
657         }
658         close FILE;
659         return 1;
660 }
661
662 ##
663 ## Start of code
664 ##
665
666 &get_config();
667
668 &read_repo_info();
669
670 &print_GIT_REVISION;
671
672 if ($set_version || $set_release) {
673         if ($set_version) {
674                 print "Generating version information\n";
675         }
676
677         if ($version_pref{"enable"} == 0) {
678                 print "Release information disabled in $vconf_file.\n";
679                 $set_release = 0;
680         }
681
682         if ($set_release) {
683                 print "Generating release information\n";
684         } else {
685                 print "Resetting release information\n";
686                 $num_commits = 0;
687                 $package_string = "";
688         }
689
690         &update_versioned_files;
691 }
692
693 __END__
694
695 =head1 NAM
696
697 make-version.pl - Get and set build-time version information for Wireshark
698
699 =head1 SYNOPSIS
700
701 make-version.pl [options] [source directory]
702
703   Options:
704
705     --help, -h                 This help message
706     --get-svn, -g              Print the SVN revision and source.
707     --set-svn, -s              Set the information in version.h
708     --set-version, -v          Set the major, minor, and micro versions in
709                                configure.ac, config.nmake, debian/changelog,
710                                and docbook/asciidoc.conf.
711                                Resets the release information when used by
712                                itself.
713     --set-release, -r          Set the release information in configure.ac
714                                and config.nmake
715     --package-version, -p      Deprecated. Same as --set-release.
716
717 Options can be used in any combination. If none are specified B<--set-svn>
718 is assumed.
719
720 #
721 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
722 #
723 # Local variables:
724 # c-basic-offset: 8
725 # tab-width: 8
726 # indent-tabs-mode: t
727 # End:
728 #
729 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
730 # :indentSize=8:tabSize=8:noTabs=false:
731 #
732 #