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