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