Alien-PNG

 view release on metacpan or  search on metacpan

lib/Alien/PNG.pm  view on Meta::CPAN

functionality works in a very similar maner to 'libpng-config' script:

    Alien::PNG->config('prefix');   # gives the same string as 'libpng-config --prefix'
    Alien::PNG->config('version');  # gives the same string as 'libpng-config --version'
    Alien::PNG->config('libs');     # gives the same string as 'libpng-config --libs'
    Alien::PNG->config('cflags');   # gives the same string as 'libpng-config --cflags'

On top of that this function supports special parameters:

    Alien::PNG->config('ld_shared_libs');

Returns a list of full paths to shared libraries (*.so, *.dll) that will be
required for running the resulting binaries you have linked with PNG libs.

    Alien::PNG->config('ld_paths');

Returns a list of full paths to directories with shared libraries (*.so, *.dll)
that will be required for running the resulting binaries you have linked with
PNG libs.

    Alien::PNG->config('ld_shlib_map');

Returns a reference to hash of value pairs '<libnick>' => '<full_path_to_shlib'>,
where '<libnick>' is shortname for PNG related library like: PNG.

NOTE: config('ld_<something>') return an empty list/hash if you have decided to
use PNG libraries already installed on your system. This concerns 'libpng-config' 
detection and detection via '$PNG_INST_DIR/bin/libpng-config'.

=head2 check_header()

This function checks the availability of given header(s) when using compiler
options provided by "Alien::PNG->config('cflags')".

    Alien::PNG->check_header('png.h');
    Alien::PNG->check_header('png.h', 'pngconf.h');

Returns 1 if all given headers are available, 0 otherwise.

=head2 get_header_version()

Tries to find a header file specified as a param in PNG prefix direcotry and
based on "#define" macros inside this header file tries to get a version triplet.

    Alien::PNG->get_header_version('png.h');

Returns string like '1.2.3' or undef if not able to find and parse version info.

=head1 BUGS

Please post issues and bugs at L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Alien-PNG>

=head1 AUTHOR

    Tobias Leich
    CPAN ID: FROGGS
    FROGGS@cpan.org

=head1 ACKNOWLEDGEMENTS

    This module is based on Alien::SDL, so in fact the credits has to be given to these guys.
    kmx - complete redesign between versions 0.7.x and 0.8.x

=head1 COPYRIGHT

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut

### get config params
sub config
{
  my $package = shift;
  my @params  = @_;
  return _png_config_via_script(@params)          if Alien::PNG::ConfigData->config('script');
  return _png_config_via_win32_pkgconfig(@params) if Alien::PNG::ConfigData->config('win32_pkgconfig');
  return _png_config_via_config_data(@params)     if Alien::PNG::ConfigData->config('config');
}

### get version info from given header file
sub get_header_version {
  my ($package, $header) = @_;
  return unless $header;

  # try to find header
  my $root = Alien::PNG->config('prefix');
  #warn 'Finding in '.$root.'/include';
  my $include = File::Spec->catfile($root, 'include');
  my @files;
  find({ wanted => sub { push @files, rel2abs($_) if /\Q$header\E$/ }, follow => 1, no_chdir => 1, follow_skip => 2 }, $include);
  return unless @files;

  # get version info
  open(DAT, $files[0]) || return;
  my @raw=<DAT>;
  close(DAT);

  # generic magic how to get version major/minor/patchlevel
  my ($v_maj) = grep(/^#define[ \t]+[A-Z_]+?MAJOR[A-Z_]*[ \t]+[0-9]+/, @raw);
  $v_maj =~ s/^#define[ \t]+[A-Z_]+[ \t]+([0-9]+)[.\r\n]*$/$1/;
  my ($v_min) = grep(/^#define[ \t]+[A-Z_]+MINOR[A-Z_]*[ \t]+[0-9]+/, @raw);
  $v_min =~ s/^#define[ \t]+[A-Z_]+[ \t]+([0-9]+)[.\r\n]*$/$1/;
  my ($v_pat) = grep(/^#define[ \t]+[A-Z_]+(PATCHLEVEL|MICRO|RELEASE)[A-Z_]*[ \t]+[0-9]+/, @raw);
  $v_pat =~ s/^#define[ \t]+[A-Z_]+[ \t]+([0-9]+)[.\r\n]*$/$1/;
  return if (($v_maj eq '')||($v_min eq '')||($v_pat eq ''));
  return "$v_maj.$v_min.$v_pat";
}

### check presence of header(s) specified as params
sub check_header {
  my ($package, @header) = @_;
  print STDERR "[$package] Testing header(s): " . join(', ', @header) . "\n";
  my $cb = ExtUtils::CBuilder->new(quiet => 1);
  my ($fs, $src) = File::Temp::tempfile('aaXXXX', SUFFIX => '.c', UNLINK => 1);
  my $inc = '';
  $inc .= "#include <$_>\n" for @header;  
  syswrite($fs, <<MARKER); # write test source code



( run in 0.393 second using v1.01-cache-2.11-cpan-02777c243ea )