Alien-SDL2

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    SDL2 and/or related libraries like this:

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

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

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

    In short "Alien::SDL2" can be used to detect and get configuration
    settings from an installed SDL2 and related libraries. Based on your
    platform it offers the possibility to download and install prebuilt
    binaries or to build SDL2 & 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 'sdl2-config' script:

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

    On top of that this function supports special parameters:

        Alien::SDL2->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 SDL2
    libs.

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

README  view on Meta::CPAN

    '<full_path_to_shlib'>, where '<libnick>' is shortname for SDL2 related
    library like: SDL2, SDL2_gfx, SDL2_net, SDL2_sound ... + some non-SDL2
    shortnames e.g. smpeg, jpeg, png.

    NOTE: config('ld_<something>') return an empty list/hash if you have
    decided to use SDL2 libraries already installed on your system. This
    concerns 'sdl2-config' detection.

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

        Alien::SDL2->check_header('SDL2.h');
        Alien::SDL2->check_header('SDL2.h', 'SDL2_net.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 SDL2 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::SDL2::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->set_ld_config($build_out);
      $self->config_data('additional_cflags', '-I' . $self->get_path($bp->{prefix} . '/include/smpeg') . ' '.
                                              '-I' . $self->get_path($bp->{prefix} . '/include') . ' ' .
                                              $self->get_additional_cflags);
      $self->config_data('additional_libs', $self->get_additional_libs);
    }
    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);
      $self->set_config_data($build_out);
      $self->set_ld_config($build_out);
    }

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

  # set defaults
  my $L   = $My::Utility::cc eq 'cl'
          ? '/LIBPATH:'
          : '-L';
  my $cfg = $self->config_data('config') || {};

  # defaults
  $cfg->{version}        = $version;
  $cfg->{prefix}         = '@PrEfIx@';
  $cfg->{libs}           = $L . $self->get_path('@PrEfIx@/lib') . ' -lSDL2main -lSDL2';
  $cfg->{cflags}         = '-I' . $self->get_path('@PrEfIx@/include/SDL2') . ' -D_GNU_SOURCE=1 -Dmain=SDL2_main';
  $cfg->{ld_shared_libs} = [ ];

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

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

sub set_ld_config {
  my( $self, $build_out ) = @_;
  my ($version, $prefix, $incdir, $libdir) = find_SDL2_dir(rel2abs($build_out));
  my $cfg   = $self->config_data('config') || {};
  my $dlext = get_dlext();
  # find ld_shared_libs and create symlinks if necessary

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

  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 SDL2 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

package My::Builder::Unix;

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

use File::Spec::Functions qw(catdir catfile rel2abs);
use My::Utility qw(check_header check_prereqs_libs check_prereqs_tools $inc_lib_candidates);
use Config;

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

  }
  return 1;
}

### internal helper functions

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

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

  if($pack =~ /^SDL2_(image|mixer|ttf|gfx|net)$/) {
    $extra .= ' --disable-sdltest';
  }

  if($pack =~ /^SDL2_/) {
    $extra .= " --with-sdl-prefix=$escaped_prefixdir";
  }

  if($pack eq 'z') {
    # does not support params CFLAGS=...
    $cmd = "./configure --prefix=$escaped_prefixdir";
  }
  else {
    $cmd = "./configure --prefix=$escaped_prefixdir --enable-static=yes --enable-shared=yes $extra" .
           " CFLAGS=\"$extra_cflags\" LDFLAGS=\"$extra_ldflags\"";
  }

  if($pack eq 'vorbis') {
    $cmd = "PKG_CONFIG_PATH=\"$escaped_prefixdir/lib/pkgconfig:\$PKG_CONFIG_PATH\" $cmd";
  }

  return $cmd;
}

sub _get_make {

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

  my( $self, $build_out, $build_src ) = @_;
  die "###ERROR### Building from sources not supported on MS Windows platform";
}

sub get_path {
  my ( $self, $path ) = @_;
  $path = '"' . $path . '"';
  return $path;
}

sub get_additional_cflags {
  my $self = shift;
  if($My::Utility::cc eq 'cl' && $self->notes('env_include')) {
    my $include = $self->notes('env_include');
    $include    =~ s/"//g;
    my @include = split(/;/, $include);
    my $cflags  = '';
    my $inc = $_;
    for( @include ) {
      my $inc = eval { require Win32; Win32::GetShortPathName($_); };
      $inc ||= $_;
      $cflags    .= "-I\"$inc\" " ;
    }
    return $cflags;
  }
  return '';
}

