home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _2208f11cc15eb9783c3aa605c65ce893 < prev    next >
Encoding:
Text File  |  2004-06-01  |  1.4 KB  |  55 lines

  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);
  9. $VERSION = sprintf '4.%03d', q$Revision: #9 $ =~ /\D(\d+)\s*$/;
  10.  
  11. use base  qw(Exporter);
  12. @EXPORT = qw(try_compile try_run);
  13. use strict;
  14. use File::Basename;
  15. use File::Spec;
  16.  
  17. my $stderr_too = ($^O eq 'MSWin32') ? '' : '2>&1';
  18.  
  19. sub try_compile
  20. {
  21.  my ($file,$inc,$lib)  = @_;
  22.  $inc = [] unless $inc;
  23.  $lib = [] unless $lib;
  24.  my $out   = basename($file,'.c').$Config{'exe_ext'};
  25.  warn "Test Compiling $file\n";
  26.  my $msgs  = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib $stderr_too`;
  27.  my $ok = ($? == 0);
  28. # warn $msgs if $msgs;
  29.  unlink($out) if (-f $out);
  30.  return $ok;
  31. }
  32.  
  33. sub try_run
  34. {
  35.  my ($file,$inc,$lib)  = @_;
  36.  $inc = [] unless $inc;
  37.  $lib = [] unless $lib;
  38.  my $out   = basename($file,'.c').$Config{'exe_ext'};
  39.  warn "Test Compile/Run $file\n";
  40.  my $msgs  = `$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib $stderr_too`;
  41.  my $ok = ($? == 0);
  42. # warn "$Config{'cc'} -o $out $Config{'ccflags'} @$inc $file @$lib:\n$msgs" if $msgs;
  43.  if ($ok)
  44.   {
  45.    my $path = File::Spec->rel2abs($out);
  46.    $msgs = `$path $stderr_too`;
  47.    $ok = ($? == 0);
  48. #  warn "$path:$msgs" if $msgs;
  49.   }
  50.  unlink($out) if (-f $out);
  51.  return $ok;
  52. }
  53.  
  54. 1;
  55.