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