Add valgrind support to randpkt-test.sh.
[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                 $package_format =~ s/%#/$num_commits-$commit_id/;
379                 $package_string = strftime($package_format, gmtime($last_change));
380         }
381
382         if ($get_vcs) {
383                 print <<"Fin";
384 Commit distance : $num_commits
385 Commit ID       : $commit_id
386 Revision source : $info_source
387 Release stamp   : $package_string
388 Fin
389         } elsif ($print_vcs) {
390                 print new_version_h();
391         }
392 }
393
394
395 # Read CMakeLists.txt, then write it back out with updated "set(PROJECT_..._VERSION ...)
396 # lines
397 # set(GIT_REVISION 999)
398 # set(PROJECT_MAJOR_VERSION 1)
399 # set(PROJECT_MINOR_VERSION 99)
400 # set(PROJECT_PATCH_VERSION 0)
401 # set(PROJECT_VERSION_EXTENSION "-rc5")
402 sub update_cmakelists_txt
403 {
404         my $line;
405         my $contents = "";
406         my $version = "";
407         my $filepath = "$srcdir/CMakeLists.txt";
408
409         return if (!$set_version && $package_string eq "");
410
411         open(CFGIN, "< $filepath") || die "Can't read $filepath!";
412         while ($line = <CFGIN>) {
413                 if ($line =~ /^set *\( *GIT_REVISION .*?([\r\n]+)$/) {
414                         $line = sprintf("set(GIT_REVISION %d)$1", $num_commits);
415                 } elsif ($line =~ /^set *\( *PROJECT_MAJOR_VERSION .*?([\r\n]+)$/) {
416                         $line = sprintf("set(PROJECT_MAJOR_VERSION %d)$1", $version_pref{"version_major"});
417                 } elsif ($line =~ /^set *\( *PROJECT_MINOR_VERSION .*?([\r\n]+)$/) {
418                         $line = sprintf("set(PROJECT_MINOR_VERSION %d)$1", $version_pref{"version_minor"});
419                 } elsif ($line =~ /^set *\( *PROJECT_PATCH_VERSION .*?([\r\n]+)$/) {
420                         $line = sprintf("set(PROJECT_PATCH_VERSION %d)$1", $version_pref{"version_micro"});
421                 } elsif ($line =~ /^set *\( *PROJECT_VERSION_EXTENSION .*?([\r\n]+)$/) {
422                         $line = sprintf("set(PROJECT_VERSION_EXTENSION \"%s\")$1", $package_string);
423                 }
424                 $contents .= $line
425         }
426
427         open(CFGIN, "> $filepath") || die "Can't write $filepath!";
428         print(CFGIN $contents);
429         close(CFGIN);
430         print "$filepath has been updated.\n";
431 }
432
433 # Read docbook/attributes.asciidoc, then write it back out with an updated
434 # wireshark-version replacement line.
435 sub update_attributes_asciidoc
436 {
437         my $line;
438         my $contents = "";
439         my $version = "";
440         my $filepath = "$srcdir/docbook/attributes.asciidoc";
441
442         open(ADOC_CONF, "< $filepath") || die "Can't read $filepath!";
443         while ($line = <ADOC_CONF>) {
444                 # :wireshark-version: 2.3.1
445
446                 if ($line =~ /^:wireshark-version:.*?([\r\n]+)$/) {
447                         $line = sprintf(":wireshark-version: %d.%d.%d$1",
448                                         $version_pref{"version_major"},
449                                         $version_pref{"version_minor"},
450                                         $version_pref{"version_micro"},
451                                         );
452                 }
453                 $contents .= $line
454         }
455
456         open(ADOC_CONF, "> $filepath") || die "Can't write $filepath!";
457         print(ADOC_CONF $contents);
458         close(ADOC_CONF);
459         print "$filepath has been updated.\n";
460 }
461
462 sub update_docinfo_asciidoc
463 {
464         my $line;
465         my @paths = ("$srcdir/docbook/developer-guide-docinfo.xml",
466                         "$srcdir/docbook/user-guide-docinfo.xml");
467
468         foreach my $filepath (@paths) {
469                 my $contents = "";
470                 open(DOCINFO_XML, "< $filepath") || die "Can't read $filepath!";
471                 while ($line = <DOCINFO_XML>) {
472                         if ($line =~ /^<subtitle>For Wireshark \d.\d+<\/subtitle>([\r\n]+)$/) {
473                                 $line = sprintf("<subtitle>For Wireshark %d.%d</subtitle>$1",
474                                                 $version_pref{"version_major"},
475                                                 $version_pref{"version_minor"},
476                                                 );
477                         }
478                         $contents .= $line
479                 }
480
481                 open(DOCINFO_XML, "> $filepath") || die "Can't write $filepath!";
482                 print(DOCINFO_XML $contents);
483                 close(DOCINFO_XML);
484                 print "$filepath has been updated.\n";
485         }
486 }
487
488 # Read debian/changelog, then write back out an updated version.
489 sub update_debian_changelog
490 {
491         my $line;
492         my $contents = "";
493         my $version = "";
494         my $filepath = "$srcdir/debian/changelog";
495
496         open(CHANGELOG, "< $filepath") || die "Can't read $filepath!";
497         while ($line = <CHANGELOG>) {
498                 if ($set_version && CHANGELOG->input_line_number() == 1) {
499                         $line =~ /^.*?([\r\n]+)$/;
500                         $line = sprintf("wireshark (%d.%d.%d) unstable; urgency=low$1",
501                                         $version_pref{"version_major"},
502                                         $version_pref{"version_minor"},
503                                         $version_pref{"version_micro"},
504                                        );
505                 }
506                 $contents .= $line
507         }
508
509         open(CHANGELOG, "> $filepath") || die "Can't write $filepath!";
510         print(CHANGELOG $contents);
511         close(CHANGELOG);
512         print "$filepath has been updated.\n";
513 }
514
515 # Read CMakeLists.txt for each library, then write back out an updated version.
516 sub update_cmake_lib_releases
517 {
518         my $line;
519         my $contents = "";
520         my $version = "";
521         my $filedir;
522         my $filepath;
523
524         for $filedir ("$srcdir/epan", "$srcdir/wiretap") {      # "$srcdir/wsutil"
525                 $contents = "";
526                 $filepath = $filedir . "/CMakeLists.txt";
527                 open(CMAKELISTS_TXT, "< $filepath") || die "Can't read $filepath!";
528                 while ($line = <CMAKELISTS_TXT>) {
529                         # set(FULL_SO_VERSION "0.0.0")
530
531                         if ($line =~ /^(set\s*\(\s*FULL_SO_VERSION\s+"\d+\.\d+\.)\d+(".*[\r\n]+)$/) {
532                                 $line = sprintf("$1%d$2", $version_pref{"version_micro"});
533                         }
534                         $contents .= $line
535                 }
536
537                 open(CMAKELISTS_TXT, "> $filepath") || die "Can't write $filepath!";
538                 print(CMAKELISTS_TXT $contents);
539                 close(CMAKELISTS_TXT);
540                 print "$filepath has been updated.\n";
541         }
542 }
543
544 # Update distributed files that contain any version information
545 sub update_versioned_files
546 {
547         # Matches CMakeLists.txt
548         printf "GR: %d, MaV: %d, MiV: %d, PL: %d, EV: %s\n",
549                 $num_commits, $version_pref{"version_major"},
550                 $version_pref{"version_minor"}, $version_pref{"version_micro"},
551                 $package_string;
552         &update_cmakelists_txt;
553         if ($set_version) {
554                 &update_attributes_asciidoc;
555                 &update_docinfo_asciidoc;
556                 &update_debian_changelog;
557                 &update_cmake_lib_releases;
558         }
559 }
560
561 sub new_version_h
562 {
563         my $line;
564         if (!$enable_vcsversion) {
565                 return "/* #undef VCSVERSION */\n";
566         }
567
568         if ($git_description) {
569                 # Do not bother adding the git branch, the git describe output
570                 # normally contains the base tag and commit ID which is more
571                 # than sufficient to determine the actual source tree.
572                 return "#define VCSVERSION \"$git_description\"\n";
573         }
574
575         if ($last_change && $num_commits) {
576                 $line = sprintf("v%d.%d.%d",
577                         $version_pref{"version_major"},
578                         $version_pref{"version_minor"},
579                         $version_pref{"version_micro"},
580                         );
581                 return "#define VCSVERSION \"$line-$vcs_name-$num_commits\"\n";
582         }
583
584         return "#define VCSVERSION \"$vcs_name Rev Unknown from unknown\"\n";
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_VCS_REVISION
590 {
591         my $VCS_REVISION;
592         my $needs_update = 1;
593
594         $VCS_REVISION = new_version_h();
595         if (open(OLDREV, "<$version_file")) {
596                 my $old_VCS_REVISION = <OLDREV>;
597                 if ($old_VCS_REVISION eq $VCS_REVISION) {
598                         $needs_update = 0;
599                 }
600                 close OLDREV;
601         }
602
603         if (! $set_vcs) { return; }
604
605         if ($needs_update) {
606                 # print "Updating $version_file so it contains:\n$VCS_REVISION";
607                 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
608                 print VER "$VCS_REVISION";
609                 close VER;
610                 print "$version_file has been updated.\n";
611         } elsif (!$enable_vcsversion) {
612                 print "$version_file disabled.\n";
613         } else {
614                 print "$version_file unchanged.\n";
615         }
616 }
617
618 # Read values from the configuration file, if it exists.
619 sub get_config {
620         my $arg;
621         my $show_help = 0;
622
623         # Get our command-line args
624         # XXX - Do we need an option to undo --set-release?
625         GetOptions(
626                    "help|h", \$show_help,
627                    "get-vcs|get-svn|g", \$get_vcs,
628                    "set-vcs|set-svn|s", \$set_vcs,
629                    "print-vcs", \$print_vcs,
630                    "set-version|v", \$set_version,
631                    "set-release|r|package-version|p", \$set_release,
632                    "verbose", \$verbose
633                    ) || pod2usage(2);
634
635         if ($show_help) { pod2usage(1); }
636
637         if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
638                 $set_vcs = 1;
639         }
640
641         if ($#ARGV >= 0) {
642                 $srcdir = $ARGV[0]
643         }
644
645         if (! open(FILE, "<$vconf_file")) {
646                 if (! open(FILE, "<$srcdir/$vconf_file")) {
647                         print_diag "Version configuration file $vconf_file not "
648                         . "found. Using defaults.\n";
649                         return 1;
650                 }
651         }
652
653         while (<FILE>) {
654                 s/^\s+|\s+$//g; # chomp() may not handle CR
655                 next if (/^#/);
656                 next unless (/^(\w+)(:|=)\s*(\S.*)/);
657                 $version_pref{$1} = $3;
658         }
659         close FILE;
660         return 1;
661 }
662
663 ##
664 ## Start of code
665 ##
666
667 &get_config();
668
669 &read_repo_info();
670
671 &print_VCS_REVISION;
672
673 if ($set_version || $set_release) {
674         if ($set_version) {
675                 print "Generating version information.\n";
676         }
677
678         if ($version_pref{"enable"} == 0) {
679                 print "Release information disabled in $vconf_file.\n";
680                 $set_release = 0;
681         }
682
683         if ($set_release) {
684                 print "Generating release information.\n";
685         } else {
686                 print "Resetting release information\n";
687                 $num_commits = 0;
688                 $package_string = "";
689         }
690
691         &update_versioned_files;
692 }
693
694 __END__
695
696 =head1 NAM
697
698 make-version.pl - Get and set build-time version information for Wireshark
699
700 =head1 SYNOPSIS
701
702 make-version.pl [options] [source directory]
703
704   Options:
705
706     --help, -h                 This help message
707     --get-vcs, -g              Print the VCS revision and source.
708     --set-vcs, -s              Set the information in version.h
709     --print-vcs                Print the vcs version to standard output
710     --set-version, -v          Set the major, minor, and micro versions in
711                                the top-level CMakeLists.txt, configure.ac,
712                                docbook/attributes.asciidoc, debian/changelog,
713                                and the CMakeLists.txt for all libraries.
714                                Resets the release information when used by
715                                itself.
716     --set-release, -r          Set the release information in the top-level
717                                CMakeLists.txt, configure.ac
718     --package-version, -p      Deprecated. Same as --set-release.
719     --verbose                  Print diagnostic messages to STDERR.
720
721 Options can be used in any combination. If none are specified B<--set-vcs>
722 is assumed.
723
724 =cut
725
726 #
727 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
728 #
729 # Local variables:
730 # c-basic-offset: 8
731 # tab-width: 8
732 # indent-tabs-mode: t
733 # End:
734 #
735 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
736 # :indentSize=8:tabSize=8:noTabs=false:
737 #
738 #