File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/checkccompiler
#!/usr/bin/perl
# cpanel - checkcompiler Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::OSSys ();
use Cpanel::SafeRun::Errors ();
use Cpanel::Usage ();
my $verbose = 0;
my $biarch_test = 0;
Cpanel::Usage::wrap_options( \@ARGV, \&usage, { 'verbose' => \$verbose, 'biarch' => \$biarch_test } );
if ( -e '/etc/skipccheck' ) {
print "C compiler check disabled per /etc/skipccheck\n";
exit 0;
}
my ( $system, $arch ) = ( Cpanel::OSSys::uname() )[ 0, 4 ];
my $test_bin = '/root/cpanel-gcc-test';
my $is_64bit = $arch =~ m/64/ ? 1 : 0;
my $is_bsd = $system =~ /freebsd/i;
my @tests = ( [] );
if ( $is_64bit && $biarch_test ) {
if ($is_bsd) {
if ( -e '/usr/lib32' ) {
push @tests, [ '-m32', '-B/usr/lib32' ];
}
else {
print "The system has no 32bit compatibility libraries installed!\n";
print "These must be installed manually on FreeBSD systems.\n";
print "See http://docs.cpanel.net/twiki/bin/view/EasyApache3/FrontPageSupport\n";
print "for more information.\n";
exit 1;
}
}
else {
push @tests, ['-m32'];
}
}
foreach my $test_ref (@tests) {
my $status = test_compile(@$test_ref);
exit 1 unless $status;
}
exit 0;
sub test_compile {
# We do two passes since we attempt to fix up common problems on Linux
foreach my $pass ( 1 .. 2 ) {
my @flags = @_;
if ( -e $test_bin . '.c' ) {
unlink $test_bin . '.c';
if ( -e $test_bin . '.c' ) {
die "${test_bin}.c still exists after we unlinked it. Unable to verify C compiler.";
}
}
if ( -e $test_bin ) {
unlink $test_bin;
if ( -e $test_bin ) {
die "$test_bin still exists after we unlinked it. Unable to verify C compiler.";
}
}
if ( open my $test_c_fh, '>', $test_bin . '.c' ) {
print {$test_c_fh} <<'EOM';
#include <stdio.h>
#include <sys/types.h>
int main (int argc, char **argv) {
printf("C Compiler Works\n");
return 0;
}
EOM
close $test_c_fh;
}
else {
die "Unable to write ${test_bin}.c: $!";
}
my @CMDLINE = ( $test_bin . '.c', '-o', $test_bin );
if ( scalar @flags ) { unshift @CMDLINE, @flags; }
print "Running gcc " . join( ' ', @CMDLINE ) . "\n" if $verbose;
my $compile_output = Cpanel::SafeRun::Errors::saferunallerrors( 'gcc', @CMDLINE );
chomp $compile_output;
my $compilerworks = -e $test_bin ? Cpanel::SafeRun::Errors::saferunnoerror($test_bin) : '';
chomp $compilerworks;
# Check if the C compiler is broken
if ( $compilerworks !~ m/C\s+Compiler\s+Works/i ) {
if ($verbose) {
print "Compiler broken\n";
print "Compile output: $compile_output\n";
print "$test_bin output: $compilerworks\n" if $compilerworks;
}
if ($is_bsd) {
warn "C compiler was detected broken!!! Please check your system.\n";
warn "Compilation command: gcc " . join( ' ', @CMDLINE ) . "\n";
warn "Compile error: $compile_output\n";
warn "$test_bin binary did not return correct output.\n";
return 0;
}
elsif ( $pass == 1 ) {
print "Attempting to autorepair compiler\n" if $verbose;
if ( scalar @flags ) {
system '/scripts/fixheaders-32bit';
}
else {
system '/scripts/fixheaders';
}
next;
}
return 0;
}
else {
print "C Compiler OK\n" if $verbose;
# Clean up test code and binary
unlink $test_bin . '.c';
unlink $test_bin;
return 1;
}
}
}
sub usage {
print <<EO_USAGE;
checkccompiler [options]
Options:
--help Brief help message
--verbose Display verbose information messages
--biarch Test biarch support on 64bit system
EO_USAGE
exit 0;
}