| 1 |
# Copyright (c) 1995-2003 Nick Ing-Simmons. All rights reserved. |
| 2 |
# This program is free software; you can redistribute it and/or |
| 3 |
# modify it under the same terms as Perl itself. |
| 4 |
package Tk::MMtry; |
| 5 |
use Config; |
| 6 |
require Exporter; |
| 7 |
|
| 8 |
use vars qw($VERSION @EXPORT $VERBOSE); |
| 9 |
#$VERSION = sprintf '4.%03d', q$Revision: #9 $ =~ /\D(\d+)\s*$/; |
| 10 |
$VERSION = '4.011'; |
| 11 |
|
| 12 |
use base qw(Exporter); |
| 13 |
@EXPORT = qw(try_compile try_run); |
| 14 |
use strict; |
| 15 |
use File::Basename; |
| 16 |
use File::Spec; |
| 17 |
|
| 18 |
my $stderr_too = ($^O eq 'MSWin32') ? '' : '2>&1'; |
| 19 |
|
| 20 |
sub try_compile |
| 21 |
{ |
| 22 |
my ($file,$inc,$lib,$def) = @_; |
| 23 |
$inc ||= []; |
| 24 |
$lib ||= []; |
| 25 |
$def ||= []; |
| 26 |
my $stderr_too = $VERBOSE ? '' : $stderr_too; |
| 27 |
my $out = basename($file,'.c').$Config{'exe_ext'}; |
| 28 |
warn "Test Compiling $file\n"; |
| 29 |
my $msgs = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file $Config{ldflags} @$lib @$def $stderr_too`; |
| 30 |
my $ok = ($? == 0); |
| 31 |
warn "$msgs\n" if $VERBOSE && $msgs; |
| 32 |
unlink($out) if (-f $out); |
| 33 |
return $ok; |
| 34 |
} |
| 35 |
|
| 36 |
sub try_run |
| 37 |
{ |
| 38 |
my ($file,$inc,$lib,$def) = @_; |
| 39 |
$inc ||= []; |
| 40 |
$lib ||= []; |
| 41 |
$def ||= []; |
| 42 |
my $stderr_too = $VERBOSE ? '' : $stderr_too; |
| 43 |
my $out = basename($file,'.c').$Config{'exe_ext'}; |
| 44 |
warn "Test Compile/Run $file\n"; |
| 45 |
my $cmdline = "$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file $Config{ldflags} @$lib @$def"; |
| 46 |
my $msgs = `$cmdline $stderr_too`; |
| 47 |
my $ok = ($? == 0); |
| 48 |
warn "$cmdline:\n$msgs\n" if $VERBOSE && $msgs; |
| 49 |
if ($ok) |
| 50 |
{ |
| 51 |
my $path = File::Spec->rel2abs($out); |
| 52 |
$msgs = `$path $stderr_too`; |
| 53 |
$ok = ($? == 0); |
| 54 |
warn "$path:$msgs\n" if $VERBOSE && $msgs; |
| 55 |
} |
| 56 |
unlink($out) if (-f $out); |
| 57 |
return $ok; |
| 58 |
} |
| 59 |
|
| 60 |
1; |