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