Imager
view release on metacpan or search on metacpan
lib/Imager/Probe.pm view on Meta::CPAN
# End of search list.
# # 1 "<stdin>"
# # 1 "<built-in>"
# ...
while (@spam && $spam[0] !~ /^#include /) {
shift @spam;
}
my @inc;
while (@spam && $spam[0] !~ /^End of search/) {
my $line = shift @spam;
chomp $line;
next if $line =~ /^#include /;
next unless $line =~ s/^\s+//;
push @inc, $line;
}
return @inc;
}
sub _dyn_inc_paths {
return map {
my $tmp = $_;
$tmp =~ s/\blib$/include/ ? $tmp : ()
} _dyn_lib_paths();
}
sub _paths {
my (@in) = @_;
my @out;
# expand any array refs
@in = map { ref() ? @$_ : $_ } @in;
for my $path (@in) {
$path or next;
$path = _tilde_expand($path);
push @out, grep -d $_, split /\Q$Config{path_sep}/, $path;
}
@out = map Cwd::realpath($_), @out;
my %seen;
@out = grep !$seen{$_}++, @out;
return @out;
}
my $home;
sub _tilde_expand {
my ($path) = @_;
if ($path =~ m!^~[/\\]!) {
defined $home or $home = $ENV{HOME};
if (!defined $home && $^O eq 'MSWin32'
&& defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) {
$home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH};
}
unless (defined $home) {
$home = eval { (getpwuid($<))[7] };
}
defined $home or die "You supplied $path, but I can't find your home directory\n";
$path =~ s/^~//;
$path = File::Spec->catdir($home, $path);
}
return $path;
}
sub _tcal_state {
my ($req) = @_;
my %state;
$state{start_dir} = Cwd::getcwd()
or die "Cannot save current directory: $!\n";
$state{keep} = !!$ENV{IMAGER_PROBE_KEEP_FILES};
$state{tmpdir} = File::Temp->newdir(CLEANUP => !$state{keep})
or Carp::confess("panic: cannot create temp directory");
$state{num} = 1;
\%state;
}
sub _sort_std {
my @stds = grep defined, @_;
# we don't support -std=iso9899:1999 etc
my $std_map = sub { my $std = shift; return $std > 80 ? $std-100 : $std };
return sort { $std_map->($b) <=> $std_map->($a) } grep defined, @stds;
}
# _try_compile_and_link
# adapted from Time::HiRes and then adapted some more.
# This is not part of the Imager::Probe API
#
# $code - code to test
#
# %args - options to control this test
# name - required description of what we're testing, used for verbose
# cc - optional C compiler (overrides $req->{cc}
# ccflags - optional extra compiler flags
# ccflags_only - only use ccflags and don't use $req->{ccflags}
# libs - extra libraries to link to
# std - C standard, needs stdflag set in $req per by probe_std()
# nolink - only test compilation success
#
# $req contains probing state, used here:
# verbose - print messages if true
# stdflag - compiler option used to select a C standard, by probe_std
# minstd - minimum standard (default: 99)
# ccflags - base ccflags
# cc - base cc
#
sub _try_compile_and_link {
my ($code, $req, %args) = @_;
my $verbose = $req->{verbose} || 0;
my $indent = $req->{indent} || "";
my $name = $args{name}
or Carp::confess("panic: no name supplied to _try_compile_and_link");
( run in 1.969 second using v1.01-cache-2.11-cpan-39bf76dae61 )