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