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