Authen-Krb5-Simple
view release on metacpan or search on metacpan
inc/Devel/CheckLib.pm view on Meta::CPAN
# $Id: CheckLib.pm,v 1.10 2007/10/30 15:12:17 drhyde Exp $
package Devel::CheckLib;
use strict;
use vars qw($VERSION @ISA @EXPORT);
$VERSION = '0.3';
use Config;
use File::Spec;
use File::Temp;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(assert_lib check_lib_or_exit);
# localising prevents the warningness leaking out of this module
local $^W = 1; # use warnings is a 5.6-ism
_findcc(); # bomb out early if there's no compiler
=head1 NAME
Devel::CheckLib - check that a library is available
=head1 DESCRIPTION
Devel::CheckLib is a perl module that checks whether a particular C
library is available, and dies if it is not.
=head1 SYNOPSIS
# in a Makefile.PL or Build.PL
use lib qw(inc);
use Devel::CheckLib;
check_lib_or_exit( lib => 'jpeg' );
check_lib_or_exit( lib => [ 'iconv', 'jpeg' ] );
# or prompt for path to library and then do this:
check_lib_or_exit( lib => 'jpeg', libpath => $additional_path );
=head1 HOW IT WORKS
You pass named parameters to a function
describing how to build and link to the library. Currently the only
parameter supported is 'lib', which can be a string or an arrayref of
several libraries. In the future, expect us to add something for
checking that header files are available as well.
It works by trying to compile this:
int main(void) { return 0; }
and linking it to the specified libraries. If something pops out the end
which looks executable, then we know that it worked.
=head1 FUNCTIONS
All of these take the same named parameters and are exported by default.
To avoid exporting them, C<use Devel::CheckLib ()>.
=head2 assert_lib
Takes several named parameters.
The value of C<lib> must be either a string with the name of a single
library or a reference to an array of strings of library names. Depending
on the compiler found, library names will be fed to the compiler either as
C<-l> arguments or as C<.lib> file names. (E.g. C<-ljpeg> or C<jpeg.lib>)
Likewise, C<libpath> must if provided either be a string or an array of strings
representing additional paths to search for libraries.
C<LIBS> must be a C<ExtUtils::MakeMaker>-style space-seperated list of
libraries (each preceded by '-l') and directories (preceded by '-L').
This will die with an error message if any of the libraries listed can
not be found. B<Note>: dying in a Makefile.PL or Build.PL may provoke
a 'FAIL' report from CPAN Testers' automated smoke testers. Use
C<check_lib_or_exit> instead.
=head2 check_lib_or_exit
This behaves exactly the same as C<assert_lib()> except that instead of
dieing, it warns (with exactly the same error message) and exits.
This is intended for use in Makefile.PL / Build.PL
when you might want to prompt the user for various paths and
things before checking that what they've told you is sane.
If a library isn't found, it exits with an exit value of 0 to avoid
causing a CPAN Testers 'FAIL' report. CPAN Testers should ignore this
result -- which is what you want if an external library dependency is not
available.
=cut
sub check_lib_or_exit {
eval 'assert_lib(@_)';
if($@) {
warn $@;
exit;
}
}
sub assert_lib {
my %args = @_;
my (@libs, @libpaths);
@libs = (ref($args{lib}) ? @{$args{lib}} : $args{lib})
if $args{lib};
@libpaths = (ref($args{libpath}) ? @{$args{libpath}} : $args{libpath})
if $args{libpath};
# work-a-like for Makefile.PL's "LIBS" argument
if(defined($args{LIBS})) {
( run in 2.305 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )