Alien-PNG

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    PNG and/or related libraries like this:

        # Sample Makefile.pl
        use ExtUtils::MakeMaker;
        use Alien::PNG;

        WriteMakefile(
          NAME         => 'Any::PNG::Module',
          VERSION_FROM => 'lib/Any/PNG/Module.pm',
          LIBS         => Alien::PNG->config('libs', [-lAdd_Lib]),
          INC          => Alien::PNG->config('cflags'),
          # + additional params
        );

DESCRIPTION
    Please see Alien for the manifest of the Alien namespace.

    In short "Alien::PNG" can be used to detect and get configuration
    settings from an installed PNG and related libraries. Based on your
    platform it offers the possibility to download and install prebuilt
    binaries or to build PNG & co. from source codes.

README  view on Meta::CPAN

        offers some special functionality (see below).

METHODS
  config()
    This function is the main public interface to this module. Basic
    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');

README  view on Meta::CPAN

    '<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'.

  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.

  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.

inc/My/Builder.pm  view on Meta::CPAN

    $self->add_to_cleanup($build_src, $build_out);

    # save some data into future Alien::PNG::ConfigData
    $self->config_data('build_prefix', $build_out);
    $self->config_data('build_params', $bp);
    $self->config_data('build_cc', $Config{cc});
    $self->config_data('build_arch', $Config{archname});
    $self->config_data('build_os', $^O);
    $self->config_data('script', '');            # just to be sure
    $self->config_data('config', {});            # just to be sure
    $self->config_data('additional_cflags', ''); # just to be sure
    $self->config_data('additional_libs', '');   # just to be sure

    if($bp->{buildtype} eq 'use_config_script') {
      $self->config_data('script', $bp->{script});
      # include path trick - adding couple of addititonal locations
      $self->config_data('additional_cflags', '-I' . get_path($bp->{prefix} . '/include/smpeg') . ' '.
                                              '-I' . get_path($bp->{prefix} . '/include') . ' ' .
                                              $self->get_additional_cflags);
      $self->config_data('additional_libs', $self->get_additional_libs);
    }
    elsif($bp->{buildtype} eq 'use_win32_pkgconfig') {
      $self->config_data(win32_pkgconfig => $bp->{win32_pkgconfig});
    }
    elsif($bp->{buildtype} eq 'use_prebuilt_binaries') {
      # all the following functions die on error, no need to test ret values
      $self->fetch_binaries($download);
      $self->clean_dir($build_out);
      $self->extract_binaries($download, $build_out);

inc/My/Builder.pm  view on Meta::CPAN

  my ($version, $prefix, $incdir, $libdir) = find_PNG_dir(rel2abs($build_out));
  die "###ERROR### Cannot find PNG directory in 'sharedir'" unless $version;
  $self->config_data('share_subdir', abs2rel($prefix, rel2abs('sharedir')));

  # set defaults
  my $cfg = {
    # defaults
    version     => $version,
    prefix      => '@PrEfIx@',
    libs        => '-L' . $self->get_path('@PrEfIx@/lib') . ' -lpng',
    cflags      => '-I' . $self->get_path('@PrEfIx@/include') . ' -D_GNU_SOURCE=1', # -Dmain=SDL_main
    shared_libs => [ ],
  };

  # overwrite values available via libpng-config
  my $bp = $self->config_data('build_prefix') || $prefix;
  my $devnull = File::Spec->devnull();
  my $script = rel2abs("$prefix/bin/libpng-config");
  foreach my $p (qw(version prefix L_opts libs I_opts cflags)) {
    my $o=`$script --$p 2>$devnull`;
    if ($o) {
      $o =~ s/[\r\n]*$//;
      $o =~ s/\Q$prefix\E/\@PrEfIx\@/g;
      $cfg->{$p} = $o;
      
      if($p eq 'libs') {
        $cfg->{$p} = $cfg->{L_opts} . ' ' . $cfg->{$p};
        delete $cfg->{L_opts};
      }
      
      if($p eq 'cflags') {
        $cfg->{$p} = $cfg->{I_opts} . ' ' . $cfg->{$p};
        delete $cfg->{I_opts};
      }
    }
  }

  # find ld_shared_libs and create symlinks if necessary
  my $symlink_exists = eval { symlink("",""); 1 };
  if($symlink_exists)
  {

inc/My/Builder.pm  view on Meta::CPAN

      $shlib_map{png12} = $full unless $shlib_map{png12};
    }
    elsif ($f =~ /^(lib)?(tiff|jpeg|png)[^a-zA-Z]/) {
      $shlib_map{$2} = $full unless $shlib_map{$2};
    }
  };
  $cfg->{ld_paths} = [ keys %tmp ];
  $cfg->{ld_shlib_map} = \%shlib_map;

  # write config
  $self->config_data('additional_cflags', '-I' . $self->get_path('@PrEfIx@/include') . ' ' .
                                          $self->get_additional_cflags);
  $self->config_data('additional_libs', $self->get_additional_libs);
  $self->config_data('config', $cfg);
}

sub can_build_binaries_from_sources {
  # this needs to be overriden in My::Builder::<platform>
  my $self = shift;
  return 0; # no
}

sub build_binaries {
  # this needs to be overriden in My::Builder::<platform>
  my ($self, $build_out, $build_src) = @_;
  die "###ERROR### My::Builder cannot build PNG from sources, use rather My::Builder::<platform>";
}

sub get_additional_cflags {
  # this needs to be overriden in My::Builder::<platform>
  my $self = shift;
  return '';
}

sub get_additional_libs {
  # this needs to be overriden in My::Builder::<platform>
  my $self = shift;
  return '';
}

inc/My/Builder/Unix.pm  view on Meta::CPAN

use warnings;
use base 'My::Builder';

