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