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