Iain Truskett <[EMAIL PROTECTED]> writes:
>Heyo,
>
>I was wondering if there was a nice recipe to determine
>whether a C compiler is available. The various modules I looked at
>that have both XS and pure perl implementations don't seem to
>have any sort of standard method of determination.
>
>Runtime isn't a problem since the C based implementation would have a
>different name from the Perl one, but I don't know a recommended way to
>work out whether to bother compiling at 'make' time.
You could see if you can execute the 'cc' in Config.pm.
e.g. Tk has a Tk::MMtry (attached not Tk specific really)
which attempts to compile some file.
Tk uses it to see if functions/headers/library exists but if
you try_compile-d
int main() { return 0; }
That would prove existance of a compiler.
>
>
>cheers,
# Copyright (c) 1995-2003 Nick Ing-Simmons. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Tk::MMtry;
use Config;
require Exporter;
use vars qw($VERSION @EXPORT);
$VERSION = sprintf '4.%03d', q$Revision: #9 $ =~ /\D(\d+)\s*$/;
use base qw(Exporter);
@EXPORT = qw(try_compile try_run);
use strict;
use File::Basename;
use File::Spec;
my $stderr_too = ($^O eq 'MSWin32') ? '' : '2>&1';
sub try_compile
{
my ($file,$inc,$lib) = @_;
$inc = [] unless $inc;
$lib = [] unless $lib;
my $out = basename($file,'.c').$Config{'exe_ext'};
warn "Test Compiling $file\n";
my $msgs = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib $stderr_too`;
my $ok = ($? == 0);
# warn $msgs if $msgs;
unlink($out) if (-f $out);
return $ok;
}
sub try_run
{
my ($file,$inc,$lib) = @_;
$inc = [] unless $inc;
$lib = [] unless $lib;
my $out = basename($file,'.c').$Config{'exe_ext'};
warn "Test Compile/Run $file\n";
my $msgs = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib $stderr_too`;
my $ok = ($? == 0);
# warn "$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib:\n$msgs" if $msgs;
if ($ok)
{
my $path = File::Spec->rel2abs($out);
$msgs = `$path $stderr_too`;
$ok = ($? == 0);
# warn "$path:$msgs" if $msgs;
}
unlink($out) if (-f $out);
return $ok;
}
1;