sub get_additional_libs {
  my $self = shift;
  if($My::Utility::cc eq 'cl' && $self->notes('env_lib')) {
    my $lib  = $self->notes('env_lib');
    $lib     =~ s/"//g;
    my @libs = split(/;/, $lib);

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

    return (
      $version,
      catpath($v, catdir(@pp), ''),
      catpath($v, catdir(@pp, 'include'), ''),
      catpath($v, catdir(@pp, 'lib'), ''),
    );
  }
}

sub check_header {
  my ($cflags, @header) = @_;
  print STDERR "Testing header(s): " . join(', ', @header) . "\n";
  my $cb = ExtUtils::CBuilder->new(quiet => 1);
  my ($fs, $src) = File::Temp->tempfile( 'XXXX', SUFFIX => 'aa.c', UNLINK => 1);
  my $inc = '';
  $inc .= "#include <$_>\n" for @header;
  syswrite($fs, <<MARKER); # write test source code
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <stdio.h>
/* GL/gl.h on Win32 requires windows.h being included before */
#include <windows.h>
#endif
$inc
int demofunc(void) { return 0; }

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

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

and/or related libraries like this:

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

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

=head1 DESCRIPTION

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

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

lib/Alien/SDL2.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 'sdl2-config' script:

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

On top of that this function supports special parameters:

    Alien::SDL2->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 SDL2 libs.

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

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

where '<libnick>' is shortname for SDL2 related library like: SDL2, SDL2_gfx, SDL2_net,
SDL2_sound ... + some non-SDL2 shortnames e.g. smpeg, jpeg, png.

NOTE: config('ld_<something>') return an empty list/hash if you have decided to
use SDL2 libraries already installed on your system. This concerns 'sdl2-config'
detection.

=head2 check_header()

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

    Alien::SDL2->check_header('SDL2.h');
    Alien::SDL2->check_header('SDL2.h', 'SDL2_net.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 SDL2 prefix direcotry and
based on "#define" macros inside this header file tries to get a version triplet.

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


### check presence of header(s) specified as params
sub check_header {
  my ($package, @header) = @_;
  print STDERR "[$package] Testing header(s): " . join(', ', @header);

  require ExtUtils::CBuilder; # PAR packer workaround

  my $config = {};
  if($^O eq 'cygwin') {
    my $ccflags = $Config{ccflags};
    $ccflags    =~ s/-fstack-protector//;
    $config     = { ld => 'gcc', cc => 'gcc', ccflags => $ccflags };
  }

  my $cb = ExtUtils::CBuilder->new( quiet => 1, config => $config );
  my ($fs, $src) = tempfile('XXXX', SUFFIX => 'aa.c', UNLINK => 1);
  my $inc = '';
  my $i = 0;
  foreach (@header) {
    @header = (splice(@header, 0, $i) , 'stdio.h', splice(@header, $i)) if $_ eq 'jpeglib.h';
    $i++;
  }

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

#endif
$inc
int demofunc(void) { return 0; }

MARKER
  close($fs);
  my $obj;
  my $stdout = '';
  my $stderr = '';
  ($stdout, $stderr) = Capture::Tiny::capture {
    $obj = eval { $cb->compile( source => $src, extra_compiler_flags => Alien::SDL2->config('cflags')); };
  };

  if($obj) {
    print STDERR "\n";
    unlink $obj;
    return 1;
  }
  else {
    if( $stderr ) {
      $stderr =~ s/[\r\n]$//;

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

### internal functions
sub _sdl2_config_via_script
{
  my $param    = shift;
  my @add_libs = @_;
  my $devnull = File::Spec->devnull();
  my $script = Alien::SDL2::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::SDL2::ConfigData->config('additional_cflags');
  }
  elsif($param eq 'libs') {
    $val .= ' ' . join(' ', @add_libs) if scalar @add_libs;
    $val .= ' ' . Alien::SDL2::ConfigData->config('additional_libs');
  }
  elsif($param =~ /^(ld_shlib_map|ld_shared_libs|ld_paths)$/) {
    $val = Alien::SDL2::ConfigData->config('config')->{$param};
  }
  return $val;
}

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

{
  my $param    = shift;
  my @add_libs = @_;
  my $share_dir = dist_dir('Alien-SDL2');
  my $subdir = Alien::SDL2::ConfigData->config('share_subdir');
  return unless $subdir;
  my $real_prefix = catdir($share_dir, $subdir);
  return unless ($param =~ /[a-z0-9_]*/i);
  my $val = Alien::SDL2::ConfigData->config('config')->{$param};
  return unless $val;
  # handle additional flags
  if($param eq 'cflags') {
    $val .= ' ' . Alien::SDL2::ConfigData->config('additional_cflags');
  }
  elsif($param eq 'libs') {
    $val .= ' ' . join(' ', @add_libs) if scalar @add_libs;
    $val .= ' ' . Alien::SDL2::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 0.657 second using v1.01-cache-2.11-cpan-94b05bcf43c )