Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/ExtUtils/Liblist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ dynamically at run time on this platform. SunOS/Solaris does not need
this because ld records the information (from LDLOADLIBS) into the
object file. This list is used to create a .bs (bootstrap) file.

=head1 ENVIRONMENT

=over 4

=item LIBRARY_PATH

On Unix and OS/2, if the C<LIBRARY_PATH> environment variable is set, its
colon-separated list of directories is prepended to the default library search
path derived from C<$Config{libpth}>. This allows users to point to a
custom or updated version of a library without modifying Perl's configuration:

LIBRARY_PATH=/opt/mylibs/lib perl Makefile.PL

Directories listed in C<LIBRARY_PATH> take priority over those in
C<$Config{libpth}>, but C<-L> flags explicitly passed via C<LIBS> still take
the highest priority.

On Win32 the same variable is honoured when GCC is in use (as
C<$Config{cc}> contains C<gcc>).

=back

=head1 PORTABILITY

This module deals with a lot of system dependencies and has quite a
Expand Down
5 changes: 5 additions & 0 deletions lib/ExtUtils/Liblist/Kid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ sub _unix_os2_ext {

my @searchpath; # from "-L/path" entries in $potential_libs
my @libpath = _space_dirs_split($Config{libpth} || '');
# Honor LIBRARY_PATH environment variable (colon-separated, used by GCC and
# other tools). Prepend so user-specified paths take priority over libpth.
if ( defined $ENV{LIBRARY_PATH} ) {
unshift @libpath, grep { length } split /:/, $ENV{LIBRARY_PATH};
}
my ( @ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen );
my ( @libs, %libs_seen );
my ( $fullname, @fullname );
Expand Down
16 changes: 16 additions & 0 deletions t/Liblist_Kid.t
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ sub test_kid_unix_os2 {
my @got = _ext( '-ldir_test' );
is_deeply \@got, [ '-ldir_test', '', '-ldir_test', 'di r' ], 'Config.libpth directories with spaces work' or diag explain \@got;
}
{
my $abs = File::Spec->rel2abs('.');
local $ENV{LIBRARY_PATH} = $abs;
local $Config{libpth} = '';
my @got = _ext( '-lfoo' );
like $got[0], qr/-lfoo/, '$ENV{LIBRARY_PATH} adds search paths for extralibs' or diag explain \@got;
like $got[2], qr/-lfoo/, '$ENV{LIBRARY_PATH} adds search paths for ldloadlibs' or diag explain \@got;
ok $got[3], '$ENV{LIBRARY_PATH} results in non-empty LD_RUN_PATH' or diag explain \@got;
}
{
my $abs = File::Spec->rel2abs('.');
local $ENV{LIBRARY_PATH} = "/nonexistent:$abs";
local $Config{libpth} = '';
my @got = _ext( '-lfoo' );
like $got[0], qr/-lfoo/, '$ENV{LIBRARY_PATH} with multiple colon-separated entries finds lib in second path' or diag explain \@got;
}
my $mm = WriteMakefile(
NAME => 'Big::Dummy',
VERSION => '1.00',
Expand Down