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