3
# Try to locate best version of auto*
4
# By Michael Pyne <michael.pyne@kdemail.net>
7
# This code is public domain. You may use it however you like (including
10
# Emulate the 'which' program.
14
my @paths = split(/:/, $ENV{'PATH'});
18
return "$path/$prog" if -x "$path/$prog";
24
# Subroutine to determine the highest installed version of the given program,
25
# searching from the given paths.
28
my ($program, @paths) = @_;
29
my $best_version_found = '0'; # Deliberately a string.
31
my %minimumVersions = (
36
# Allow user to use environment variable to override search.
37
return $ENV{uc $program} if $ENV{uc $program};
41
@files = glob "$prefix/$program*";
44
# Don't check non-executable scripts.
47
($version) = $file =~ /$prefix\/$program-?(.*)$/;
48
$version =~ s/-|\.//g;
50
# Special case some programs to make sure it has a minimum version.
51
if (not $version and exists $minimumVersions{$program})
53
my $min_version = $minimumVersions{$program};
54
my $versionOutput = `$program --version 2>/dev/null | head -n 1`;
56
# If we can't run the script to get the version it likely won't work later.
57
next unless $versionOutput;
59
# Use number.number for version (we don't need the excess in general).
60
($versionOutput) = ($versionOutput =~ /(\d\.\d)/);
62
# Use lt to do lexicographical comparison of strings (which should be
63
# equivalent and doesn't involve issues with floating point conversions).
64
if (not $versionOutput or $versionOutput lt $min_version)
70
# If no version suffix then use it in favor of a versioned autotool
71
# since the ever-popular WANT_AUTOFOO should then work (in theory).
72
return $file unless $version;
74
# Emulate 'which', and abort if we've already seen this version.
75
next if exists $versions{$version};
77
# Save filename of program.
78
$versions{$version} = $file;
80
# Use string comparison so that e.g. 253a will be > 253 but < 254.
81
if ($version gt $best_version_found)
83
$best_version_found = $version;
88
return $versions{$best_version_found};
91
# Find an appropriate "which" program for later use by the shell script calling
95
for $candidate ('type -p', 'which', 'type')
97
$test = `$candidate sh 2>/dev/null`;
100
return $candidate if -x $test;
104
# Uses which() to find a program unless the user provided its path in the
105
# environment (the upper case program name is searched).
108
$suffix = ""; # For use if @_ has only one param.
109
my ($program, $suffix) = @_;
111
return $ENV{uc $program} if $ENV{uc $program};
112
return which("$program$suffix");
118
@paths = split(/:/, $ENV{'PATH'});
120
# Make sure at least /usr/bin and /usr/local/bin are in this search.
121
unshift @paths, '/usr/local/bin' unless grep $_ eq '/usr/local/bin', @paths;
122
unshift @paths, '/usr/bin' unless grep $_ eq '/usr/bin', @paths;
124
$autoconf = findBest('autoconf', @paths);
125
($autoconf_suffix) = $autoconf =~ /.*autoconf(.*)$/;
127
# Find matching autoconf companions.
128
$autoheader = findProgram('autoheader', $autoconf_suffix);
129
$autom4te = findProgram('autom4te', $autoconf_suffix);
131
# Get best automake, and look for unsermake to possibly override it.
132
$automake = findBest('automake', @paths);
134
# backward compatible: if $UNSERMAKE points to a path, use it
135
$unsermake = findProgram('unsermake') if (defined($ENV{'UNSERMAKE'}) and $ENV{'UNSERMAKE'} =~ /\//);
136
# new compatible: if it says 'yes', use the one from path
137
$unsermake = which('unsermake') if ($ENV{'UNSERMAKE'} ne 'no');
139
($automake_suffix) = $automake =~ /.*automake(.*)$/;
141
# Use unsermake if we found it.
142
$automake = "$unsermake -c" if $unsermake;
144
# Find matching automake companions.
145
$aclocal = findProgram('aclocal', $automake_suffix);
147
$which = findWhich();
149
# Make sure we have all of the needed programs.
150
for $i (qw'autoconf autoheader autom4te automake aclocal')
154
print "# Unable to find $i!!\n";
159
# Print results in eval-able form.
162
AUTOHEADER="$autoheader"
170
export AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE ACLOCAL WHICH