PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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