Add preferences for related packets and the scroll bar minimap.
[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 # git_client: 0
49 # svn_client: 0
50 # tortoise_svn: 0
51 # format: git %Y%m%d%H%M%S
52 # pkg_enable: 1
53 # pkg_format: -%#
54
55 # XXX - We're pretty dumb about the "%#" substitution, and about having
56 # spaces in the package format.
57
58 use strict;
59
60 use Time::Local;
61 use File::Basename;
62 use POSIX qw(strftime);
63 use Getopt::Long;
64 use Pod::Usage;
65 use IO::Handle;
66 use English;
67
68 my $version_file = 'version.h';
69 my $package_string = "";
70 my $vconf_file = 'version.conf';
71 my $vcs_name = "Git";
72 my $tortoise_file = "tortoise_template";
73 my $last_change = 0;
74 my $num_commits = 0;
75 my $commit_id = '';
76 my $repo_branch = "unknown";
77 my $git_description = undef;
78 my $get_vcs = 0;
79 my $set_vcs = 0;
80 my $print_vcs = 0;
81 my $set_version = 0;
82 my $set_release = 0;
83 my %version_pref = (
84         "version_major" => 2,
85         "version_minor" => 1,
86         "version_micro" => 0,
87         "version_build" => 0,
88
89         "enable"        => 1,
90         "git_client"    => 0,   # set if .git found and .git/svn not found
91         "svn_client"    => 0,   # set if .svn found
92         "tortoise_svn"  => 0,
93         "format"        => "git %Y%m%d%H%M%S",
94
95         # Normal development builds
96         "pkg_enable" => 1,
97         "pkg_format" => "-%#",
98
99         # Development releases
100         #"pkg_enable" => 0,
101         #"pkg_format" => "",
102         );
103 my $srcdir = ".";
104 my $info_cmd = "";
105
106 # Ensure we run with correct locale
107 $ENV{LANG} = "C";
108 $ENV{LC_ALL} = "C";
109 $ENV{GIT_PAGER} = "";
110
111 # Attempt to get revision information from the repository.
112 sub read_repo_info {
113         my $line;
114         my $version_format = $version_pref{"format"};
115         my $package_format = "";
116         my $in_entries = 0;
117         my $svn_name;
118         my $repo_version;
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                 $version_pref{"svn_client"} = 1;
133         } elsif (-d "$srcdir/.git/svn") {
134                 $info_source = "Command line (git-svn)";
135                 $info_cmd = "(cd $srcdir; git svn info)";
136         }
137
138         #Git can give us:
139         #
140         # A big ugly hash: git rev-parse HEAD
141         # 1ddc83849075addb0cac69a6fe3782f4325337b9
142         #
143         # A small ugly hash: git rev-parse --short HEAD
144         # 1ddc838
145         #
146         # The upstream branch path: git rev-parse --abbrev-ref --symbolic-full-name @{upstream}
147         # origin/master
148         #
149         # A version description: git describe --tags --dirty
150         # wireshark-1.8.12-15-g1ddc838
151         #
152         # Number of commits in this branch: git rev-list --count HEAD
153         # 48879
154         #
155         # Number of commits since 1.8.0: git rev-list --count 5e212d72ce098a7fec4332cbe6c22fcda796a018..HEAD
156         # 320
157         #
158         # Refs: git ls-remote code.wireshark.org:wireshark
159         # ea19c7f952ce9fc53fe4c223f1d9d6797346258b (r48972, changed version to 1.11.0)
160
161         if ($version_pref{"git_client"}) {
162                 eval {
163                         use warnings "all";
164                         no warnings "all";
165
166                         chomp($line = qx{git --git-dir=$srcdir/.git log -1 --pretty=format:%at});
167                         if ($? == 0 && length($line) > 1) {
168                                 $last_change = $line;
169                         }
170
171                         # Commits since last annotated tag.
172                         chomp($line = qx{git --git-dir=$srcdir/.git describe --long --always --match "v*"});
173                         if ($? == 0 && length($line) > 1) {
174                                 my @parts = split(/-/, $line);
175                                 $git_description = $line;
176                                 $num_commits = $parts[-2];
177                                 $commit_id = $parts[-1];
178                         }
179
180                         # This will break in some cases. Hopefully not during
181                         # official package builds.
182                         chomp($line = qx{git --git-dir=$srcdir/.git rev-parse --abbrev-ref --symbolic-full-name \@\{upstream\}});
183                         if ($? == 0 && length($line) > 1) {
184                                 $repo_branch = basename($line);
185                         }
186
187                         1;
188                 };
189
190                 if ($last_change && $num_commits && $repo_branch) {
191                         $do_hack = 0;
192                 }
193         } elsif ($version_pref{"svn_client"}) {
194                 my $repo_root = undef;
195                 my $repo_url = undef;
196                 eval {
197                         use warnings "all";
198                         no warnings "all";
199                         $line = qx{$info_cmd};
200                         if (defined($line)) {
201                                 if ($line =~ /Last Changed Date: (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
202                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
203                                 }
204                                 if ($line =~ /Last Changed Rev: (\d+)/) {
205                                         $num_commits = $1;
206                                 }
207                                 if ($line =~ /URL: (\S+)/) {
208                                         $repo_url = $1;
209                                 }
210                                 if ($line =~ /Repository Root: (\S+)/) {
211                                         $repo_root = $1;
212                                 }
213                                 $vcs_name = "SVN";
214                         }
215                         1;
216                 };
217
218                 if ($repo_url && $repo_root && index($repo_url, $repo_root) == 0) {
219                         $repo_branch = substr($repo_url, length($repo_root));
220                 }
221
222                 if ($last_change && $num_commits && $repo_url && $repo_root) {
223                         $do_hack = 0;
224                 }
225         } elsif ($version_pref{"tortoise_svn"}) {
226                 # Dynamically generic template file needed by TortoiseSVN
227                 open(TORTOISE, ">$tortoise_file");
228                 print TORTOISE "#define VCSVERSION \"\$WCREV\$\"\r\n";
229                 print TORTOISE "#define VCSBRANCH \"\$WCURL\$\"\r\n";
230                 close(TORTOISE);
231
232                 $info_source = "Command line (SubWCRev)";
233                 $info_cmd = "SubWCRev $srcdir $tortoise_file $version_file";
234                 my $tortoise = system($info_cmd);
235                 if ($tortoise == 0) {
236                         $do_hack = 0;
237                 }
238                 $vcs_name = "SVN";
239
240                 #clean up the template file
241                 unlink($tortoise_file);
242         }
243
244         if ($num_commits == 0) {
245                 # Fall back to config.nmake
246                 $info_source = "Prodding config.nmake";
247                 my $filepath = "$srcdir/config.nmake";
248                 open(CFGNMAKE, "< $filepath") || die "Can't read $filepath!";
249                 while ($line = <CFGNMAKE>) {
250                         if ($line =~ /^VCS_REVISION=(\d+)/) {
251                                 $num_commits = $1;
252                                 $do_hack = 0;
253                                 last;
254                         }
255                 }
256                 close (CFGNMAKE);
257         }
258         if ($num_commits == 0 and -d "$srcdir/.git") {
259
260                 # Try git...
261                 eval {
262                         use warnings "all";
263                         no warnings "all";
264                         # If someone had properly tagged 1.9.0 we could also use
265                         # "git describe --abbrev=1 --tags HEAD"
266
267                         $info_cmd = "(cd $srcdir; git log --format='%b' -n 1)";
268                         $line = qx{$info_cmd};
269                         if (defined($line)) {
270                                 if ($line =~ /svn path=.*; revision=(\d+)/) {
271                                         $num_commits = $1;
272                                 }
273                         }
274                         $info_cmd = "(cd $srcdir; git log --format='%ad' -n 1 --date=iso)";
275                         $line = qx{$info_cmd};
276                         if (defined($line)) {
277                                 if ($line =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
278                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
279                                 }
280                         }
281                         $info_cmd = "(cd $srcdir; git branch)";
282                         $line = qx{$info_cmd};
283                         if (defined($line)) {
284                                 if ($line =~ /\* (\S+)/) {
285                                         $repo_branch = $1;
286                                 }
287                         }
288                         1;
289                         };
290         }
291         if ($num_commits == 0 and -d "$srcdir/.bzr") {
292
293                 # Try bzr...
294                 eval {
295                         use warnings "all";
296                         no warnings "all";
297                         $info_cmd = "(cd $srcdir; bzr log -l 1)";
298                         $line = qx{$info_cmd};
299                         if (defined($line)) {
300                                 if ($line =~ /timestamp: \S+ (\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) {
301                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
302                                 }
303                                 if ($line =~ /svn revno: (\d+) \(on (\S+)\)/) {
304                                         $num_commits = $1;
305                                         $repo_branch = $2;
306                                 }
307                                 $vcs_name = "Bzr";
308                         }
309                         1;
310                         };
311         }
312
313
314         # 'svn info' failed or the user really wants us to dig around in .svn/entries
315         if ($do_hack) {
316                 # Start of ugly internal SVN file hack
317                 if (! open (ENTRIES, "< $srcdir/.svn/entries")) {
318                         print STDERR "Unable to open $srcdir/.svn/entries\n";
319                 } else {
320                         $info_source = "Prodding .svn";
321                         # We need to find out whether our parser can handle the entries file
322                         $line = <ENTRIES>;
323                         chomp $line;
324                         if ($line eq '<?xml version="1.0" encoding="utf-8"?>') {
325                                 $repo_version = "pre1.4";
326                         } elsif ($line =~ /^8$/) {
327                                 $repo_version = "1.4";
328                         } else {
329                                 $repo_version = "unknown";
330                         }
331
332                         if ($repo_version eq "pre1.4") {
333                                 # The entries schema is flat, so we can use regexes to parse its contents.
334                                 while ($line = <ENTRIES>) {
335                                         if ($line =~ /<entry$/ || $line =~ /<entry\s/) {
336                                                 $in_entries = 1;
337                                                 $svn_name = "";
338                                         }
339                                         if ($in_entries) {
340                                                 if ($line =~ /name="(.*)"/) { $svn_name = $1; }
341                                                 if ($line =~ /committed-date="(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) {
342                                                         $last_change = timegm($6, $5, $4, $3, $2 - 1, $1);
343                                                 }
344                                                 if ($line =~ /revision="(\d+)"/) { $num_commits = $1; }
345                                         }
346                                         if ($line =~ /\/>/) {
347                                                 if (($svn_name eq "" || $svn_name eq "svn:this_dir") &&
348                                                                 $last_change && $num_commits) {
349                                                         $in_entries = 0;
350                                                         last;
351                                                 }
352                                         }
353                                         # XXX - Fetch the repository root & URL
354                                 }
355                         }
356                         close ENTRIES;
357                 }
358         }
359
360         # If we picked up the revision and modification time,
361         # generate our strings.
362         if ($version_pref{"pkg_enable"}) {
363                 $version_format =~ s/%#/$num_commits/;
364                 $package_format =~ s/%#/$num_commits-$commit_id/;
365                 $package_string = strftime($package_format, gmtime($last_change));
366         }
367
368         if ($get_vcs) {
369                 print <<"Fin";
370 Commit distance : $num_commits
371 Commit ID       : $commit_id
372 Revision source : $info_source
373 Release stamp   : $package_string
374 Fin
375         } elsif ($print_vcs) {
376                 print new_version_h();
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 sub new_version_h
629 {
630         my $VCS_REVISION;
631
632         if ($git_description) {
633                 $VCS_REVISION = "#define VCSVERSION \"" .
634                         $git_description . "\"\n" .
635                         "#define VCSBRANCH \"" . $repo_branch . "\"\n";
636         } elsif ($last_change && $num_commits) {
637                 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name . " Rev " .
638                         $num_commits . "\"\n" .
639                         "#define VCSBRANCH \"" . $repo_branch . "\"\n";
640         } else {
641                 $VCS_REVISION = "#define VCSVERSION \"" . $vcs_name .
642                         " Rev Unknown\"\n" .
643                         "#define VCSBRANCH \"unknown\"\n";
644         }
645
646         return $VCS_REVISION;
647 }
648
649 # Print the version control system's version to $version_file.
650 # Don't change the file if it is not needed.
651 sub print_VCS_REVISION
652 {
653         my $VCS_REVISION = new_version_h();
654         my $needs_update = 1;
655         if (open(OLDREV, "<$version_file")) {
656                 my $old_VCS_REVISION = <OLDREV> . <OLDREV>;
657                 if ($old_VCS_REVISION eq $VCS_REVISION) {
658                         $needs_update = 0;
659                 }
660                 close OLDREV;
661         }
662
663         if (! $set_vcs) { return; }
664
665         if ($needs_update) {
666                 # print "Updating $version_file so it contains:\n$VCS_REVISION";
667                 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
668                 print VER "$VCS_REVISION";
669                 close VER;
670                 print "$version_file has been updated.\n";
671         } else {
672                 print "$version_file unchanged.\n";
673         }
674 }
675
676 # Read values from the configuration file, if it exists.
677 sub get_config {
678         my $arg;
679         my $show_help = 0;
680
681         # Get our command-line args
682         # XXX - Do we need an option to undo --set-release?
683         GetOptions(
684                    "help|h", \$show_help,
685                    "get-vcs|get-svn|g", \$get_vcs,
686                    "set-vcs|set-svn|s", \$set_vcs,
687                    "print-vcs", \$print_vcs,
688                    "set-version|v", \$set_version,
689                    "set-release|r|package-version|p", \$set_release
690                    ) || pod2usage(2);
691
692         if ($show_help) { pod2usage(1); }
693
694         if ( !( $show_help || $get_vcs || $set_vcs || $print_vcs || $set_version || $set_release ) ) {
695                 $set_vcs = 1;
696         }
697
698         if ($#ARGV >= 0) {
699                 $srcdir = $ARGV[0]
700         }
701
702         if (! open(FILE, "<$vconf_file")) {
703                 print STDERR "Version configuration file $vconf_file not "
704                 . "found.  Using defaults.\n";
705                 return 1;
706         }
707
708         while (<FILE>) {
709                 s/^\s+|\s+$//g; # chomp() may not handle CR
710                 next if (/^#/);
711                 next unless (/^(\w+)(:|=)\s*(\S.*)/);
712                 $version_pref{$1} = $3;
713         }
714         close FILE;
715         return 1;
716 }
717
718 ##
719 ## Start of code
720 ##
721
722 &get_config();
723
724 &read_repo_info();
725
726 &print_VCS_REVISION;
727
728 if ($set_version || $set_release) {
729         if ($set_version) {
730                 print "Generating version information\n";
731         }
732
733         if ($version_pref{"enable"} == 0) {
734                 print "Release information disabled in $vconf_file.\n";
735                 $set_release = 0;
736         }
737
738         if ($set_release) {
739                 print "Generating release information\n";
740         } else {
741                 print "Resetting release information\n";
742                 $num_commits = 0;
743                 $package_string = "";
744         }
745
746         &update_versioned_files;
747 }
748
749 __END__
750
751 =head1 NAM
752
753 make-version.pl - Get and set build-time version information for Wireshark
754
755 =head1 SYNOPSIS
756
757 make-version.pl [options] [source directory]
758
759   Options:
760
761     --help, -h                 This help message
762     --get-vcs, -g              Print the VCS revision and source.
763     --set-vcs, -s              Set the information in version.h
764     --print-vcs                Print the vcs version to standard output
765     --set-version, -v          Set the major, minor, and micro versions in
766                                configure.ac, config.nmake, debian/changelog,
767                                and docbook/asciidoc.conf.
768                                Resets the release information when used by
769                                itself.
770     --set-release, -r          Set the release information in configure.ac
771                                and config.nmake
772     --package-version, -p      Deprecated. Same as --set-release.
773
774 Options can be used in any combination. If none are specified B<--set-svn>
775 is assumed.
776
777 =cut
778
779 #
780 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
781 #
782 # Local variables:
783 # c-basic-offset: 8
784 # tab-width: 8
785 # indent-tabs-mode: t
786 # End:
787 #
788 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
789 # :indentSize=8:tabSize=8:noTabs=false:
790 #
791 #