88 |
andreas |
1 |
#!/usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
# Try to locate best version of auto*
|
|
|
4 |
# By Michael Pyne <michael.pyne@kdemail.net>
|
|
|
5 |
#
|
|
|
6 |
# Copyright (c) 2005.
|
|
|
7 |
# This code is public domain. You may use it however you like (including
|
|
|
8 |
# relicensing).
|
|
|
9 |
|
|
|
10 |
# Emulate the 'which' program.
|
|
|
11 |
sub which
|
|
|
12 |
{
|
|
|
13 |
my $prog = shift;
|
|
|
14 |
my @paths = split(/:/, $ENV{'PATH'});
|
|
|
15 |
|
|
|
16 |
for $path (@paths)
|
|
|
17 |
{
|
|
|
18 |
return "$path/$prog" if -x "$path/$prog";
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
return "";
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
# Subroutine to determine the highest installed version of the given program,
|
|
|
25 |
# searching from the given paths.
|
|
|
26 |
sub findBest
|
|
|
27 |
{
|
|
|
28 |
my ($program, @paths) = @_;
|
|
|
29 |
my $best_version_found = '0'; # Deliberately a string.
|
|
|
30 |
my %versions;
|
|
|
31 |
my %minimumVersions = (
|
|
|
32 |
'autoconf' => '2.5',
|
|
|
33 |
'automake' => '1.6',
|
|
|
34 |
);
|
|
|
35 |
|
|
|
36 |
# Allow user to use environment variable to override search.
|
|
|
37 |
return $ENV{uc $program} if $ENV{uc $program};
|
|
|
38 |
|
|
|
39 |
for $prefix (@paths)
|
|
|
40 |
{
|
|
|
41 |
@files = glob "$prefix/$program*";
|
|
|
42 |
for $file (@files)
|
|
|
43 |
{
|
|
|
44 |
# Don't check non-executable scripts.
|
|
|
45 |
next unless -x $file;
|
|
|
46 |
|
|
|
47 |
($version) = $file =~ /$prefix\/$program-?(.*)$/;
|
|
|
48 |
$version =~ s/-|\.//g;
|
|
|
49 |
# Don't check the -wrapper ones
|
|
|
50 |
next if $version eq "wrapper";
|
|
|
51 |
|
|
|
52 |
# Special case some programs to make sure it has a minimum version.
|
|
|
53 |
if (not $version and exists $minimumVersions{$program})
|
|
|
54 |
{
|
|
|
55 |
my $min_version = $minimumVersions{$program};
|
|
|
56 |
my $versionOutput = `$program --version 2>/dev/null | head -n 1`;
|
|
|
57 |
|
|
|
58 |
# If we can't run the script to get the version it likely won't work later.
|
|
|
59 |
next unless $versionOutput;
|
|
|
60 |
|
|
|
61 |
# 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 |
{
|
|
|
68 |
next;
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
# If no version suffix then use it in favor of a versioned autotool
|
|
|
73 |
# since the ever-popular WANT_AUTOFOO should then work (in theory).
|
|
|
74 |
return $file unless $version;
|
|
|
75 |
|
|
|
76 |
# Emulate 'which', and abort if we've already seen this version.
|
|
|
77 |
next if exists $versions{$version};
|
|
|
78 |
|
|
|
79 |
# Save filename of program.
|
|
|
80 |
$versions{$version} = $file;
|
|
|
81 |
|
|
|
82 |
# Use string comparison so that e.g. 253a will be > 253 but < 254.
|
|
|
83 |
if ($version gt $best_version_found)
|
|
|
84 |
{
|
|
|
85 |
$best_version_found = $version;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
return $versions{$best_version_found};
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
# Find an appropriate "which" program for later use by the shell script calling
|
|
|
94 |
# us.
|
|
|
95 |
sub findWhich
|
|
|
96 |
{
|
|
|
97 |
for $candidate ('type -p', 'which', 'type')
|
|
|
98 |
{
|
|
|
99 |
$test = `$candidate sh 2>/dev/null`;
|
|
|
100 |
chomp $test;
|
|
|
101 |
|
|
|
102 |
return $candidate if -x $test;
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
# Uses which() to find a program unless the user provided its path in the
|
|
|
107 |
# environment (the upper case program name is searched).
|
|
|
108 |
sub findProgram
|
|
|
109 |
{
|
|
|
110 |
$suffix = ""; # For use if @_ has only one param.
|
|
|
111 |
my ($program, $suffix) = @_;
|
|
|
112 |
|
|
|
113 |
return $ENV{uc $program} if $ENV{uc $program};
|
|
|
114 |
return which("$program$suffix");
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
# SCRIPT STARTS.
|
|
|
118 |
|
|
|
119 |
# Search in path.
|
|
|
120 |
@paths = split(/:/, $ENV{'PATH'});
|
|
|
121 |
|
|
|
122 |
# Make sure at least /usr/bin and /usr/local/bin are in this search.
|
|
|
123 |
unshift @paths, '/usr/local/bin' unless grep $_ eq '/usr/local/bin', @paths;
|
|
|
124 |
unshift @paths, '/usr/bin' unless grep $_ eq '/usr/bin', @paths;
|
|
|
125 |
|
|
|
126 |
$autoconf = findBest('autoconf', @paths);
|
|
|
127 |
($autoconf_suffix) = $autoconf =~ /.*autoconf(.*)$/;
|
|
|
128 |
|
|
|
129 |
# Find matching autoconf companions.
|
|
|
130 |
$autoheader = findProgram('autoheader', $autoconf_suffix);
|
|
|
131 |
$autom4te = findProgram('autom4te', $autoconf_suffix);
|
|
|
132 |
|
|
|
133 |
# Get best automake, and look for unsermake to possibly override it.
|
|
|
134 |
$automake = findBest('automake', @paths);
|
|
|
135 |
$unsermake = "";
|
|
|
136 |
# backward compatible: if $UNSERMAKE points to a path, use it
|
|
|
137 |
$unsermake = findProgram('unsermake') if (defined($ENV{'UNSERMAKE'}) and $ENV{'UNSERMAKE'} =~ /\//);
|
|
|
138 |
# new compatible: if it says 'yes', use the one from path
|
|
|
139 |
$unsermake = which('unsermake') if ($ENV{'UNSERMAKE'} ne 'no');
|
|
|
140 |
|
|
|
141 |
($automake_suffix) = $automake =~ /.*automake(.*)$/;
|
|
|
142 |
|
|
|
143 |
# Use unsermake if we found it.
|
|
|
144 |
$automake = "$unsermake -c" if $unsermake;
|
|
|
145 |
|
|
|
146 |
# Find matching automake companions.
|
|
|
147 |
$aclocal = findProgram('aclocal', $automake_suffix);
|
|
|
148 |
|
|
|
149 |
$which = findWhich();
|
|
|
150 |
|
|
|
151 |
# Make sure we have all of the needed programs.
|
|
|
152 |
for $i (qw'autoconf autoheader autom4te automake aclocal')
|
|
|
153 |
{
|
|
|
154 |
unless(${$i})
|
|
|
155 |
{
|
|
|
156 |
print "# Unable to find $i!!\n";
|
|
|
157 |
exit 1;
|
|
|
158 |
}
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
# Print results in eval-able form.
|
|
|
162 |
print <<EOF;
|
|
|
163 |
AUTOCONF="$autoconf"
|
|
|
164 |
AUTOHEADER="$autoheader"
|
|
|
165 |
AUTOM4TE="$autom4te"
|
|
|
166 |
|
|
|
167 |
AUTOMAKE="$automake"
|
|
|
168 |
ACLOCAL="$aclocal"
|
|
|
169 |
|
|
|
170 |
WHICH="$which"
|
|
|
171 |
|
|
|
172 |
export AUTOCONF AUTOHEADER AUTOM4TE AUTOMAKE ACLOCAL WHICH
|
|
|
173 |
EOF
|
|
|
174 |
|
|
|
175 |
exit 0;
|