aboutsummaryrefslogtreecommitdiffstats
path: root/misc/config/code/wag.pl
diff options
context:
space:
mode:
Diffstat (limited to 'misc/config/code/wag.pl')
-rw-r--r--misc/config/code/wag.pl206
1 files changed, 206 insertions, 0 deletions
diff --git a/misc/config/code/wag.pl b/misc/config/code/wag.pl
new file mode 100644
index 000000000..b9ea42c3c
--- /dev/null
+++ b/misc/config/code/wag.pl
@@ -0,0 +1,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;
+}