/lib/SDL/Internal/Loader.pm

http://github.com/PerlGameDev/SDL · Perl · 54 lines · 26 code · 7 blank · 21 comment · 3 complexity · a9585390c889fcd8d8108cfc04380695 MD5 · raw file

  1. package SDL::Internal::Loader;
  2. use strict;
  3. use warnings;
  4. require Exporter;
  5. our @ISA = qw(Exporter);
  6. our @EXPORT = qw(internal_load_dlls);
  7. our @LIBREFS = ();
  8. use SDL::ConfigData;
  9. use Alien::SDL;
  10. our $VERSION = 2.548;
  11. # SDL::Internal::Loader is a king of "Dynaloader kung-fu" that is
  12. # necessary in situations when you install Allien::SDL from sources
  13. # or from prebuilt binaries as in these scenarios the SDL stuff is
  14. # installed into so called 'sharedir' somewhere in perl/lib/ tree
  15. # on Windows box it is e.g.
  16. # C:\strawberry\perl\site\lib\auto\share\dist\Alien-SDL...
  17. #
  18. # What happens is that for example XS module "SDL::Video" is linked
  19. # with -lSDL library which means that resulting "Video.(so|dll)" has
  20. # a dependency on "libSDL.(so|dll)" - however "libSDL.(so|dll)" is
  21. # neither in PATH (Win) or in LD_LIBRARY_PATH (Unix) so Dynaloader
  22. # will fail to load "Video.(so|dll)".
  23. #
  24. # To handle this we have internal_load_dlls() which has to be called
  25. # from XS modules (e.g. SDL::Video) linked with SDL libs like this:
  26. #
  27. # use SDL::Internal::Loader;
  28. # internal_load_dlls(PACKAGE);
  29. sub internal_load_dlls($) {
  30. my $package = shift;
  31. ### check if some ld_shlib_map is defined
  32. my $shlib_map = Alien::SDL->config('ld_shlib_map');
  33. return unless $shlib_map; # empty shlib_map, nothing to do
  34. ### get list of lib nicknames based on packagename
  35. my $lib_nick = SDL::ConfigData->config('SDL_lib_translate')->{$package};
  36. return unless $lib_nick; # no need to load anything
  37. ### let us load the corresponding shlibs (*.dll|*.so)
  38. require DynaLoader;
  39. foreach my $n (@$lib_nick) {
  40. my $file = $shlib_map->{$n};
  41. next unless $file && -e $file;
  42. my $libref = DynaLoader::dl_load_file( $file, 0 );
  43. push( @DynaLoader::dl_librefs, $libref ) if $libref;
  44. push( @LIBREFS, $libref ) if $libref;
  45. }
  46. }
  47. 1;