use File::Spec::Functions qw(catdir catfile rel2abs);
use Config;

my $inc_lib_candidates = {
  '/usr/local/include' => '/usr/local/lib',
};

sub get_additional_cflags {
  my $self = shift;
  my @list = ();
  ### any platform specific -L/path/to/libs shoud go here
  for (keys %$inc_lib_candidates) {
    push @list, "-I$_" if (-d $_);
  }
  return join(' ', @list);
}

sub get_additional_libs {

inc/My/Builder/Unix.pm  view on Meta::CPAN

    chdir $self->base_dir();
  }
  return 1;
}

### internal helper functions

sub _get_configure_cmd {
  my ($self, $pack, $prefixdir) = @_;
  my $extra = '';
  my $extra_cflags  = "-I$prefixdir/include";
  my $extra_ldflags = "-L$prefixdir/lib";  
  my $cmd;

  # NOTE: all ugly IFs concerning ./configure params have to go here

  if($pack =~ /^zlib/) {
    # does not support params CFLAGS=...
    $cmd = "./configure --prefix=$prefixdir";
  }
  else {
    $cmd = "./configure --prefix=$prefixdir --enable-static=no --enable-shared=yes $extra" .
           " CFLAGS=\"$extra_cflags\" LDFLAGS=\"$extra_ldflags\"";
  }
  
  # we need to have $prefixdir/bin in PATH while running ./configure
  $cmd = "PATH=\"$prefixdir/bin:\$PATH\" $cmd";
  
  return $cmd;
}

sub _get_make {
  my ($self) = @_;

inc/My/Utility.pm  view on Meta::CPAN

    ],
  },
];

sub check_config_script
{
  my $script = shift || 'libpng-config';
  print "Gonna check config script...\n";
  print "(scriptname=$script)\n";
  my $devnull = File::Spec->devnull();
  my $cflags  = `$script --cflags 2>$devnull`;
  $cflags =~ s/^-I//;
  $cflags =~ s/[\s\n\r]*$//;
  my ($version) = find_PNG_dir($cflags);
  return if($? >> 8);
  my $prefix = `$script --prefix 2>$devnull`;
  return if($? >> 8);
  $version =~ s/[\r\n]*$//;
  $prefix =~ s/[\r\n]*$//;
  #returning HASHREF
  return {
    title     => "Already installed PNG-$version path=$prefix",
    buildtype => 'use_config_script',
    script    => $script,

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

and/or related libraries like this:

    # Sample Makefile.pl
    use ExtUtils::MakeMaker;
    use Alien::PNG;

    WriteMakefile(
      NAME         => 'Any::PNG::Module',
      VERSION_FROM => 'lib/Any/PNG/Module.pm',
      LIBS         => Alien::PNG->config('libs', [-lAdd_Lib]),
      INC          => Alien::PNG->config('cflags'),
      # + additional params
    );

=head1 DESCRIPTION

Please see L<Alien> for the manifest of the Alien namespace.

In short C<Alien::PNG> can be used to detect and get
configuration settings from an installed PNG and related libraries.
Based on your platform it offers the possibility to download and

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

=head1 METHODS

=head2 config()

This function is the main public interface to this module. Basic
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');

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

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.

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

/* GL/gl.h on Win32 requires windows.h being included before */
#include <windows.h>
#endif
$inc
int demofunc(void) { return 0; }

MARKER
  close($fs);
  #open OLDERR, ">&STDERR";
  #open STDERR, ">", File::Spec->devnull();  
  my $obj = eval { $cb->compile( source => $src, extra_compiler_flags => Alien::PNG->config('cflags')); };
  #open(STDERR, ">&OLDERR");
  if($obj) {
    unlink $obj;
    return 1;
  }
  else {
    print STDERR "###TEST FAILED### for: " . join(', ', @header) . "\n";
    return 0;
  }
}

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

### internal functions
sub _png_config_via_script
{
  my $param    = shift;
  my @add_libs = @_;
  my $devnull = File::Spec->devnull();
  my $script = Alien::PNG::ConfigData->config('script');
  return unless ($script && ($param =~ /[a-z0-9_]*/i));
  my $val = `$script --$param 2>$devnull`;
  $val =~ s/[\r\n]*$//;
  if($param eq 'cflags') {
    $val .= ' ' . Alien::PNG::ConfigData->config('additional_cflags');
  }
  elsif($param eq 'libs') {
    $val .= ' ' . join(' ', @add_libs) if scalar @add_libs;
    $val .= ' ' . Alien::PNG::ConfigData->config('additional_libs');
  }
  return $val;
}

sub _png_config_via_win32_pkgconfig
{

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

{
  my $param    = shift;
  my @add_libs = @_;
  my $share_dir = dist_dir('Alien-PNG');
  my $subdir = Alien::PNG::ConfigData->config('share_subdir');
  return unless $subdir;
  my $real_prefix = catdir($share_dir, $subdir);
  return unless ($param =~ /[a-z0-9_]*/i);
  my $val = Alien::PNG::ConfigData->config('config')->{$param};
  return unless $val;
  # handle additional flags
  if($param eq 'cflags') {
    $val .= ' ' . Alien::PNG::ConfigData->config('additional_cflags');
  }
  elsif($param eq 'libs') {
    $val .= ' ' . join(' ', @add_libs) if scalar @add_libs;
    $val .= ' ' . Alien::PNG::ConfigData->config('additional_libs');
  }  
  # handle @PrEfIx@ replacement
  if ($param =~ /^(ld_shared_libs|ld_paths)$/) {
    s/\@PrEfIx\@/$real_prefix/g foreach (@{$val});
  }
  elsif ($param =~ /^(ld_shlib_map)$/) {



( run in 1.161 second using v1.01-cache-2.11-cpan-94b05bcf43c )