wireshark/make-version.pl

111 lines
3.2 KiB
Perl
Raw Normal View History

#!/usr/bin/perl -w
#
# Copyright 2004 J<>rg Mayer (see AUTHORS file)
#
# $Id: make-version.pl,v 1.4 2004/01/18 05:17:23 jmayer Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@ethereal.com>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# usage: ./make-version.pl
use strict;
my ($d1,$d2,$d3,$date,$drest);
my ($wdayascii, $monthascii, $day, $time, $year);
my %asctonum = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04",
"May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08",
"Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12" );
my $current;
my $last = "";
# Recursively find all files named Entries and call lastentry on them.
# Args: Startdirectory
sub findentries {
my $currentdir = shift;
opendir(DIR, "$currentdir") || print STDERR "Opendir $currentdir failed ($!)\n" && next;
grep { (-d "$currentdir/$_" && $_ !~ /^\.(|.)$/ && &findentries("$currentdir/$_")) ||
(-f "$currentdir/$_" && $_ =~ /^Entries$/ && &lastentry("$currentdir/$_")) } readdir(DIR);
closedir DIR;
}
# Check all entries in $file. In case they are newer, update $last accordingly
# Args: Entries file
sub lastentry {
my $file = shift;
open(FILE, "<$file") || print STDERR "Open $file for reading failed ($!)\n" && return 1;
while (<FILE>) {
chomp;
# Regular lines look like this: /ethereal_be.py/1.6/Fri Aug 2 22:55:19 2002//
next if (/^D/);
($d1,$d2,$d2,$date,$drest) = split(/\//, $_, 5);
next if ($date !~ /\d:\d\d:\d\d/);
($wdayascii, $monthascii, $day, $time, $year) = split(/\s+/, $date);
$day = substr("0".$day, -2, 2);
$time =~ s/://g;
$current = "$year$asctonum{$monthascii}$day$time";
if ($current gt $last) {
$last = $current;
}
}
close FILE;
return 1;
}
&findentries(".");
# In case that there are no Entries files but the sources are based on a cvs snapshot,
# it is possible to add a file cvsversion to the toplevel directory containing the
# cvs version string YYYYMMDDhhmmss
if ($last eq "" && -f "cvsversion") {
$last = `cat cvsversion`;
}
if ( $last ne "" ) {
$last = "#define CVSVERSION \"$last\"\n";
} else {
$last = "/* #define CVSVERSION \"\" */\n";
}
# Only write to cvsversion.h, if this changes its contents: This avoids needless
# rebuilds of tethereal, mergecap etc.
my $needsupdate=0;
if (! open(OLDVER, "<cvsversion.h")) {
$needsupdate = 1;
} else {
if (<OLDVER> ne $last) {
$needsupdate = 1;
}
close OLDVER;
}
if ($needsupdate == 1) {
open(VER, ">cvsversion.h") || die ("Cannot write to cvsversion.h ($!)\n");
print VER "$last";
close VER;
}
__END__