This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to ExtUtils-MakeMaker-6.48
[perl5.git] / lib / ExtUtils / Mkbootstrap.pm
CommitLineData
005c1a0e 1package ExtUtils::Mkbootstrap;
15e1d173 2
1e65eb70
SP
3# There's just too much Dynaloader incest here to turn on strict vars.
4use strict 'refs';
5
b5b9b385 6our $VERSION = '6.48';
1e65eb70
SP
7
8require Exporter;
a592ba15
RGS
9our @ISA = ('Exporter');
10our @EXPORT = ('&Mkbootstrap');
15e1d173 11
005c1a0e 12use Config;
1e65eb70 13
a592ba15 14our $Verbose = 0;
1e65eb70 15
005c1a0e
AD
16
17sub Mkbootstrap {
005c1a0e 18 my($baseext, @bsloadlibs)=@_;
005c1a0e
AD
19 @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
20
21 print STDOUT " bsloadlibs=@bsloadlibs\n" if $Verbose;
22
23 # We need DynaLoader here because we and/or the *_BS file may
24 # call dl_findfile(). We don't say `use' here because when
25 # first building perl extensions the DynaLoader will not have
26 # been built when MakeMaker gets first used.
27 require DynaLoader;
28
29 rename "$baseext.bs", "$baseext.bso"
30 if -s "$baseext.bs";
31
32 if (-f "${baseext}_BS"){
33 $_ = "${baseext}_BS";
34 package DynaLoader; # execute code as if in DynaLoader
15e1d173
PP
35 local($osname, $dlsrc) = (); # avoid warnings
36 ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
005c1a0e
AD
37 $bscode = "";
38 unshift @INC, ".";
39 require $_;
40 shift @INC;
41 }
42
43 if ($Config{'dlsrc'} =~ /^dl_dld/){
44 package DynaLoader;
45 push(@dl_resolve_using, dl_findfile('-lc'));
46 }
47
48 my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
49 my($method) = '';
50 if (@all){
a592ba15 51 open my $bs, ">", "$baseext.bs"
005c1a0e
AD
52 or die "Unable to open $baseext.bs: $!";
53 print STDOUT "Writing $baseext.bs\n";
54 print STDOUT " containing: @all" if $Verbose;
a592ba15
RGS
55 print $bs "# $baseext DynaLoader bootstrap file for $^O architecture.\n";
56 print $bs "# Do not edit this file, changes will be lost.\n";
57 print $bs "# This file was automatically generated by the\n";
58 print $bs "# Mkbootstrap routine in ExtUtils::Mkbootstrap (v$VERSION).\n";
59 print $bs "\@DynaLoader::dl_resolve_using = ";
005c1a0e
AD
60 # If @all contains names in the form -lxxx or -Lxxx then it's asking for
61 # runtime library location so we automatically add a call to dl_findfile()
62 if (" @all" =~ m/ -[lLR]/){
a592ba15 63 print $bs " dl_findfile(qw(\n @all\n ));\n";
005c1a0e 64 }else{
a592ba15 65 print $bs " qw(@all);\n";
005c1a0e
AD
66 }
67 # write extra code if *_BS says so
a592ba15
RGS
68 print $bs $DynaLoader::bscode if $DynaLoader::bscode;
69 print $bs "\n1;\n";
70 close $bs;
005c1a0e
AD
71 }
72}
73
15e1d173
PP
741;
75
76__END__
77
78=head1 NAME
79
80ExtUtils::Mkbootstrap - make a bootstrap file for use by DynaLoader
81
82=head1 SYNOPSIS
83
39234879 84C<Mkbootstrap>
15e1d173
PP
85
86=head1 DESCRIPTION
87
88Mkbootstrap typically gets called from an extension Makefile.
89
a7665c5e
GS
90There is no C<*.bs> file supplied with the extension. Instead, there may
91be a C<*_BS> file which has code for the special cases, like posix for
15e1d173
PP
92berkeley db on the NeXT.
93
94This file will get parsed, and produce a maybe empty
95C<@DynaLoader::dl_resolve_using> array for the current architecture.
96That will be extended by $BSLOADLIBS, which was computed by
97ExtUtils::Liblist::ext(). If this array still is empty, we do nothing,
98else we write a .bs file with an C<@DynaLoader::dl_resolve_using>
99array.
100
101The C<*_BS> file can put some code into the generated C<*.bs> file by
102placing it in C<$bscode>. This is a handy 'escape' mechanism that may
103prove useful in complex situations.
104
105If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
106Mkbootstrap will automatically add a dl_findfile() call to the
107generated C<*.bs> file.
108
109=cut