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