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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
sub which
{
my $file = $_[0];
my @paths = split(/:/, $ENV{PATH});
foreach my $path (@paths)
{
my $file_path = File::Spec->catfile($path, $file);
return $file_path if(guess_check_for_file($file_path));
}
return '';
}
sub guess_cpu_from_this
{
my $cpuinfo = lc $_[0];
my $cpu = '';
$cpu = 'athlon' if($cpuinfo =~ /athlon/);
$cpu = 'pentium4' if($cpuinfo =~ /pentium 4/);
$cpu = 'pentium4' if($cpuinfo =~ /pentium\(r\) 4/);
$cpu = 'pentium3' if($cpuinfo =~ /pentium iii/);
$cpu = 'pentium2' if($cpuinfo =~ /pentium ii/);
$cpu = 'pentium3' if($cpuinfo =~ /pentium 3/);
$cpu = 'pentium2' if($cpuinfo =~ /pentium 2/);
# The 32-bit SPARC stuff is impossible to match to arch type easily, and
# anyway the uname stuff will pick up that it's a SPARC so it doesn't
# matter. If it's an Ultra, assume a 32-bit userspace, no 64-bit code
# possible; that's the most common setup right now anyway
$cpu = 'sparc32-v9' if($cpuinfo =~ /ultrasparc/);
# 64-bit PowerPC
$cpu = 'rs64a' if($cpuinfo =~ /rs64-/);
$cpu = 'power3' if($cpuinfo =~ /power3/);
$cpu = 'power4' if($cpuinfo =~ /power4/);
$cpu = 'power5' if($cpuinfo =~ /power5/);
$cpu = 'ppc970' if($cpuinfo =~ /ppc970/);
# Ooh, an Alpha. Try to figure out what kind
if($cpuinfo =~ /alpha/)
{
$cpu = 'alpha-ev4' if($cpuinfo =~ /ev4/);
$cpu = 'alpha-ev5' if($cpuinfo =~ /ev5/);
$cpu = 'alpha-ev56' if($cpuinfo =~ /ev56/);
$cpu = 'alpha-pca56' if($cpuinfo =~ /pca56/);
$cpu = 'alpha-ev6' if($cpuinfo =~ /ev6/);
$cpu = 'alpha-ev67' if($cpuinfo =~ /ev67/);
$cpu = 'alpha-ev68' if($cpuinfo =~ /ev68/);
$cpu = 'alpha-ev7' if($cpuinfo =~ /ev7/);
}
return $cpu;
}
# Do some WAGing and see if we can figure out what system we are. Think about
# this as a really moronic config.guess
sub guess_triple
{
# /bin/sh, good bet we're on something Unix-y (at least it'll have uname)
if(-f '/bin/sh')
{
my $os = lc `uname -s 2>/dev/null`; chomp $os;
# Let the crappy hacks commence!
# Cygwin's uname -s is cygwin_<windows version>
$os = 'cygwin' if($os =~ /^cygwin/);
if(!defined $OS_TYPE{$os} && !defined $OS_ALIAS{$os})
{
print "Unknown uname -s output: $os, falling back to 'generic'\n";
$os = 'generic';
}
$os = $OS_ALIAS{$os} if(defined($OS_ALIAS{$os}));
my $cpu = '';
# If we have /proc/cpuinfo, try to get nice specific information about
# what kind of CPU we're running on.
if(guess_check_for_file('/proc/cpuinfo'))
{
open CPUINFO, '/proc/cpuinfo' or die
"Hey, guess_check_for_file said /proc/cpuinfo was readable!\n";
my $cpuinfo = join('', <CPUINFO>);
close CPUINFO;
$cpu = guess_cpu_from_this($cpuinfo);
}
# `umame -p` is sometimes something stupid like unknown, but in some
# cases it can be more specific (useful) than `uname -m`
if($cpu eq '') # no guess so far
{
my $uname_p = `uname -p 2>/dev/null`;
chomp $uname_p;
$cpu = guess_cpu_from_this($uname_p);
# If guess_cpu_from_this didn't figure it out, try it plain
if($cpu eq '') { $cpu = lc $uname_p; }
if(!defined $ARCH{$cpu} && !defined $SUBMODEL_ALIAS{$cpu} &&
!defined $ARCH_ALIAS{$cpu})
{
# Nope, couldn't figure out uname -p
$cpu = lc `uname -m 2>/dev/null`;
chomp $cpu;
if(!defined $ARCH{$cpu} && !defined $SUBMODEL_ALIAS{$cpu} &&
!defined $ARCH_ALIAS{$cpu})
{
$cpu = 'generic';
}
}
}
my @CCS = ('gcc', 'icc', 'compaq', 'kai'); # Skips several, oh well...
# First try the CC enviornmental variable, if it's set
if(defined($ENV{CC}))
{
my @new_CCS = ($ENV{CC});
foreach my $cc (@CCS) { push @new_CCS, $cc; }
@CCS = @new_CCS;
}
my $cc = '';
foreach (@CCS)
{
my $bin_name = $CC_BINARY_NAME{$_};
$cc = $_ if(which($bin_name) ne '');
last if($cc ne '');
}
if($cc eq '') {
warn "Can't find a usable C++ compiler, is your PATH right?\n";
warn "You might need to run with explicit compiler/system flags;\n";
warn " run '$0 --help' for more information\n";
exit 1;
}
return "$cc-$os-$cpu";
}
elsif($^O eq 'MSWin32' or $^O eq 'dos')
{
my $os = 'windows'; # obviously
# Suggestions on this? The Win32 'shell' env is not so hot. We could
# try using cpuinfo, except that will crash hard on NT/Alpha (like what
# we're doing now won't!). In my defense of choosing i686:
# a) There are maybe a few hundred Alpha/MIPS boxes running NT4 today
# b) Anyone running Windows on < Pentium Pro deserves to lose.
my $cpu = 'i686';
# No /bin/sh, so not cygwin. Assume VC++; again, this could be much
# smarter
my $cc = 'msvc';
return "$cc-$os-$cpu";
}
else
{
print "Sorry, you don't seem to be on Unix or Windows;\n" .
" autoconfig failed (try running me with --help)\n";
exit 1;
}
}
sub guess_check_for_file
{
my $file = $_[0];
return 1 if(-f $file and -r $file);
return 0;
}
sub guess_mods
{
my ($cc, $os, $arch, $submodel) = @_;
my @usable_modules;
foreach my $mod (sort keys %MODULES)
{
next if($mod eq 'minimal'); # Never enabled by default
my %modinfo = %{ $MODULES{$mod} };
# If it uses external libs, the user has to request it specifically
next if($modinfo{'external_libs'});
my @cc_list = ();
if($modinfo{'cc'}) { @cc_list = keys %{ $modinfo{'cc'} }; }
my @os_list = ();
if($modinfo{'os'}) { @os_list = keys %{ $modinfo{'os'} }; }
my @arch_list = ();
if($modinfo{'arch'}) { @arch_list = keys %{ $modinfo{'arch'} }; }
next if(scalar @cc_list > 0 && !in_array(\@cc_list, $cc));
next if(scalar @os_list > 0 && !in_array(\@os_list, $os));
next if(scalar @arch_list > 0 &&
!in_array(\@arch_list, $arch) &&
!in_array(\@arch_list, $submodel));
push @usable_modules, $mod;
}
return @usable_modules;
}
|