24
# Subroutine to lexicographically compare two version strings, a and b.
25
# If a > b, 1 is returned.
26
# If a == b, 0 is returned.
27
# If a < b, -1 is returned.
29
# If the strings are of uneven number length then the shorter string is
30
# prepended by enough zeroes to make the two string lengths equal in order to
31
# allow an accurate comparison. Note that the zero-padding only occurs in
32
# between version separators (i.e. 1.6 and 1.10, results in 1.06 vs. 1.10).
33
# Parts of the version ending in -foo (or any other text) are not considered
34
# when doing the compare. (i.e. 2.53a vs 2.53 doesn't end up in 2.53a vs.
40
# Split the strings up by '.' (version separator) and start comparing digit
43
my @aParts = split(/\./, $a);
44
my @bParts = split(/\./, $b);
46
# Make the arrays equal in length by adding missing zeroes to the end of the
48
push @aParts, '0' while scalar @aParts < scalar @bParts;
49
push @bParts, '0' while scalar @bParts < scalar @aParts;
51
# Now compare each individual portion.
52
for (my $i = 0; $i < scalar @aParts; ++$i)
54
# Make sure that any portion that has numbers is contiguous. I'm sure
55
# there's a technique for saving stuff like 2.52a2 but I don't feel
56
# like implementing it.
57
if ($aParts[$i] !~ /^[^\d]*\d+[^\d]*$/ or
58
$bParts[$i] !~ /^[^\d]*\d+[^\d]*$/)
60
die "Not able to compare $a to $b!\n";
63
my ($aDigits) = ($aParts[$i] =~ /(\d+)/);
64
my ($bDigits) = ($bParts[$i] =~ /(\d+)/);
66
# Perl is $MODERATELY_INSULTING_TERM, don't remove the parentheses in
67
# the delta calculation below.
68
my $delta = (length $aDigits) - (length $bDigits);
69
if ($delta < 0) # b is longer
71
my $replacement = ('0' x (-$delta)) . $aDigits;
72
$aParts[$i] =~ s/$aDigits/$replacement/;
74
elsif ($delta > 0) # a is longer
76
my $replacement = ('0' x $delta) . $bDigits;
77
$bParts[$i] =~ s/$bDigits/$replacement/;
81
# Arrays now have standardized version components, let's re-merge them
82
# to strings to do the compare.
83
my $newA = join('.', @aParts);
84
my $newB = join('.', @bParts);
86
return 1 if ($newA gt $newB);
87
return -1 if ($newA lt $newB);
24
91
# Subroutine to determine the highest installed version of the given program,
25
92
# searching from the given paths.
45
113
next unless -x $file;
47
115
($version) = $file =~ /$prefix\/$program-?(.*)$/;
48
$version =~ s/-|\.//g;
49
# Don't check the -wrapper ones
50
next if $version eq "wrapper";
117
# Don't check the -wrapper ones (or any other non program one).
118
# The real deal should start with a version number, or have no
120
next if $version =~ /^[^\d]/;
52
122
# Special case some programs to make sure it has a minimum version.
53
123
if (not $version and exists $minimumVersions{$program})
56
126
my $versionOutput = `$program --version 2>/dev/null | head -n 1`;
58
128
# If we can't run the script to get the version it likely won't work later.
59
next unless $versionOutput;
129
next unless $versionOutput;
61
131
# Use number.number for version (we don't need the excess in general).
62
($versionOutput) = ($versionOutput =~ /(\d\.\d)/);
64
# Use lt to do lexicographical comparison of strings (which should be
65
# equivalent and doesn't involve issues with floating point conversions).
66
if (not $versionOutput or $versionOutput lt $min_version)
132
($versionOutput) = ($versionOutput =~ /(\d+\.\d+)/);
134
# compareVersions returns -1 if the left argument is less than
135
# the right argument. It can also die for invalid input so
138
$sgn = compareVersions($versionOutput, $min_version);
141
# $@ would be set if an error was encountered.
142
if ($@ or not $versionOutput or $sgn == -1) {
80
155
$versions{$version} = $file;
82
157
# Use string comparison so that e.g. 253a will be > 253 but < 254.
83
if ($version gt $best_version_found)
158
# See above about the need for eval.
160
$sgn = compareVersions($version, $best_version_found);
163
if (not $@ and $sgn == 1)
85
165
$best_version_found = $version;
141
221
($automake_suffix) = $automake =~ /.*automake(.*)$/;
143
# Use unsermake if we found it.
144
$automake = "$unsermake -c" if $unsermake;
146
223
# Find matching automake companions.
147
224
$aclocal = findProgram('aclocal', $automake_suffix);
226
# Use unsermake if we found it.
227
$automake = "$unsermake -c" if ($unsermake and $aclocal);
149
229
$which = findWhich();
151
231
# Make sure we have all of the needed programs.