aboutsummaryrefslogtreecommitdiffstats
path: root/make-version.pl
blob: 79d9118023aed18e722577c747d4557b3eb7f69f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/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__