1package ExtUtils::Mkbootstrap;
2
3# There's just too much Dynaloader incest here to turn on strict vars.
4use strict 'refs';
5
6our $VERSION = '6.98';
7
8require Exporter;
9our @ISA = ('Exporter');
10our @EXPORT = ('&Mkbootstrap');
11
12use Config;
13
14our $Verbose = 0;
15
16
17sub Mkbootstrap {
18    my($baseext, @bsloadlibs)=@_;
19    @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
20
21    print "	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
35	local($osname, $dlsrc) = (); # avoid warnings
36	($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
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){
51	open my $bs, ">", "$baseext.bs"
52		or die "Unable to open $baseext.bs: $!";
53	print "Writing $baseext.bs\n";
54	print "	containing: @all" if $Verbose;
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 = ";
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]/){
63	    print $bs "  dl_findfile(qw(\n  @all\n  ));\n";
64	}else{
65	    print $bs "  qw(@all);\n";
66	}
67	# write extra code if *_BS says so
68	print $bs $DynaLoader::bscode if $DynaLoader::bscode;
69	print $bs "\n1;\n";
70	close $bs;
71    }
72}
73
741;
75
76__END__
77
78=head1 NAME
79
80ExtUtils::Mkbootstrap - make a bootstrap file for use by DynaLoader
81
82=head1 SYNOPSIS
83
84C<Mkbootstrap>
85
86=head1 DESCRIPTION
87
88Mkbootstrap typically gets called from an extension Makefile.
89
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
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
110