File Coverage

lib/ExtUtils/Liblist.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 21 23 91.3


line stmt bran cond sub pod time code
1              
2             use strict;
3 53     53   31227 use warnings;
  53         105  
  53         2901  
4 53     53   229  
  53         105  
  53         2438  
5             our $VERSION = '7.64';
6             $VERSION =~ tr/_//d;
7              
8             use File::Spec;
9 53     53   291 require ExtUtils::Liblist::Kid;
  53         95  
  53         6847  
10             our @ISA = qw(ExtUtils::Liblist::Kid File::Spec);
11              
12             # Backwards compatibility with old interface.
13             goto &ExtUtils::Liblist::Kid::ext;
14             }
15 156     156 0 3348  
16             shift;
17             my $rex = qr/$_[1]/;
18             opendir my $dir_fh, $_[0];
19 28     28 0 40 my @out = grep /$rex/, readdir $dir_fh;
20 28         380 closedir $dir_fh;
21 28         594 return @out;
22 28         2346 }
23 28         331  
24 28         1245  
25             =head1 NAME
26              
27             ExtUtils::Liblist - determine libraries to use and how to use them
28              
29             =head1 SYNOPSIS
30              
31             require ExtUtils::Liblist;
32              
33             $MM->ext($potential_libs, $verbose, $need_names);
34              
35             # Usually you can get away with:
36             ExtUtils::Liblist->ext($potential_libs, $verbose, $need_names)
37              
38             =head1 DESCRIPTION
39              
40             This utility takes a list of libraries in the form C<-llib1 -llib2
41             -llib3> and returns lines suitable for inclusion in an extension
42             Makefile. Extra library paths may be included with the form
43             C<-L/another/path> this will affect the searches for all subsequent
44             libraries.
45              
46             It returns an array of four or five scalar values: EXTRALIBS,
47             BSLOADLIBS, LDLOADLIBS, LD_RUN_PATH, and, optionally, a reference to
48             the array of the filenames of actual libraries. Some of these don't
49             mean anything unless on Unix. See the details about those platform
50             specifics below. The list of the filenames is returned only if
51             $need_names argument is true.
52              
53             Dependent libraries can be linked in one of three ways:
54              
55             =over 2
56              
57             =item * For static extensions
58              
59             by the ld command when the perl binary is linked with the extension
60             library. See EXTRALIBS below.
61              
62             =item * For dynamic extensions at build/link time
63              
64             by the ld command when the shared object is built/linked. See
65             LDLOADLIBS below.
66              
67             =item * For dynamic extensions at load time
68              
69             by the DynaLoader when the shared object is loaded. See BSLOADLIBS
70             below.
71              
72             =back
73              
74             =head2 EXTRALIBS
75              
76             List of libraries that need to be linked with when linking a perl
77             binary which includes this extension. Only those libraries that
78             actually exist are included. These are written to a file and used
79             when linking perl.
80              
81             =head2 LDLOADLIBS and LD_RUN_PATH
82              
83             List of those libraries which can or must be linked into the shared
84             library when created using ld. These may be static or dynamic
85             libraries. LD_RUN_PATH is a colon separated list of the directories
86             in LDLOADLIBS. It is passed as an environment variable to the process
87             that links the shared library.
88              
89             =head2 BSLOADLIBS
90              
91             List of those libraries that are needed but can be linked in
92             dynamically at run time on this platform. SunOS/Solaris does not need
93             this because ld records the information (from LDLOADLIBS) into the
94             object file. This list is used to create a .bs (bootstrap) file.
95              
96             =head1 PORTABILITY
97              
98             This module deals with a lot of system dependencies and has quite a
99             few architecture specific C<if>s in the code.
100              
101             =head2 VMS implementation
102              
103             The version of ext() which is executed under VMS differs from the
104             Unix-OS/2 version in several respects:
105              
106             =over 2
107              
108             =item *
109              
110             Input library and path specifications are accepted with or without the
111             C<-l> and C<-L> prefixes used by Unix linkers. If neither prefix is
112             present, a token is considered a directory to search if it is in fact
113             a directory, and a library to search for otherwise. Authors who wish
114             their extensions to be portable to Unix or OS/2 should use the Unix
115             prefixes, since the Unix-OS/2 version of ext() requires them.
116              
117             =item *
118              
119             Wherever possible, shareable images are preferred to object libraries,
120             and object libraries to plain object files. In accordance with VMS
121             naming conventions, ext() looks for files named I<lib>shr and I<lib>rtl;
122             it also looks for I<lib>lib and libI<lib> to accommodate Unix conventions
123             used in some ported software.
124              
125             =item *
126              
127             For each library that is found, an appropriate directive for a linker options
128             file is generated. The return values are space-separated strings of
129             these directives, rather than elements used on the linker command line.
130              
131             =item *
132              
133             LDLOADLIBS contains both the libraries found based on C<$potential_libs> and
134             the CRTLs, if any, specified in Config.pm. EXTRALIBS contains just those
135             libraries found based on C<$potential_libs>. BSLOADLIBS and LD_RUN_PATH
136             are always empty.
137              
138             =back
139              
140             In addition, an attempt is made to recognize several common Unix library
141             names, and filter them out or convert them to their VMS equivalents, as
142             appropriate.
143              
144             In general, the VMS version of ext() should properly handle input from
145             extensions originally designed for a Unix or VMS environment. If you
146             encounter problems, or discover cases where the search could be improved,
147             please let us know.
148              
149             =head2 Win32 implementation
150              
151             The version of ext() which is executed under Win32 differs from the
152             Unix-OS/2 version in several respects:
153              
154             =over 2
155              
156             =item *
157              
158             If C<$potential_libs> is empty, the return value will be empty.
159             Otherwise, the libraries specified by C<$Config{perllibs}> (see Config.pm)
160             will be appended to the list of C<$potential_libs>. The libraries
161             will be searched for in the directories specified in C<$potential_libs>,
162             C<$Config{libpth}>, and in C<$Config{installarchlib}/CORE>.
163             For each library that is found, a space-separated list of fully qualified
164             library pathnames is generated.
165              
166             =item *
167              
168             Input library and path specifications are accepted with or without the
169             C<-l> and C<-L> prefixes used by Unix linkers.
170              
171             An entry of the form C<-La:\foo> specifies the C<a:\foo> directory to look
172             for the libraries that follow.
173              
174             An entry of the form C<-lfoo> specifies the library C<foo>, which may be
175             spelled differently depending on what kind of compiler you are using. If
176             you are using GCC, it gets translated to C<libfoo.a>, but for other win32
177             compilers, it becomes C<foo.lib>. If no files are found by those translated
178             names, one more attempt is made to find them using either C<foo.a> or
179             C<libfoo.lib>, depending on whether GCC or some other win32 compiler is
180             being used, respectively.
181              
182             If neither the C<-L> or C<-l> prefix is present in an entry, the entry is
183             considered a directory to search if it is in fact a directory, and a
184             library to search for otherwise. The C<$Config{lib_ext}> suffix will
185             be appended to any entries that are not directories and don't already have
186             the suffix.
187              
188             Note that the C<-L> and C<-l> prefixes are B<not required>, but authors
189             who wish their extensions to be portable to Unix or OS/2 should use the
190             prefixes, since the Unix-OS/2 version of ext() requires them.
191              
192             =item *
193              
194             Entries cannot be plain object files, as many Win32 compilers will
195             not handle object files in the place of libraries.
196              
197             =item *
198              
199             Entries in C<$potential_libs> beginning with a colon and followed by
200             alphanumeric characters are treated as flags. Unknown flags will be ignored.
201              
202             An entry that matches C</:nodefault/i> disables the appending of default
203             libraries found in C<$Config{perllibs}> (this should be only needed very rarely).
204              
205             An entry that matches C</:nosearch/i> disables all searching for
206             the libraries specified after it. Translation of C<-Lfoo> and
207             C<-lfoo> still happens as appropriate (depending on compiler being used,
208             as reflected by C<$Config{cc}>), but the entries are not verified to be
209             valid files or directories.
210              
211             An entry that matches C</:search/i> reenables searching for
212             the libraries specified after it. You can put it at the end to
213             enable searching for default libraries specified by C<$Config{perllibs}>.
214              
215             =item *
216              
217             The libraries specified may be a mixture of static libraries and
218             import libraries (to link with DLLs). Since both kinds are used
219             pretty transparently on the Win32 platform, we do not attempt to
220             distinguish between them.
221              
222             =item *
223              
224             LDLOADLIBS and EXTRALIBS are always identical under Win32, and BSLOADLIBS
225             and LD_RUN_PATH are always empty (this may change in future).
226              
227             =item *
228              
229             You must make sure that any paths and path components are properly
230             surrounded with double-quotes if they contain spaces. For example,
231             C<$potential_libs> could be (literally):
232              
233             "-Lc:\Program Files\vc\lib" msvcrt.lib "la test\foo bar.lib"
234              
235             Note how the first and last entries are protected by quotes in order
236             to protect the spaces.
237              
238             =item *
239              
240             Since this module is most often used only indirectly from extension
241             C<Makefile.PL> files, here is an example C<Makefile.PL> entry to add
242             a library to the build process for an extension:
243              
244             LIBS => ['-lgl']
245              
246             When using GCC, that entry specifies that MakeMaker should first look
247             for C<libgl.a> (followed by C<gl.a>) in all the locations specified by
248             C<$Config{libpth}>.
249              
250             When using a compiler other than GCC, the above entry will search for
251             C<gl.lib> (followed by C<libgl.lib>).
252              
253             If the library happens to be in a location not in C<$Config{libpth}>,
254             you need:
255              
256             LIBS => ['-Lc:\gllibs -lgl']
257              
258             Here is a less often used example:
259              
260             LIBS => ['-lgl', ':nosearch -Ld:\mesalibs -lmesa -luser32']
261              
262             This specifies a search for library C<gl> as before. If that search
263             fails to find the library, it looks at the next item in the list. The
264             C<:nosearch> flag will prevent searching for the libraries that follow,
265             so it simply returns the value as C<-Ld:\mesalibs -lmesa -luser32>,
266             since GCC can use that value as is with its linker.
267              
268             When using the Visual C compiler, the second item is returned as
269             C<-libpath:d:\mesalibs mesa.lib user32.lib>.
270              
271             When using the Borland compiler, the second item is returned as
272             C<-Ld:\mesalibs mesa.lib user32.lib>, and MakeMaker takes care of
273             moving the C<-Ld:\mesalibs> to the correct place in the linker
274             command line.
275              
276             =back
277              
278              
279             =head1 SEE ALSO
280              
281             L<ExtUtils::MakeMaker>
282              
283             =cut
284