3 # Copyright 2004 Jörg Mayer (see AUTHORS file)
5 # $Id: make-version.pl,v 1.7 2004/03/04 16:19:40 jmayer Exp $
7 # Ethereal - Network traffic analyzer
8 # By Gerald Combs <gerald@ethereal.com>
9 # Copyright 1998 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # usage: ./make-version.pl
27 # If "version.conf" is present, it is parsed for configuration values.
28 # Possible values are:
30 # enable - Enable or disable versioning. Zero (0) disables, nonzero
32 # format - A strftime() formatted string to use as a template for the
35 # Default configuration:
38 # format: CVS %Y%m%d%H%M%S
43 use POSIX qw(strftime);
45 my $version_file = 'cvsversion.h';
46 my $vconf_file = 'version.conf';
47 my %monthnum = ( "Jan" => "0", "Feb" => "1", "Mar" => "2", "Apr" => "3",
48 "May" => "4", "Jun" => "5", "Jul" => "6", "Aug" => "7",
49 "Sep" => "8", "Oct" => "9", "Nov" => "10", "Dec" => "11" );
51 my $last_file = undef;
52 my %version_pref = ("enable" => 1, "format" => "CVS %Y%m%d%H%M%S");
55 # Recursively find all CVS Entries files starting from the given directory,
56 # and compute the modification time of the most recently modified Entries file.
57 sub find_last_CVS_Entries {
61 opendir(DIR, "$dir") || print STDERR "Can't open directory $dir ($!)\n" && next;
62 foreach $d (readdir(DIR)) {
63 if (-d "$dir/$d" && $d !~ /^\.(|.)$/) {
65 if (-f "$dir/CVS/Entries") {
66 &lastentry("$dir/CVS/Entries");
68 } else { # Recurse in directory
69 &find_last_CVS_Entries("$dir/$d");
77 # Check all entries in $file. In case they are newer, update $last accordingly
81 my ($wdayascii, $monthascii, $day, $time, $year);
85 open(FILE, "<$file") || print STDERR "Open $file for reading failed ($!)\n" && return 1;
89 # Regular lines look like this: /ethereal_be.py/1.6/Fri Aug 2 22:55:19 2002//
91 $date = (split(/\//, $_, 5))[3];
92 # Month Day Hour Minute Second Year
93 next if ($date !~ /\w{3} (\w{3}) (.\d) (\d\d):(\d\d):(\d\d) (\d{4})/);
94 $current = timegm($5, $4, $3, $2, $monthnum{$1}, $6);
96 if ($current > $last) {
105 # Print the CVS version to $version_file.
106 # Don't change the file if it is not needed.
107 sub print_cvs_version
110 my $needs_update = 1;
113 $cvs_version = "#define CVSVERSION \"" .
114 strftime($version_pref{"format"}, gmtime($last)) .
117 $cvs_version = "/* #define CVSVERSION \"\" */\n";
119 if (open(OLDVER, "<$version_file")) {
120 if (<OLDVER> eq $cvs_version) {
121 print "$version_file is up-to-date.\n";
127 if ($needs_update == 1) {
128 # print "Updating $version_file so it contains:\n$cvs_version";
129 open(VER, ">$version_file") || die ("Cannot write to $version_file ($!)\n");
130 print VER "$cvs_version";
132 print "$version_file has been updated.\n";
136 # Read values from the configuration file, if it exists.
138 open(FILE, "<$vconf_file") || print STDERR "Version configuration file $vconf_file not found. Using defaults.\n" && return 1;
143 next unless (/^(\w+):\s+(\S.*)/);
144 $version_pref{$1} = $2;
156 if ($version_pref{"enable"} == 0) {
157 print "Version tag disabled in $vconf_file.\n";
158 } elsif (-d "./CVS") {
159 print "This is a build from CVS (or a CVS snapshot), "
160 . "CVS version tag will be computed.\n";
161 &find_last_CVS_Entries(".");
163 print "This is not a CVS build.\n";
166 # Now that we've computed everything, print the CVS version to $version_file