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