Acme-MITHALDU-XSGrabBag
view release on metacpan or search on metacpan
inc/Inline/C.pm view on Meta::CPAN
for my $function (sort @{$data->{functions}}) {
my $return_type = $data->{function}{$function}{return_type};
my @arg_names = @{$data->{function}{$function}{arg_names}};
my @arg_types = @{$data->{function}{$function}{arg_types}};
my @args = map {$_ . ' ' . shift @arg_names} @arg_types;
$text .= "\t$return_type $function(" . join(', ', @args) . ")\n";
}
}
else {
$text .= "No $o->{API}{language} functions have been successfully bound to Perl.\n\n";
}
$text .= Inline::Struct::info($o) if $o->{STRUCT}{'.any'};
return $text;
}
sub config {
my $o = shift;
}
#==============================================================================
# Parse and compile C code
#==============================================================================
my $total_build_time;
sub build {
my $o = shift;
if ($o->{CONFIG}{BUILD_TIMERS}) {
eval {require Time::HiRes};
croak "You need Time::HiRes for BUILD_TIMERS option:\n$@" if $@;
$total_build_time = Time::HiRes::time();
}
my ($file, $lockfh);
if (IS_WIN32) {
#this can not look like a file path, or new() fails
$file = 'Inline__C_' . $o->{API}{directory} . '.lock';
$file =~ s/\\/_/g; #per CreateMutex on MSDN
$lockfh = Win32::Mutex->new(0, $file) or die "lockmutex $file: $^E";
$lockfh->wait(); #acquire, can't use 1 to new(), since if new() opens
#existing instead of create new Muxtex, it is not acquired
}
else {
$file = File::Spec->catfile($o->{API}{directory}, '.lock');
open $lockfh, '>', $file or die "lockfile $file: $!";
flock($lockfh, LOCK_EX) or die "flock: $!\n" if $^O !~ /^VMS|riscos|VOS$/;
}
$o->mkpath($o->{API}{build_dir});
$o->call('preprocess', 'Build Preprocess');
$o->call('parse', 'Build Parse');
$o->call('write_XS', 'Build Glue 1');
$o->call('write_Inline_headers', 'Build Glue 2');
$o->call('write_Makefile_PL', 'Build Glue 3');
$o->call('compile', 'Build Compile');
if (IS_WIN32) {
$lockfh->release or die "releasemutex $file: $^E";
}
else {
flock($lockfh, LOCK_UN) if $^O !~ /^VMS|riscos|VOS$/;
}
if ($o->{CONFIG}{BUILD_TIMERS}) {
$total_build_time = Time::HiRes::time() - $total_build_time;
printf STDERR "Total Build Time: %5.4f secs\n", $total_build_time;
}
}
sub call {
my ($o, $method, $header, $indent) = (@_, 0);
my $time;
my $i = ' ' x $indent;
print STDERR "${i}Starting $header Stage\n" if $o->{CONFIG}{BUILD_NOISY};
$time = Time::HiRes::time()
if $o->{CONFIG}{BUILD_TIMERS};
$o->$method();
$time = Time::HiRes::time() - $time
if $o->{CONFIG}{BUILD_TIMERS};
print STDERR "${i}Finished $header Stage\n" if $o->{CONFIG}{BUILD_NOISY};
printf STDERR "${i}Time for $header Stage: %5.4f secs\n", $time
if $o->{CONFIG}{BUILD_TIMERS};
print STDERR "\n" if $o->{CONFIG}{BUILD_NOISY};
}
#==============================================================================
# Apply any
#==============================================================================
sub preprocess {
my $o = shift;
return if $o->{ILSM}{parser};
$o->get_maps;
$o->get_types;
$o->{ILSM}{code} = $o->filter(@{$o->{ILSM}{FILTERS}});
}
#==============================================================================
# Parse the function definition information out of the C code
#==============================================================================
sub parse {
my $o = shift;
return if $o->{ILSM}{parser};
return if $o->{ILSM}{XSMODE};
my $parser = $o->{ILSM}{parser} = $o->get_parser;
$parser->{data}{typeconv} = $o->{ILSM}{typeconv};
$parser->{data}{AUTOWRAP} = $o->{ILSM}{AUTOWRAP};
Inline::Struct::parse($o) if $o->{STRUCT}{'.any'};
$parser->code($o->{ILSM}{code})
or croak <<END;
Bad $o->{API}{language} code passed to Inline at @{[caller(2)]}
END
}
# Create and initialize a parser
sub get_parser {
my $o = shift;
Inline::C::_parser_test($o->{CONFIG}{DIRECTORY}, "Inline::C::get_parser called\n")
if $o->{CONFIG}{_TESTING};
require Inline::C::Parser::RecDescent;
Inline::C::Parser::RecDescent::get_parser($o);
}
#==============================================================================
# Gather the path names of all applicable typemap files.
#==============================================================================
sub get_maps {
my $o = shift;
print STDERR "get_maps Stage\n" if $o->{CONFIG}{BUILD_NOISY};
my $typemap = '';
my $file;
$file = File::Spec->catfile(
$Config::Config{installprivlib},
"ExtUtils",
"typemap",
);
$typemap = $file if -f $file;
$file = File::Spec->catfile(
$Config::Config{privlibexp}
,"ExtUtils","typemap"
);
( run in 3.467 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )