Alien-TinyCC
view release on metacpan or search on metacpan
lib/Alien/TinyCC.pm view on Meta::CPAN
# on Unixish systems; Windows simply uses the %PATH%, which was already
# appropriately set.
sub libtcc_library_path {
return $dist_dir if $^O =~ /MSWin/;
return File::Spec->catdir($dist_dir, 'lib');
}
# Add library path on Unixish:
if ($ENV{LD_LIBRARY_PATH}) {
$ENV{LD_LIBRARY_PATH} = libtcc_library_path() . ':' . $ENV{LD_LIBRARY_PATH};
}
elsif ($^O !~ /MSWin/) {
$ENV{LD_LIBRARY_PATH} = libtcc_library_path();
}
# Determine path for libtcc.h
sub libtcc_include_path {
return File::Spec->catdir($dist_dir, 'libtcc') if $^O =~ /MSWin/;
return File::Spec->catdir($dist_dir, 'include');
}
###########################
# Module::Build Functions #
###########################
sub MB_linker_flags {
return ('-L' . libtcc_library_path, '-ltcc');
}
#################################
# ExtUtils::MakeMaker Functions #
#################################
sub EUMM_LIBS {
return (LIBS => ['-L' . libtcc_library_path . '\libtcc -ltcc']) if $^O =~ /MSWin/;
return;
}
sub EUMM_OBJECT {
return OBJECT => '$(O_FILES)' if $^O =~ /MSWin/;
return OBJECT => '$(O_FILES) ' . File::Spec->catdir(libtcc_library_path, 'libtcc'.$Config{lib_ext}),
}
# version
1;
__END__
=head1 NAME
Alien::TinyCC - retrieve useful information about the Alien installation of tcc
=head1 ALIEN SYNOPSIS
use Alien::TinyCC;
## libtcc location functions ##
say 'The libtcc headers can be found in ',
Alien::TinyCC->libtcc_include_path;
say 'The libtcc library can be found in ',
Alien::TinyCC->libtcc_library_path;
## tcc functions ##
say 'The tcc executable can be found in ',
Alien::TinyCC->path_to_tcc;
# Create a C file
open my $out_fh, '>', 'test.c';
print $out_fh <<'EOF';
#include <stdio.h>
int main() {
printf("Good to go");
return 1;
}
EOF
close $out_fh;
# Alien::TinyCC ensures that the tcc executable is
# in your PATH environment variable, so this Just Works:
my $output = `tcc -run test.c`;
=head1 XS SYNOPSIS
If you want to build against F<libtcc>, then in your F<Build.PL> file you
should have something like this:
use Module::Build;
use Alien::TinyCC;
Module::Build->new(
...
configure_requires => {
'Alien::TinyCC' => 0,
...
},
build_requires => {
'Alien::TinyCC' => 0,
...
},
requires => {
'Alien::TinyCC' => 0,
...
},
needs_compiler => 1,
dynamic_config => 1,
include_dirs => [Alien::TinyCC->libtcc_include_path],
extra_linker_flags => [Alien::TinyCC->MB_linker_flags],
)->create_build_script
At the top of the Perl module that provides the Perl libtcc interface:
# My/C/Tiny/Interface.pm
use Alien::TinyCC; # set LD_LIBRARY_PATH, PATH, etc
BEGIN {
our $VERSION = '0.02';
use XSLoader;
XSLoader::load 'My::C::Tiny::Interface', $VERSION;
}
In your XS file that interfaces with libtcc:
/* Usual Perl XS suspects */
( run in 0.684 second using v1.01-cache-2.11-cpan-483215c6ad5 )