~ubuntu-branches/ubuntu/hardy/kdeartwork/hardy-backports

« back to all changes in this revision

Viewing changes to admin/detect-autoconf.pl

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-02-14 12:27:06 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20080214122706-hfu103z9lyvj05g5
Tags: 4:3.5.9-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    return "";
22
22
}
23
23
 
 
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.
 
28
#
 
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.
 
35
# 2.053)
 
36
sub compareVersions
 
37
{
 
38
    my ($a, $b) = @_;
 
39
 
 
40
    # Split the strings up by '.' (version separator) and start comparing digit
 
41
    # length.
 
42
 
 
43
    my @aParts = split(/\./, $a);
 
44
    my @bParts = split(/\./, $b);
 
45
 
 
46
    # Make the arrays equal in length by adding missing zeroes to the end of the
 
47
    # version.
 
48
    push @aParts, '0' while scalar @aParts < scalar @bParts;
 
49
    push @bParts, '0' while scalar @bParts < scalar @aParts;
 
50
 
 
51
    # Now compare each individual portion.
 
52
    for (my $i = 0; $i < scalar @aParts; ++$i)
 
53
    {
 
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]*$/)
 
59
        {
 
60
            die "Not able to compare $a to $b!\n";
 
61
        }
 
62
 
 
63
        my ($aDigits) = ($aParts[$i] =~ /(\d+)/);
 
64
        my ($bDigits) = ($bParts[$i] =~ /(\d+)/);
 
65
 
 
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
 
70
        {
 
71
            my $replacement = ('0' x (-$delta)) . $aDigits;
 
72
            $aParts[$i] =~ s/$aDigits/$replacement/;
 
73
        }
 
74
        elsif ($delta > 0) # a is longer
 
75
        {
 
76
            my $replacement = ('0' x $delta) . $bDigits;
 
77
            $bParts[$i] =~ s/$bDigits/$replacement/;
 
78
        }
 
79
    }
 
80
 
 
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);
 
85
 
 
86
    return 1 if ($newA gt $newB);
 
87
    return -1 if ($newA lt $newB);
 
88
    return 0;
 
89
}
 
90
 
24
91
# Subroutine to determine the highest installed version of the given program,
25
92
# searching from the given paths.
26
93
sub findBest
29
96
    my $best_version_found = '0'; # Deliberately a string.
30
97
    my %versions;
31
98
    my %minimumVersions = (
32
 
        'autoconf' => '2.5',
 
99
        'autoconf' => '2.5',
33
100
        'automake' => '1.6',
34
101
    );
 
102
    my $sgn; # Used for compareVersions results.
35
103
 
36
104
    # Allow user to use environment variable to override search.
37
105
    return $ENV{uc $program} if $ENV{uc $program};
45
113
            next unless -x $file;
46
114
 
47
115
            ($version) = $file =~ /$prefix\/$program-?(.*)$/;
48
 
            $version =~ s/-|\.//g;
49
 
            # Don't check the -wrapper ones
50
 
            next if $version eq "wrapper";
 
116
 
 
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
 
119
            # suffix at all.
 
120
            next if $version =~ /^[^\d]/;
51
121
 
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`;
57
127
 
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;
60
130
 
61
131
                # Use number.number for version (we don't need the excess in general).
62
 
                ($versionOutput) = ($versionOutput =~ /(\d\.\d)/);
63
 
 
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)
67
 
                {
 
132
                ($versionOutput) = ($versionOutput =~ /(\d+\.\d+)/);
 
133
 
 
134
                # compareVersions returns -1 if the left argument is less than
 
135
                # the right argument.  It can also die for invalid input so
 
136
                # wrap with eval.
 
137
                eval {
 
138
                    $sgn = compareVersions($versionOutput, $min_version);
 
139
                };
 
140
 
 
141
                # $@ would be set if an error was encountered.
 
142
                if ($@ or not $versionOutput or $sgn == -1) {
68
143
                    next;
69
144
                }
70
145
            }
80
155
            $versions{$version} = $file;
81
156
 
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.
 
159
            eval {
 
160
                $sgn = compareVersions($version, $best_version_found);
 
161
            };
 
162
 
 
163
            if (not $@ and $sgn == 1)
84
164
            {
85
165
                $best_version_found = $version;
86
166
            }
140
220
 
141
221
($automake_suffix) = $automake =~ /.*automake(.*)$/;
142
222
 
143
 
# Use unsermake if we found it.
144
 
$automake = "$unsermake -c" if $unsermake;
145
 
 
146
223
# Find matching automake companions.
147
224
$aclocal = findProgram('aclocal', $automake_suffix);
148
225
 
 
226
# Use unsermake if we found it.
 
227
$automake = "$unsermake -c" if ($unsermake and $aclocal);
 
228
 
149
229
$which = findWhich();
150
230
 
151
231
# Make sure we have all of the needed programs.
153
233
{
154
234
    unless(${$i})
155
235
    {
156
 
        print "# Unable to find $i!!\n";
157
 
        exit 1;
 
236
        print STDERR "# Unable to find $i!!\n";
158
237
    }
159
238
}
160
239
 
173
252
EOF
174
253
 
175
254
exit 0;
 
255
 
 
256
# vim: set noet ts=8 sw=4: