563241f1dae82fdd440239760db86fc692b48020
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MakeMaker.pm
1 package ExtUtils::MakeMaker;
2
3 # Authors: Andy Dougherty       <doughera@lafcol.lafayette.edu>
4 #          Andreas Koenig       <k@franz.ww.TU-Berlin.DE>
5 #          Tim Bunce            <Tim.Bunce@ig.co.uk>
6
7 # Last Revision: 12 Oct 1994
8
9 # This utility is designed to write a Makefile for an extension 
10 # module from a Makefile.PL. It is based on the excellent Makefile.SH
11 # model provided by Andy Dougherty and the perl5-porters. 
12
13 # It splits the task of generating the Makefile into several
14 # subroutines that can be individually overridden.
15 # Each subroutine returns the text it wishes to have written to
16 # the Makefile.
17
18 use Config;
19 require Exporter;
20 @ISA = qw(Exporter);
21 @EXPORT = qw(writeMakefile mkbootstrap $Verbose);
22 @EXPORT_OK = qw(%att @recognized_att_keys);
23
24 use strict qw(refs);
25
26 # Setup dummy package:
27 # MY exists for overriding methods to be defined within
28 unshift(@MY::ISA, qw(MM));
29
30 $Verbose = 0;
31 $Subdirs = 0;   # set to 1 to have this .PL run all below
32 $^W=1;
33
34
35 # For most extensions it will do to call
36 #
37 #   use ExtUtils::MakeMaker
38 #   &writeMakefile("potential_libs" => "-L/usr/alpha -lfoo -lbar");
39 #
40 # from Makefile.PL in the extension directory
41 # It is also handy to include some of the following attributes:
42 #
43 @recognized_att_keys=qw(
44     TOP INC DISTNAME VERSION DEFINE OBJECT LDTARGET ARMAYBE
45     BACKUP_LIBS  AUTOSPLITMAXLEN LINKTYPE
46     potential_libs otherldflags perl fullperl
47     distclean_tarflags
48     clean_files realclean_files
49 );
50
51 #
52 # TOP      is the directory above lib/ and ext/ (normally ../..)
53 #          (MakeMaker will normally work this out for itself)
54 # INC      is something like "-I/usr/local/Minerva/include"
55 # DISTNAME is a name of your choice for distributing the package
56 # VERSION  is your version number
57 # DEFINE   is something like "-DHAVE_UNISTD_H"
58 # OBJECT   defaults to '$(BASEEXT).o', but can be a long string containing 
59 #          all object files, e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
60 # LDTARGET defaults to $(OBJECT) and is used in the ld command
61 #          (some machines need additional switches for bigger projects)
62 # ARMAYBE  defaults to ":", but can be used to run ar before ld
63 # BACKUP_LIBS is an anonymous array of libraries to be searched for
64 #          until we get at least some output from ext/util/extliblist
65 #          'potential_libs' => "-lgdbm",
66 #          'BACKUP_LIBS' => [ "-ldbm -lfoo", "-ldbm.nfs" ]
67 # AUTOSPLITMAXLEN defaults to 8 and is used when autosplit is done
68 #          (can be set higher on a case-by-case basis)
69 # defaults to `dynamic', can be set to `static'
70
71 #
72 # `make distclean'  builds $(DISTNAME)-$(VERSION).tar.Z after a clean
73
74 # Be aware, that you can also pass attributes into the %att hash table
75 # by calling Makefile.PL with an argument of the form TOP=/some/where.
76
77 # If the Makefile generated by default does not fit your purpose,
78 # you may specify private subroutines in the Makefile.PL as there are:
79 #
80 # MY->initialize        =>   sub MY::initialize{ ... }
81 # MY->post_initialize   =>   sub MY::post_initialize{ ... }
82 # MY->constants         =>   etc
83 # MY->dynamic
84 # etc. (see function writeMakefile, for the current breakpoints)
85 #
86 # Each subroutines returns the text it wishes to have written to
87 # the Makefile. To override a section of the Makefile you can
88 # either say:   sub MY::co { "new literal text" }
89 # or you can edit the default by saying something like:
90 #       sub MY::co { $_=MM->co; s/old text/new text/; $_ }
91 #
92 # If you still need a different solution, try to develop another 
93 # subroutine, that fits your needs and submit the diffs to 
94 # perl5-porters or comp.lang.perl as appropriate.
95
96 sub writeMakefile {
97     %att = @_;
98     local($\)="\n";
99
100     foreach (@ARGV){
101         $att{$1}=$2 if m/(.*)=(.*)/;
102     }
103     print STDOUT "MakeMaker" if $Verbose;
104     print STDOUT map("  $_ = '$att{$_}'\n", sort keys %att) if ($Verbose && %att);
105
106     MY->initialize();
107
108     print STDOUT "Writing ext/$att{FULLEXT}/Makefile (with variable substitutions)";
109
110     open MAKE, ">Makefile" or die "Unable to open Makefile: $!";
111
112     MY->mkbootstrap(split(" ", $att{'dynaloadlibs'}));
113     print MAKE MY->post_initialize;
114
115     print MAKE MY->constants;
116     print MAKE MY->post_constants;
117
118     print MAKE MY->subdir if $Subdirs;
119     print MAKE MY->dynamic;
120     print MAKE MY->force;
121     print MAKE MY->static;
122     print MAKE MY->co;
123     print MAKE MY->c;
124     print MAKE MY->installpm;
125     print MAKE MY->clean;
126     print MAKE MY->realclean;
127     print MAKE MY->test;
128     print MAKE MY->install;
129     print MAKE MY->perldepend;
130     print MAKE MY->distclean;
131     print MAKE MY->postamble;
132
133     MY->finish;
134
135     close MAKE;
136
137     1;
138 }
139
140
141 sub mkbootstrap{
142     MY->mkbootstrap(@_)
143 }
144
145
146 sub avoid_typo_warnings{
147     local($t) = "$t
148         $main::writeMakefile
149         $main::mkbootstrap
150         $main::Verbose
151         $DynaLoader::dl_resolve_using
152         $ExtUtils::MakeMaker::Config
153         $DynaLoader::Config
154     ";
155 }
156
157
158 # --- Supply the MakeMaker default methods ---
159
160 package MM;
161
162 use Config;
163 require Exporter;
164
165 Exporter::import('ExtUtils::MakeMaker', qw(%att @recognized_att_keys));
166
167 # These attributes cannot be overridden
168 @other_att_keys=qw(extralibs dynaloadlibs statloadlibs bootdep);
169
170
171 sub find_perl{
172     my($self, $ver, $names, $dirs, $trace) = @_;
173     my($name, $dir);
174     print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n"
175         if ($trace);
176     foreach $dir (@$dirs){
177         foreach $name (@$names){
178             print "checking $dir/$name\n" if ($trace >= 2);
179             next unless -x "$dir/$name";
180             print "executing $dir/$name\n" if ($trace);
181             my($out) = `$dir/$name -e 'require $ver; print "5OK\n" ' 2>&1`;
182             return "$dir/$name" if $out =~ /5OK/;
183         }
184     }
185     warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
186     0; # false and not empty
187 }
188
189
190 sub initialize {
191     # Find out directory name.  This is also the extension name.
192     chop($pwd=`pwd`);
193
194     unless ( $top = $att{TOP} ){
195         foreach(qw(../.. ../../.. ../../../..)){
196             ($top=$_, last) if -f "$_/config.sh";
197         }
198         die "Can't find config.sh" unless -f "$top/config.sh";
199     }
200     chdir $top or die "Couldn't chdir $top: $!";
201     chop($abstop=`pwd`);
202     chdir $pwd;
203
204     # EXTMODNAME = The perl module name for this extension.
205     # FULLEXT = Full pathname to extension directory.
206     # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
207     # ROOTEXT = Directory part of FULLEXT. May be empty.
208     my($p) = $pwd; $p =~ s:^\Q$abstop/ext/\E::;
209     ($att{EXTMODNAME}=$p) =~ s#/#::#g ;         #eg. BSD::Foo::Socket
210     ($att{FULLEXT}   =$p);                      #eg. BSD/Foo/Socket
211     ($att{BASEEXT}   =$p) =~ s:.*/:: ;          #eg. Socket
212     ($att{ROOTEXT}   =$p) =~ s:/?\Q$att{BASEEXT}\E$:: ; #eg. BSD/Foo
213
214     # Find Perl 5. The only contract here is that both 'perl' and 'fullperl'
215     # will be working versions of perl 5.
216     $att{'perl'} = MY->find_perl(5.0, [ qw(perl5 perl miniperl) ],
217                             [ $abstop, split(":", $ENV{PATH}) ], 0 )
218             unless ($att{'perl'} && -x $att{'perl'});
219
220     # Define 'fullperl' to be a non-miniperl (used in test: target)
221     ($att{'fullperl'} = $att{'perl'}) =~ s/miniperl$/perl/
222         unless ($att{'fullperl'} && -x $att{'fullperl'});
223
224     for $key (@recognized_att_keys, @other_att_keys){
225         # avoid warnings for uninitialized vars
226         $att{$key} = "" unless defined $att{$key};
227     }
228
229     # compute extralibs, dynaloadlibs and statloadlibs from
230     # $att{'potential_libs'}
231
232     unless ( &run_extliblist($att{'potential_libs'}) ){
233        foreach ( @{$att{'BACKUP_LIBS'} || []} ){
234            #  Try again.  Maybe they have specified some other libraries
235            last if  &run_extliblist($_);
236        }
237     }
238 }
239
240
241 sub run_extliblist {
242     my($potential_libs)=@_;
243     # Now run ext/util/extliblist to discover what *libs definitions
244     # are required for the needs of $potential_libs
245     $ENV{'potential_libs'} = $potential_libs;
246     $_=`. $abstop/ext/util/extliblist;
247         echo extralibs=\$extralibs
248         echo dynaloadlibs=\$dynaloadlibs
249         echo statloadlibs=\$statloadlibs
250         echo bootdep=\$bootdep
251         `;
252     my(@w);
253     foreach $line (split "\n", $_){
254         chomp $line;
255         if ($line =~ /(.*)\s*=\s*(.*)$/){
256             $att{$1} = $2;
257             print STDERR "      $1 = $2" if $Verbose;
258         }else{
259             push(@w, $line);
260         }
261     }
262     print STDERR "Messages from extliblist:\n", join("\n",@w,'')
263        if @w ;
264     join '', @att{qw(extralibs dynaloadlibs statloadlibs)};
265 }
266
267
268 sub post_initialize{
269     "";
270 }
271  
272
273 sub constants {
274     my(@m);
275
276     $att{BOOTDEP}  = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
277     $att{OBJECT}   = '$(BASEEXT).o' unless $att{OBJECT};
278     $att{LDTARGET} = '$(OBJECT)'    unless $att{LDTARGET};
279     $att{ARMAYBE}  = ":"            unless $att{ARMAYBE};
280     $att{AUTOSPLITMAXLEN} = 8       unless $att{AUTOSPLITMAXLEN};
281     $att{LINKTYPE} = ($Config{'usedl'}) ? 'dynamic' : 'static'
282         unless $att{LINKTYPE};
283
284
285     push @m, "
286 #
287 # This Makefile is for the $att{FULLEXT} extension to perl.
288 # It was written by Makefile.PL, so don't edit it, edit
289 # Makefile.PL instead. ANY CHANGES MADE HERE WILL BE LOST!
290
291
292 DISTNAME = $att{DISTNAME}
293 VERSION = $att{VERSION}
294
295 TOP = $top
296 ABSTOP = $abstop
297 PERL = $att{'perl'}
298 FULLPERL = $att{'fullperl'}
299 INC = $att{INC}
300 DEFINE = $att{DEFINE}
301 OBJECT = $att{OBJECT}
302 LDTARGET = $att{LDTARGET}
303 ";
304
305     push @m, "
306 CC = $Config{'cc'}
307 LIBC = $Config{'libc'}
308 LDFLAGS = $Config{'ldflags'}
309 CLDFLAGS = $Config{'ldflags'}
310 LINKTYPE = $att{LINKTYPE}
311 ARMAYBE = $att{ARMAYBE}
312 RANLIB = $Config{'ranlib'}
313
314 SMALL = $Config{'small'}
315 LARGE = $Config{'large'} $Config{'split'}
316 # The following are used to build and install shared libraries for
317 # dynamic loading.
318 LDDLFLAGS = $Config{'lddlflags'}
319 CCDLFLAGS = $Config{'ccdlflags'}
320 CCCDLFLAGS = $Config{'cccdlflags'}
321 SO = $Config{'so'}
322 DLEXT = $Config{'dlext'}
323 DLSRC = $Config{'dlsrc'}
324 ";
325
326     push @m, "
327 # $att{FULLEXT} might need to be linked with some extra libraries.
328 # EXTRALIBS =  full list of libraries needed for static linking.
329 #               Only those libraries that actually exist are included.
330 # DYNALOADLIBS = list of those libraries that are needed but can be
331 #               linked in dynamically on this platform.  On SunOS, for
332 #               example, this would be .so* libraries, but not archive
333 #               libraries.  The bootstrap file is installed only if
334 #               this list is not empty.
335 # STATLOADLIBS = list of those libraries which must be statically
336 #               linked into the shared library.  On SunOS 4.1.3, 
337 #               for example,  I have only an archive version of
338 #               -lm, and it must be linked in statically.
339 EXTRALIBS = $att{'extralibs'}
340 DYNALOADLIBS = $att{'dynaloadlibs'}
341 STATLOADLIBS = $att{'statloadlibs'}
342
343 ";
344
345     push @m, "
346 # EXTMODNAME = The perl module name for this extension.
347 # FULLEXT = Full pathname to extension directory.
348 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
349 # ROOTEXT = Directory part of FULLEXT. May be empty.
350 EXTMODNAME = $att{EXTMODNAME}
351 FULLEXT = $att{FULLEXT}
352 BASEEXT = $att{BASEEXT}
353 ROOTEXT = $att{ROOTEXT}
354 # and for backward compatibility and for AIX support (due to change!)
355 EXT = $att{BASEEXT}
356
357 # $att{FULLEXT} might have its own typemap
358 EXTTYPEMAP = ".(-f "typemap" ? "typemap" : "")."
359 # $att{FULLEXT} might have its own bootstrap support
360 BOOTSTRAP = $att{BASEEXT}.bs
361 BOOTDEP = $att{BOOTDEP}
362 ";
363
364     push @m, '
365 # Where to put things:
366 AUTO = $(TOP)/lib/auto
367 AUTOEXT = $(TOP)/lib/auto/$(FULLEXT)
368 INST_BOOT = $(AUTOEXT)/$(BASEEXT).bs
369 INST_DYNAMIC = $(AUTOEXT)/$(BASEEXT).$(DLEXT)
370 INST_STATIC = $(BASEEXT).a
371 INST_PM = $(TOP)/lib/$(FULLEXT).pm
372 '."
373 # These two are only used by install: targets
374 INSTALLPRIVLIB = $Config{'installprivlib'}
375 INSTALLARCHLIB = $Config{'installarchlib'}
376 ";
377
378     push @m, "\nshellflags = $Config{'shellflags'}" if $Config{'shellflags'};
379
380     push @m, q{
381 # Tools
382 SHELL = /bin/sh
383 CCCMD = `sh $(shellflags) $(ABSTOP)/cflags $@`
384 XSUBPP = $(TOP)/ext/xsubpp
385 # the following is a portable way to say mkdir -p
386 MKPATH = $(PERL) -we '$$"="/"; foreach(split(/\//,$$ARGV[0])){ push(@p, $$_); next if -d "@p"; print "mkdir @p\n"; mkdir("@p",0777)||die "mkdir @p: $$!" } exit 0;'
387 AUTOSPLITLIB = cd $(TOP); \
388         $(PERL) -Ilib -e 'use AutoSplit; $$AutoSplit::Maxlen=}.$att{AUTOSPLITMAXLEN}.q{; autosplit_lib_modules(@ARGV) ;'
389 };
390
391     push @m, '
392
393 all :: 
394
395 config :: Makefile
396         @$(MKPATH) $(AUTOEXT)
397
398 install ::
399
400 ';
401
402     join('',@m);
403 }
404
405
406 sub post_constants{
407     "";
408 }
409
410
411 sub subdir {
412     my(@m);
413     foreach $MakefilePL (<*/Makefile.PL>){
414         ($subdir=$MakefilePL) =~ s:/Makefile\.PL$:: ;
415         push @m, "
416 config ::
417         \@cd $subdir ; \\
418         if test ! -f Makefile; then \\
419         test -f Makefile.PL  && \$(PERL) -I\$(ABSTOP)/lib Makefile.PL TOP=\$(ABSTOP) ; \\
420         fi
421
422 all ::
423         cd $subdir ; \$(MAKE) config
424         cd $subdir ; \$(MAKE) all
425 ";
426
427     }
428     join('',@m);
429 }
430
431
432 sub co {
433     '
434 .c.o:
435         $(CCCMD) $(CCCDLFLAGS) $(DEFINE) -I$(TOP) $(INC) $*.c
436 ';
437 }
438
439
440 sub force {
441     '
442 # Phony target to force checking subdirectories.
443 FORCE:
444 ';
445 }
446
447
448 sub dynamic {
449     '
450 all::   $(LINKTYPE)
451
452 # Target for Dynamic Loading:
453 dynamic::       $(INST_DYNAMIC) $(INST_PM) $(INST_BOOT)
454
455 $(INST_DYNAMIC): $(OBJECT)
456         @$(MKPATH) $(AUTOEXT)
457         $(ARMAYBE) cr $(EXTMODNAME).a $(OBJECT) 
458         ld $(LDDLFLAGS) -o $@ $(LDTARGET) '.$att{'otherldflags'}.' $(STATLOADLIBS)
459
460 $(BOOTSTRAP): $(BOOTDEP)
461         $(PERL) -I$(TOP)/lib -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(DYNALOADLIBS)");\'
462         touch $(BOOTSTRAP)
463
464 $(INST_BOOT): $(BOOTSTRAP)
465         @test ! -s $(BOOTSTRAP) || cp $(BOOTSTRAP) $@
466 ';
467 }
468
469
470 sub static {
471     '
472 # Target for Static Loading:
473 static:: $(INST_STATIC) $(INST_PM)
474
475 $(INST_STATIC): $(OBJECT)
476         ar cr $@ $(OBJECT)
477         $(RANLIB) $@
478         echo $(EXTRALIBS) >> $(TOP)/ext.libs
479 ';
480 }
481
482
483 sub c {
484     '
485 $(BASEEXT).c:   $(BASEEXT).xs $(XSUBPP) $(TOP)/ext/typemap $(EXTTYPEMAP) $(TOP)/cflags
486         $(PERL) $(XSUBPP) $(BASEEXT).xs >tmp
487         mv tmp $@
488 ';
489 }
490
491
492 sub installpm {
493     '
494 $(INST_PM):     $(BASEEXT).pm
495         @$(MKPATH) $(TOP)/lib/$(ROOTEXT)
496         rm -f $@
497         cp $(BASEEXT).pm $@
498         @$(AUTOSPLITLIB) $(EXTMODNAME)
499 ';
500 }
501
502
503 sub clean {
504     '
505 clean::
506         rm -f *.o *.a mon.out core $(BASEEXT).c so_locations
507         rm -f makefile Makefile $(BOOTSTRAP) $(BASEEXT).bso '.$att{'clean_files'}.'
508 ';
509 }
510
511
512 sub realclean {
513     '
514 realclean::     clean
515         rm -f $(INST_DYNAMIC) $(INST_STATIC) $(INST_BOOT)
516         rm -rf $(INST_PM) $(AUTOEXT) '.$att{'realclean_files'}.'
517
518 purge:  realclean
519 ';
520 }
521
522
523 sub test {
524     '
525 test: all
526         $(FULLPERL) -I$(TOP)/lib -e \'use Test::Harness; runtests @ARGV;\' t/*.t
527 ';
528 }
529
530
531 sub install {
532     '
533 # used if installperl will not be installing it for you
534 install:: all
535         # not yet defined
536 ';
537 }
538
539
540 sub distclean {
541     my($tarflags) = $att{'distclean_tarflags'} || 'cvf';
542     '
543 distclean:     clean
544         rm -f Makefile *~ t/*~
545         cd ..; tar '.$tarflags.' "$(DISTNAME)-$(VERSION).tar" $(BASEEXT)
546         cd ..; compress "$(DISTNAME)-$(VERSION).tar"
547 ';
548 }
549
550
551 sub perldepend {
552     '
553 $(OBJECT) : Makefile
554 $(OBJECT) : $(TOP)/EXTERN.h
555 $(OBJECT) : $(TOP)/INTERN.h
556 $(OBJECT) : $(TOP)/XSUB.h
557 $(OBJECT) : $(TOP)/av.h
558 $(OBJECT) : $(TOP)/cop.h
559 $(OBJECT) : $(TOP)/cv.h
560 $(OBJECT) : $(TOP)/dosish.h
561 $(OBJECT) : $(TOP)/embed.h
562 $(OBJECT) : $(TOP)/form.h
563 $(OBJECT) : $(TOP)/gv.h
564 $(OBJECT) : $(TOP)/handy.h
565 $(OBJECT) : $(TOP)/hv.h
566 $(OBJECT) : $(TOP)/keywords.h
567 $(OBJECT) : $(TOP)/mg.h
568 $(OBJECT) : $(TOP)/op.h
569 $(OBJECT) : $(TOP)/opcode.h
570 $(OBJECT) : $(TOP)/patchlevel.h
571 $(OBJECT) : $(TOP)/perl.h
572 $(OBJECT) : $(TOP)/perly.h
573 $(OBJECT) : $(TOP)/pp.h
574 $(OBJECT) : $(TOP)/proto.h
575 $(OBJECT) : $(TOP)/regcomp.h
576 $(OBJECT) : $(TOP)/regexp.h
577 $(OBJECT) : $(TOP)/scope.h
578 $(OBJECT) : $(TOP)/sv.h
579 $(OBJECT) : $(TOP)/unixish.h
580 $(OBJECT) : $(TOP)/util.h
581 $(TOP)/config.h:        $(TOP)/config.sh; cd $(TOP); /bin/sh config_h.SH
582 $(TOP)/embed.h: $(TOP)/config.sh; cd $(TOP); /bin/sh embed_h.SH
583 $(TOP)/cflags:  $(TOP)/config.sh; cd $(TOP); /bin/sh cflags.SH
584
585 Makefile:       Makefile.PL
586         $(PERL) -I$(TOP)/lib Makefile.PL
587 ';
588 }
589
590
591 sub postamble{
592     "";
593 }
594
595
596 sub finish {
597     chmod 0644, "Makefile";
598     system("$Config{'eunicefix'} Makefile") unless $Config{'eunicefix'} eq ":";
599 }
600
601
602
603 sub mkbootstrap {
604 #
605 # mkbootstrap, by:
606 #
607 #       Andreas Koenig <k@otto.ww.TU-Berlin.DE>
608 #       Tim Bunce <Tim.Bunce@ig.co.uk>
609 #       Andy Dougherty <doughera@lafcol.lafayette.edu>
610 #
611 #  This perl script attempts to make a bootstrap file for use by this
612 #  system's DynaLoader. It typically gets called from an extension
613 #  Makefile.
614 #
615 # There is no .bs file supplied with the extension. Instead a _BS
616 # file which has code for the special cases, like posix for berkeley db
617 # on the NeXT.
618
619 # This file will get parsed, and produce a maybe empty
620 # @DynaLoader::dl_resolve_using array for the current architecture.
621 # That will be extended by $dynaloadlibs, which was computed by Andy's
622 # extliblist script. If this array still is empty, we do nothing, else
623 # we write a .bs file with an @DynaLoader::dl_resolve_using array, but
624 # without any `if's, because there is no longer a need to deal with
625 # special cases.
626
627 # The _BS file can put some code into the generated .bs file by placing
628 # it in $bscode. This is a handy 'escape' mechanism that may prove
629 # useful in complex situations.
630
631 # If @DynaLoader::dl_resolve_using contains -L* or -l* entries then
632 # mkbootstrap will automatically add a dl_findfile() call to the
633 # generated .bs file.
634 #
635     my($self, @dynaloadlibs)=@_;
636     print STDERR "      dynaloadlibs=@dynaloadlibs" if $Verbose;
637     require DynaLoader; # we need DynaLoader, if the *_BS gets interpreted
638     import DynaLoader;  # we don't say `use', so if DynaLoader is not 
639                   # yet built MakeMaker works nonetheless except here
640
641     &initialize unless defined $att{'perl'};
642
643     rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
644
645     if (-f "$att{BASEEXT}_BS"){
646         $_ = "$att{BASEEXT}_BS";
647         package DynaLoader; # execute code as if in DynaLoader
648         local($osname, $dlsrc) = (); # avoid warnings
649         ($osname, $dlsrc) = @Config{qw(osname dlsrc)};
650         $bscode = "";
651         unshift @INC, ".";
652         require $_;
653     }
654
655     if ($Config{'dlsrc'} =~ /^dl_dld/){
656         package DynaLoader;
657         push(@dl_resolve_using, dl_findfile('-lc'));
658     }
659
660     my(@all) = (@dynaloadlibs, @DynaLoader::dl_resolve_using);
661     my($method) = '';
662     if (@all){
663         open BS, ">$att{BASEEXT}.bs"
664                 or die "Unable to open $att{BASEEXT}.bs: $!";
665         print STDOUT "Writing $att{BASEEXT}.bs\n";
666         print STDOUT "  containing: @all" if $Verbose;
667         print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
668         print BS "# Do not edit this file, changes will be lost.\n";
669         print BS "# This file was automatically generated by the\n";
670         print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
671         print BS "\@DynaLoader::dl_resolve_using = ";
672         if (" @all" =~ m/ -[lL]/){
673             print BS "  dl_findfile(qw(\n  @all\n  ));\n";
674         }else{
675             print BS "  qw(@all);\n";
676         }
677         # write extra code if *_BS says so
678         print BS $DynaLoader::bscode if $DynaLoader::bscode;
679         print BS "1;\n";
680         close BS;
681     }
682
683     if ($Config{'dlsrc'} =~ /^dl_aix/){
684        open AIX, ">$att{BASEEXT}.exp";
685        print AIX "#!\nboot_$att{BASEEXT}\n";
686        close AIX;
687     }
688 }
689
690 # the following makes AutoSplit happy (bug in perl5b3e)
691 package ExtUtils::MakeMaker;
692 1;
693
694 __END__