summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Tk/MMtry.pm
blob: 110f6b2ae81265cbcf7f7970e49104e6045f38e7 (plain)
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
# 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 $VERBOSE);
#$VERSION = sprintf '4.%03d', q$Revision: #9 $ =~ /\D(\d+)\s*$/;
$VERSION = '4.010';

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,$def)  = @_;
 $inc = [] unless $inc;
 $lib = [] unless $lib;
 $def = [] unless $def;
 my $out   = basename($file,'.c').$Config{'exe_ext'};
 warn "Test Compiling $file\n";
 my $msgs  = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib @$def $stderr_too`;
 my $ok = ($? == 0);
 warn "$msgs\n" if $VERBOSE && $msgs;
 unlink($out) if (-f $out);
 return $ok;
}

sub try_run
{
 my ($file,$inc,$lib,$def)  = @_;
 $inc = [] unless $inc;
 $lib = [] unless $lib;
 $def = [] unless $def;
 my $out   = basename($file,'.c').$Config{'exe_ext'};
 warn "Test Compile/Run $file\n";
 my $cmdline = "$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib @$def";
 my $msgs  = `$cmdline $stderr_too`;
 my $ok = ($? == 0);
 warn "$cmdline:\n$msgs\n" if $VERBOSE && $msgs;
 if ($ok)
  {
   my $path = File::Spec->rel2abs($out);
   $msgs = `$path $stderr_too`;
   $ok = ($? == 0);
   warn "$path:$msgs\n" if $VERBOSE && $msgs;
  }
 unlink($out) if (-f $out);
 return $ok;
}

1;