home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / lib / ExtUtils / MM_Unix.pm < prev    next >
Text File  |  1999-04-02  |  101KB  |  3,577 lines

  1. package ExtUtils::MM_Unix;
  2.  
  3. use Exporter ();
  4. use Config;
  5. use File::Basename qw(basename dirname fileparse);
  6. use DirHandle;
  7. use strict;
  8. use vars qw($VERSION $Is_Mac $Is_OS2 $Is_VMS $Is_Win32 $Is_Dos $Is_RISCOS
  9.         $Is_PERL_OBJECT $Verbose %pm %static $Xsubpp_Version);
  10.  
  11. $VERSION = substr q$Revision: 1.12602 $, 10;
  12. # $Id: MM_Unix.pm,v 1.126 1998/06/28 21:32:49 k Exp k $
  13.  
  14. Exporter::import('ExtUtils::MakeMaker',
  15.     qw( $Verbose &neatvalue));
  16.  
  17. $Is_OS2 = $^O eq 'os2';
  18. $Is_Mac = $^O eq 'MacOS';
  19. $Is_Win32 = $^O eq 'MSWin32';
  20. $Is_Dos = $^O eq 'dos';
  21. $Is_RISCOS = $^O eq 'riscos';
  22.  
  23. $Is_PERL_OBJECT = $Config{'ccflags'} =~ /-DPERL_OBJECT/;
  24.  
  25. if ($Is_VMS = $^O eq 'VMS') {
  26.     require VMS::Filespec;
  27.     import VMS::Filespec qw( &vmsify );
  28. }
  29.  
  30. =head1 NAME
  31.  
  32. ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
  33.  
  34. =head1 SYNOPSIS
  35.  
  36. C<require ExtUtils::MM_Unix;>
  37.  
  38. =head1 DESCRIPTION
  39.  
  40. The methods provided by this package are designed to be used in
  41. conjunction with ExtUtils::MakeMaker. When MakeMaker writes a
  42. Makefile, it creates one or more objects that inherit their methods
  43. from a package C<MM>. MM itself doesn't provide any methods, but it
  44. ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
  45. specific packages take the responsibility for all the methods provided
  46. by MM_Unix. We are trying to reduce the number of the necessary
  47. overrides by defining rather primitive operations within
  48. ExtUtils::MM_Unix.
  49.  
  50. If you are going to write a platform specific MM package, please try
  51. to limit the necessary overrides to primitive methods, and if it is not
  52. possible to do so, let's work out how to achieve that gain.
  53.  
  54. If you are overriding any of these methods in your Makefile.PL (in the
  55. MY class), please report that to the makemaker mailing list. We are
  56. trying to minimize the necessary method overrides and switch to data
  57. driven Makefile.PLs wherever possible. In the long run less methods
  58. will be overridable via the MY class.
  59.  
  60. =head1 METHODS
  61.  
  62. The following description of methods is still under
  63. development. Please refer to the code for not suitably documented
  64. sections and complain loudly to the makemaker mailing list.
  65.  
  66. Not all of the methods below are overridable in a
  67. Makefile.PL. Overridable methods are marked as (o). All methods are
  68. overridable by a platform specific MM_*.pm file (See
  69. L<ExtUtils::MM_VMS>) and L<ExtUtils::MM_OS2>).
  70.  
  71. =head2 Preloaded methods
  72.  
  73. =over 2
  74.  
  75. =item canonpath
  76.  
  77. No physical check on the filesystem, but a logical cleanup of a
  78. path. On UNIX eliminated successive slashes and successive "/.".
  79.  
  80. =cut
  81.  
  82. sub canonpath {
  83.     my($self,$path) = @_;
  84.     my $node = '';
  85.     if ( $^O eq 'qnx' && $path =~ s|^(//\d+)/|/| ) {
  86.       $node = $1;
  87.     }
  88.     $path =~ s|(?<=[^/])/+|/|g ;                   # xx////xx  -> xx/xx
  89.     $path =~ s|(/\.)+/|/|g ;                       # xx/././xx -> xx/xx
  90.     $path =~ s|^(\./)+|| unless $path eq "./";     # ./xx      -> xx
  91.     $path =~ s|(?<=[^/])/$|| ;                     # xx/       -> xx
  92.     "$node$path";
  93. }
  94.  
  95. =item catdir
  96.  
  97. Concatenate two or more directory names to form a complete path ending
  98. with a directory. But remove the trailing slash from the resulting
  99. string, because it doesn't look good, isn't necessary and confuses
  100. OS2. Of course, if this is the root directory, don't cut off the
  101. trailing slash :-)
  102.  
  103. =cut
  104.  
  105. # ';
  106.  
  107. sub catdir {
  108.     my $self = shift @_;
  109.     my @args = @_;
  110.     for (@args) {
  111.     # append a slash to each argument unless it has one there
  112.     $_ .= "/" if $_ eq '' or substr($_,-1) ne "/";
  113.     }
  114.     $self->canonpath(join('', @args));
  115. }
  116.  
  117. =item catfile
  118.  
  119. Concatenate one or more directory names and a filename to form a
  120. complete path ending with a filename
  121.  
  122. =cut
  123.  
  124. sub catfile {
  125.     my $self = shift @_;
  126.     my $file = pop @_;
  127.     return $self->canonpath($file) unless @_;
  128.     my $dir = $self->catdir(@_);
  129.     for ($dir) {
  130.     $_ .= "/" unless substr($_,length($_)-1,1) eq "/";
  131.     }
  132.     return $self->canonpath($dir.$file);
  133. }
  134.  
  135. =item curdir
  136.  
  137. Returns a string representing of the current directory.  "." on UNIX.
  138.  
  139. =cut
  140.  
  141. sub curdir {
  142.     return "." ;
  143. }
  144.  
  145. =item rootdir
  146.  
  147. Returns a string representing of the root directory.  "/" on UNIX.
  148.  
  149. =cut
  150.  
  151. sub rootdir {
  152.     return "/";
  153. }
  154.  
  155. =item updir
  156.  
  157. Returns a string representing of the parent directory.  ".." on UNIX.
  158.  
  159. =cut
  160.  
  161. sub updir {
  162.     return "..";
  163. }
  164.  
  165. sub ExtUtils::MM_Unix::c_o ;
  166. sub ExtUtils::MM_Unix::clean ;
  167. sub ExtUtils::MM_Unix::const_cccmd ;
  168. sub ExtUtils::MM_Unix::const_config ;
  169. sub ExtUtils::MM_Unix::const_loadlibs ;
  170. sub ExtUtils::MM_Unix::constants ;
  171. sub ExtUtils::MM_Unix::depend ;
  172. sub ExtUtils::MM_Unix::dir_target ;
  173. sub ExtUtils::MM_Unix::dist ;
  174. sub ExtUtils::MM_Unix::dist_basics ;
  175. sub ExtUtils::MM_Unix::dist_ci ;
  176. sub ExtUtils::MM_Unix::dist_core ;
  177. sub ExtUtils::MM_Unix::dist_dir ;
  178. sub ExtUtils::MM_Unix::dist_test ;
  179. sub ExtUtils::MM_Unix::dlsyms ;
  180. sub ExtUtils::MM_Unix::dynamic ;
  181. sub ExtUtils::MM_Unix::dynamic_bs ;
  182. sub ExtUtils::MM_Unix::dynamic_lib ;
  183. sub ExtUtils::MM_Unix::exescan ;
  184. sub ExtUtils::MM_Unix::export_list ;
  185. sub ExtUtils::MM_Unix::extliblist ;
  186. sub ExtUtils::MM_Unix::file_name_is_absolute ;
  187. sub ExtUtils::MM_Unix::find_perl ;
  188. sub ExtUtils::MM_Unix::fixin ;
  189. sub ExtUtils::MM_Unix::force ;
  190. sub ExtUtils::MM_Unix::guess_name ;
  191. sub ExtUtils::MM_Unix::has_link_code ;
  192. sub ExtUtils::MM_Unix::init_dirscan ;
  193. sub ExtUtils::MM_Unix::init_main ;
  194. sub ExtUtils::MM_Unix::init_others ;
  195. sub ExtUtils::MM_Unix::install ;
  196. sub ExtUtils::MM_Unix::installbin ;
  197. sub ExtUtils::MM_Unix::libscan ;
  198. sub ExtUtils::MM_Unix::linkext ;
  199. sub ExtUtils::MM_Unix::lsdir ;
  200. sub ExtUtils::MM_Unix::macro ;
  201. sub ExtUtils::MM_Unix::makeaperl ;
  202. sub ExtUtils::MM_Unix::makefile ;
  203. sub ExtUtils::MM_Unix::manifypods ;
  204. sub ExtUtils::MM_Unix::maybe_command ;
  205. sub ExtUtils::MM_Unix::maybe_command_in_dirs ;
  206. sub ExtUtils::MM_Unix::needs_linking ;
  207. sub ExtUtils::MM_Unix::nicetext ;
  208. sub ExtUtils::MM_Unix::parse_version ;
  209. sub ExtUtils::MM_Unix::pasthru ;
  210. sub ExtUtils::MM_Unix::path ;
  211. sub ExtUtils::MM_Unix::perl_archive;
  212. sub ExtUtils::MM_Unix::perl_script ;
  213. sub ExtUtils::MM_Unix::perldepend ;
  214. sub ExtUtils::MM_Unix::pm_to_blib ;
  215. sub ExtUtils::MM_Unix::post_constants ;
  216. sub ExtUtils::MM_Unix::post_initialize ;
  217. sub ExtUtils::MM_Unix::postamble ;
  218. sub ExtUtils::MM_Unix::ppd ;
  219. sub ExtUtils::MM_Unix::prefixify ;
  220. sub ExtUtils::MM_Unix::processPL ;
  221. sub ExtUtils::MM_Unix::realclean ;
  222. sub ExtUtils::MM_Unix::replace_manpage_separator ;
  223. sub ExtUtils::MM_Unix::static ;
  224. sub ExtUtils::MM_Unix::static_lib ;
  225. sub ExtUtils::MM_Unix::staticmake ;
  226. sub ExtUtils::MM_Unix::subdir_x ;
  227. sub ExtUtils::MM_Unix::subdirs ;
  228. sub ExtUtils::MM_Unix::test ;
  229. sub ExtUtils::MM_Unix::test_via_harness ;
  230. sub ExtUtils::MM_Unix::test_via_script ;
  231. sub ExtUtils::MM_Unix::tool_autosplit ;
  232. sub ExtUtils::MM_Unix::tool_xsubpp ;
  233. sub ExtUtils::MM_Unix::tools_other ;
  234. sub ExtUtils::MM_Unix::top_targets ;
  235. sub ExtUtils::MM_Unix::writedoc ;
  236. sub ExtUtils::MM_Unix::xs_c ;
  237. sub ExtUtils::MM_Unix::xs_cpp ;
  238. sub ExtUtils::MM_Unix::xs_o ;
  239. sub ExtUtils::MM_Unix::xsubpp_version ;
  240.  
  241. package ExtUtils::MM_Unix;
  242.  
  243. use SelfLoader;
  244.  
  245. 1;
  246.  
  247. __DATA__
  248.  
  249. =back
  250.  
  251. =head2 SelfLoaded methods
  252.  
  253. =over 2
  254.  
  255. =item c_o (o)
  256.  
  257. Defines the suffix rules to compile different flavors of C files to
  258. object files.
  259.  
  260. =cut
  261.  
  262. sub c_o {
  263. # --- Translation Sections ---
  264.  
  265.     my($self) = shift;
  266.     return '' unless $self->needs_linking();
  267.     my(@m);
  268.     push @m, '
  269. .c$(OBJ_EXT):
  270.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
  271. ';
  272.     push @m, '
  273. .C$(OBJ_EXT):
  274.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.C
  275. ' if $^O ne 'os2' and $^O ne 'MSWin32' and $^O ne 'dos' and $^O ne 'riscos';
  276.   # Case-specific
  277.     push @m, '
  278. .cpp$(OBJ_EXT):
  279.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cpp
  280.  
  281. .cxx$(OBJ_EXT):
  282.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cxx
  283.  
  284. .cc$(OBJ_EXT):
  285.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.cc
  286. ';
  287.     join "", @m;
  288. }
  289.  
  290. =item cflags (o)
  291.  
  292. Does very much the same as the cflags script in the perl
  293. distribution. It doesn't return the whole compiler command line, but
  294. initializes all of its parts. The const_cccmd method then actually
  295. returns the definition of the CCCMD macro which uses these parts.
  296.  
  297. =cut
  298.  
  299. #'
  300.  
  301. sub cflags {
  302.     my($self,$libperl)=@_;
  303.     return $self->{CFLAGS} if $self->{CFLAGS};
  304.     return '' unless $self->needs_linking();
  305.  
  306.     my($prog, $uc, $perltype, %cflags);
  307.     $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
  308.     $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
  309.  
  310.     @cflags{qw(cc ccflags optimize large split shellflags)}
  311.     = @Config{qw(cc ccflags optimize large split shellflags)};
  312.     my($optdebug) = "";
  313.  
  314.     $cflags{shellflags} ||= '';
  315.  
  316.     my(%map) =  (
  317.         D =>   '-DDEBUGGING',
  318.         E =>   '-DEMBED',
  319.         DE =>  '-DDEBUGGING -DEMBED',
  320.         M =>   '-DEMBED -DMULTIPLICITY',
  321.         DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
  322.         );
  323.  
  324.     if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
  325.     $uc = uc($1);
  326.     } else {
  327.     $uc = ""; # avoid warning
  328.     }
  329.     $perltype = $map{$uc} ? $map{$uc} : "";
  330.  
  331.     if ($uc =~ /^D/) {
  332.     $optdebug = "-g";
  333.     }
  334.  
  335.  
  336.     my($name);
  337.     ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
  338.     if ($prog = $Config::Config{$name}) {
  339.     # Expand hints for this extension via the shell
  340.     print STDOUT "Processing $name hint:\n" if $Verbose;
  341.     my(@o)=`cc=\"$cflags{cc}\"
  342.       ccflags=\"$cflags{ccflags}\"
  343.       optimize=\"$cflags{optimize}\"
  344.       perltype=\"$cflags{perltype}\"
  345.       optdebug=\"$cflags{optdebug}\"
  346.       large=\"$cflags{large}\"
  347.       split=\"$cflags{'split'}\"
  348.       eval '$prog'
  349.       echo cc=\$cc
  350.       echo ccflags=\$ccflags
  351.       echo optimize=\$optimize
  352.       echo perltype=\$perltype
  353.       echo optdebug=\$optdebug
  354.       echo large=\$large
  355.       echo split=\$split
  356.       `;
  357.     my($line);
  358.     foreach $line (@o){
  359.         chomp $line;
  360.         if ($line =~ /(.*?)=\s*(.*)\s*$/){
  361.         $cflags{$1} = $2;
  362.         print STDOUT "    $1 = $2\n" if $Verbose;
  363.         } else {
  364.         print STDOUT "Unrecognised result from hint: '$line'\n";
  365.         }
  366.     }
  367.     }
  368.  
  369.     if ($optdebug) {
  370.     $cflags{optimize} = $optdebug;
  371.     }
  372.  
  373.     for (qw(ccflags optimize perltype large split)) {
  374.     $cflags{$_} =~ s/^\s+//;
  375.     $cflags{$_} =~ s/\s+/ /g;
  376.     $cflags{$_} =~ s/\s+$//;
  377.     $self->{uc $_} ||= $cflags{$_}
  378.     }
  379.  
  380.     if ($self->{CAPI} && $Is_PERL_OBJECT) {
  381.         $self->{CCFLAGS} =~ s/-DPERL_OBJECT(\s|$)//;
  382.         $self->{CCFLAGS} .= ' -DPERL_CAPI ';
  383.         if ($Is_Win32 && $Config{'cc'} =~ /^cl.exe/i) {
  384.             # Turn off C++ mode of the MSC compiler
  385.             $self->{CCFLAGS} =~ s/-TP(\s|$)//;
  386.             $self->{OPTIMIZE} =~ s/-TP(\s|$)//;
  387.         }
  388.     }
  389.     return $self->{CFLAGS} = qq{
  390. CCFLAGS = $self->{CCFLAGS}
  391. OPTIMIZE = $self->{OPTIMIZE}
  392. PERLTYPE = $self->{PERLTYPE}
  393. LARGE = $self->{LARGE}
  394. SPLIT = $self->{SPLIT}
  395. };
  396.  
  397. }
  398.  
  399. =item clean (o)
  400.  
  401. Defines the clean target.
  402.  
  403. =cut
  404.  
  405. sub clean {
  406. # --- Cleanup and Distribution Sections ---
  407.  
  408.     my($self, %attribs) = @_;
  409.     my(@m,$dir);
  410.     push(@m, '
  411. # Delete temporary files but do not touch installed files. We don\'t delete
  412. # the Makefile here so a later make realclean still has a makefile to use.
  413.  
  414. clean ::
  415. ');
  416.     # clean subdirectories first
  417.     for $dir (@{$self->{DIR}}) {
  418.     push @m, "\t-cd $dir && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) clean\n";
  419.     }
  420.  
  421.     my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
  422.     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
  423.     push(@otherfiles, qw[./blib $(MAKE_APERL_FILE) $(INST_ARCHAUTODIR)/extralibs.all
  424.              perlmain.c mon.out core so_locations pm_to_blib
  425.              *~ */*~ */*/*~ *$(OBJ_EXT) *$(LIB_EXT) perl.exe
  426.              $(BOOTSTRAP) $(BASEEXT).bso $(BASEEXT).def
  427.              $(BASEEXT).exp
  428.             ]);
  429.     push @m, "\t-$self->{RM_RF} @otherfiles\n";
  430.     # See realclean and ext/utils/make_ext for usage of Makefile.old
  431.     push(@m,
  432.      "\t-$self->{MV} $self->{MAKEFILE} $self->{MAKEFILE}.old \$(DEV_NULL)\n");
  433.     push(@m,
  434.      "\t$attribs{POSTOP}\n")   if $attribs{POSTOP};
  435.     join("", @m);
  436. }
  437.  
  438. =item const_cccmd (o)
  439.  
  440. Returns the full compiler call for C programs and stores the
  441. definition in CONST_CCCMD.
  442.  
  443. =cut
  444.  
  445. sub const_cccmd {
  446.     my($self,$libperl)=@_;
  447.     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
  448.     return '' unless $self->needs_linking();
  449.     return $self->{CONST_CCCMD} =
  450.     q{CCCMD = $(CC) -c $(INC) $(CCFLAGS) $(OPTIMIZE) \\
  451.     $(PERLTYPE) $(LARGE) $(SPLIT) $(DEFINE_VERSION) \\
  452.     $(XS_DEFINE_VERSION)};
  453. }
  454.  
  455. =item const_config (o)
  456.  
  457. Defines a couple of constants in the Makefile that are imported from
  458. %Config.
  459.  
  460. =cut
  461.  
  462. sub const_config {
  463. # --- Constants Sections ---
  464.  
  465.     my($self) = shift;
  466.     my(@m,$m);
  467.     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
  468.     push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
  469.     my(%once_only);
  470.     foreach $m (@{$self->{CONFIG}}){
  471.     # SITE*EXP macros are defined in &constants; avoid duplicates here
  472.     next if $once_only{$m} or $m eq 'sitelibexp' or $m eq 'sitearchexp';
  473.     push @m, "\U$m\E = ".$self->{uc $m}."\n";
  474.     $once_only{$m} = 1;
  475.     }
  476.     join('', @m);
  477. }
  478.  
  479. =item const_loadlibs (o)
  480.  
  481. Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
  482. L<ExtUtils::Liblist> for details.
  483.  
  484. =cut
  485.  
  486. sub const_loadlibs {
  487.     my($self) = shift;
  488.     return "" unless $self->needs_linking;
  489.     my @m;
  490.     push @m, qq{
  491. # $self->{NAME} might depend on some other libraries:
  492. # See ExtUtils::Liblist for details
  493. #
  494. };
  495.     my($tmp);
  496.     for $tmp (qw/
  497.      EXTRALIBS LDLOADLIBS BSLOADLIBS LD_RUN_PATH
  498.      /) {
  499.     next unless defined $self->{$tmp};
  500.     push @m, "$tmp = $self->{$tmp}\n";
  501.     }
  502.     return join "", @m;
  503. }
  504.  
  505. =item constants (o)
  506.  
  507. Initializes lots of constants and .SUFFIXES and .PHONY
  508.  
  509. =cut
  510.  
  511. sub constants {
  512.     my($self) = @_;
  513.     my(@m,$tmp);
  514.  
  515.     for $tmp (qw/
  516.  
  517.           AR_STATIC_ARGS NAME DISTNAME NAME_SYM VERSION
  518.           VERSION_SYM XS_VERSION INST_BIN INST_EXE INST_LIB
  519.           INST_ARCHLIB INST_SCRIPT PREFIX  INSTALLDIRS
  520.           INSTALLPRIVLIB INSTALLARCHLIB INSTALLSITELIB
  521.           INSTALLSITEARCH INSTALLBIN INSTALLSCRIPT PERL_LIB
  522.           PERL_ARCHLIB SITELIBEXP SITEARCHEXP LIBPERL_A MYEXTLIB
  523.           FIRST_MAKEFILE MAKE_APERL_FILE PERLMAINCC PERL_SRC
  524.           PERL_INC PERL FULLPERL
  525.  
  526.           / ) {
  527.     next unless defined $self->{$tmp};
  528.     push @m, "$tmp = $self->{$tmp}\n";
  529.     }
  530.  
  531.     push @m, qq{
  532. VERSION_MACRO = VERSION
  533. DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
  534. XS_VERSION_MACRO = XS_VERSION
  535. XS_DEFINE_VERSION = -D\$(XS_VERSION_MACRO)=\\\"\$(XS_VERSION)\\\"
  536. };
  537.  
  538.     push @m, qq{
  539. MAKEMAKER = $INC{'ExtUtils/MakeMaker.pm'}
  540. MM_VERSION = $ExtUtils::MakeMaker::VERSION
  541. };
  542.  
  543.     push @m, q{
  544. # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
  545. # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
  546. # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)  !!! Deprecated from MM 5.32  !!!
  547. # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
  548. # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
  549. };
  550.  
  551.     for $tmp (qw/
  552.           FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
  553.           LDFROM LINKTYPE
  554.           /    ) {
  555.     next unless defined $self->{$tmp};
  556.     push @m, "$tmp = $self->{$tmp}\n";
  557.     }
  558.  
  559.     push @m, "
  560. # Handy lists of source code files:
  561. XS_FILES= ".join(" \\\n\t", sort keys %{$self->{XS}})."
  562. C_FILES = ".join(" \\\n\t", @{$self->{C}})."
  563. O_FILES = ".join(" \\\n\t", @{$self->{O_FILES}})."
  564. H_FILES = ".join(" \\\n\t", @{$self->{H}})."
  565. MAN1PODS = ".join(" \\\n\t", sort keys %{$self->{MAN1PODS}})."
  566. MAN3PODS = ".join(" \\\n\t", sort keys %{$self->{MAN3PODS}})."
  567. ";
  568.  
  569.     for $tmp (qw/
  570.           INST_MAN1DIR INSTALLMAN1DIR MAN1EXT INST_MAN3DIR INSTALLMAN3DIR MAN3EXT
  571.           /) {
  572.     next unless defined $self->{$tmp};
  573.     push @m, "$tmp = $self->{$tmp}\n";
  574.     }
  575.  
  576.     for $tmp (qw(
  577.         PERM_RW PERM_RWX
  578.         )
  579.          ) {
  580.         my $method = lc($tmp);
  581.     # warn "self[$self] method[$method]";
  582.         push @m, "$tmp = ", $self->$method(), "\n";
  583.     }
  584.  
  585.     push @m, q{
  586. .NO_CONFIG_REC: Makefile
  587. } if $ENV{CLEARCASE_ROOT};
  588.  
  589.     # why not q{} ? -- emacs
  590.     push @m, qq{
  591. # work around a famous dec-osf make(1) feature(?):
  592. makemakerdflt: all
  593.  
  594. .SUFFIXES: .xs .c .C .cpp .cxx .cc \$(OBJ_EXT)
  595.  
  596. # Nick wanted to get rid of .PRECIOUS. I don't remember why. I seem to recall, that
  597. # some make implementations will delete the Makefile when we rebuild it. Because
  598. # we call false(1) when we rebuild it. So make(1) is not completely wrong when it
  599. # does so. Our milage may vary.
  600. # .PRECIOUS: Makefile    # seems to be not necessary anymore
  601.  
  602. .PHONY: all config static dynamic test linkext manifest
  603.  
  604. # Where is the Config information that we are using/depend on
  605. CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
  606. };
  607.  
  608.     my @parentdir = split(/::/, $self->{PARENT_NAME});
  609.     push @m, q{
  610. # Where to put things:
  611. INST_LIBDIR      = }. $self->catdir('$(INST_LIB)',@parentdir)        .q{
  612. INST_ARCHLIBDIR  = }. $self->catdir('$(INST_ARCHLIB)',@parentdir)    .q{
  613.  
  614. INST_AUTODIR     = }. $self->catdir('$(INST_LIB)','auto','$(FULLEXT)')       .q{
  615. INST_ARCHAUTODIR = }. $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)')   .q{
  616. };
  617.  
  618.     if ($self->has_link_code()) {
  619.     push @m, '
  620. INST_STATIC  = $(INST_ARCHAUTODIR)/$(BASEEXT)$(LIB_EXT)
  621. INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(DLBASE).$(DLEXT)
  622. INST_BOOT    = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
  623. ';
  624.     } else {
  625.     push @m, '
  626. INST_STATIC  =
  627. INST_DYNAMIC =
  628. INST_BOOT    =
  629. ';
  630.     }
  631.  
  632.     $tmp = $self->export_list;
  633.     push @m, "
  634. EXPORT_LIST = $tmp
  635. ";
  636.     $tmp = $self->perl_archive;
  637.     push @m, "
  638. PERL_ARCHIVE = $tmp
  639. ";
  640.  
  641. #    push @m, q{
  642. #INST_PM = }.join(" \\\n\t", sort values %{$self->{PM}}).q{
  643. #
  644. #PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
  645. #};
  646.  
  647.     push @m, q{
  648. TO_INST_PM = }.join(" \\\n\t", sort keys %{$self->{PM}}).q{
  649.  
  650. PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
  651. };
  652.  
  653.     join('',@m);
  654. }
  655.  
  656. =item depend (o)
  657.  
  658. Same as macro for the depend attribute.
  659.  
  660. =cut
  661.  
  662. sub depend {
  663.     my($self,%attribs) = @_;
  664.     my(@m,$key,$val);
  665.     while (($key,$val) = each %attribs){
  666.     last unless defined $key;
  667.     push @m, "$key: $val\n";
  668.     }
  669.     join "", @m;
  670. }
  671.  
  672. =item dir_target (o)
  673.  
  674. Takes an array of directories that need to exist and returns a
  675. Makefile entry for a .exists file in these directories. Returns
  676. nothing, if the entry has already been processed. We're helpless
  677. though, if the same directory comes as $(FOO) _and_ as "bar". Both of
  678. them get an entry, that's why we use "::".
  679.  
  680. =cut
  681.  
  682. sub dir_target {
  683. # --- Make-Directories section (internal method) ---
  684. # dir_target(@array) returns a Makefile entry for the file .exists in each
  685. # named directory. Returns nothing, if the entry has already been processed.
  686. # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
  687. # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the
  688. # prerequisite, because there has to be one, something that doesn't change
  689. # too often :)
  690.  
  691.     my($self,@dirs) = @_;
  692.     my(@m,$dir,$targdir);
  693.     foreach $dir (@dirs) {
  694.     my($src) = $self->catfile($self->{PERL_INC},'perl.h');
  695.     my($targ) = $self->catfile($dir,'.exists');
  696.     # catfile may have adapted syntax of $dir to target OS, so...
  697.     if ($Is_VMS) { # Just remove file name; dirspec is often in macro
  698.         ($targdir = $targ) =~ s:/?\.exists$::;
  699.     }
  700.     else { # while elsewhere we expect to see the dir separator in $targ
  701.         $targdir = dirname($targ);
  702.     }
  703.     next if $self->{DIR_TARGET}{$self}{$targdir}++;
  704.     push @m, qq{
  705. $targ :: $src
  706.     $self->{NOECHO}\$(MKPATH) $targdir
  707.     $self->{NOECHO}\$(EQUALIZE_TIMESTAMP) $src $targ
  708. };
  709.     push(@m, qq{
  710.     -$self->{NOECHO}\$(CHMOD) \$(PERM_RWX) $targdir
  711. }) unless $Is_VMS;
  712.     }
  713.     join "", @m;
  714. }
  715.  
  716. =item dist (o)
  717.  
  718. Defines a lot of macros for distribution support.
  719.  
  720. =cut
  721.  
  722. sub dist {
  723.     my($self, %attribs) = @_;
  724.  
  725.     my(@m);
  726.     # VERSION should be sanitised before use as a file name
  727.     my($version)  = $attribs{VERSION}  || '$(VERSION)';
  728.     my($name)     = $attribs{NAME}     || '$(DISTNAME)';
  729.     my($tar)      = $attribs{TAR}      || 'tar';        # eg /usr/bin/gnutar
  730.     my($tarflags) = $attribs{TARFLAGS} || 'cvf';
  731.     my($zip)      = $attribs{ZIP}      || 'zip';        # eg pkzip Yuck!
  732.     my($zipflags) = $attribs{ZIPFLAGS} || '-r';
  733.     my($compress) = $attribs{COMPRESS} || 'gzip --best';
  734.     my($suffix)   = $attribs{SUFFIX}   || '.gz';          # eg .gz
  735.     my($shar)     = $attribs{SHAR}     || 'shar';       # eg "shar --gzip"
  736.     my($preop)    = $attribs{PREOP}    || "$self->{NOECHO}\$(NOOP)"; # eg update MANIFEST
  737.     my($postop)   = $attribs{POSTOP}   || "$self->{NOECHO}\$(NOOP)"; # eg remove the distdir
  738.  
  739.     my($to_unix)  = $attribs{TO_UNIX} || ($Is_OS2
  740.                       ? "$self->{NOECHO}"
  741.                       . '$(TEST_F) tmp.zip && $(RM) tmp.zip;'
  742.                       . ' $(ZIP) -ll -mr tmp.zip $(DISTVNAME) && unzip -o tmp.zip && $(RM) tmp.zip'
  743.                       : "$self->{NOECHO}\$(NOOP)");
  744.  
  745.     my($ci)       = $attribs{CI}       || 'ci -u';
  746.     my($rcs_label)= $attribs{RCS_LABEL}|| 'rcs -Nv$(VERSION_SYM): -q';
  747.     my($dist_cp)  = $attribs{DIST_CP}  || 'best';
  748.     my($dist_default) = $attribs{DIST_DEFAULT} || 'tardist';
  749.  
  750.     push @m, "
  751. DISTVNAME = ${name}-$version
  752. TAR  = $tar
  753. TARFLAGS = $tarflags
  754. ZIP  = $zip
  755. ZIPFLAGS = $zipflags
  756. COMPRESS = $compress
  757. SUFFIX = $suffix
  758. SHAR = $shar
  759. PREOP = $preop
  760. POSTOP = $postop
  761. TO_UNIX = $to_unix
  762. CI = $ci
  763. RCS_LABEL = $rcs_label
  764. DIST_CP = $dist_cp
  765. DIST_DEFAULT = $dist_default
  766. ";
  767.     join "", @m;
  768. }
  769.  
  770. =item dist_basics (o)
  771.  
  772. Defines the targets distclean, distcheck, skipcheck, manifest.
  773.  
  774. =cut
  775.  
  776. sub dist_basics {
  777.     my($self) = shift;
  778.     my @m;
  779.     push @m, q{
  780. distclean :: realclean distcheck
  781. };
  782.  
  783.     push @m, q{
  784. distcheck :
  785.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=fullcheck \\
  786.         -e fullcheck
  787. };
  788.  
  789.     push @m, q{
  790. skipcheck :
  791.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=skipcheck \\
  792.         -e skipcheck
  793. };
  794.  
  795.     push @m, q{
  796. manifest :
  797.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=mkmanifest \\
  798.         -e mkmanifest
  799. };
  800.     join "", @m;
  801. }
  802.  
  803. =item dist_ci (o)
  804.  
  805. Defines a check in target for RCS.
  806.  
  807. =cut
  808.  
  809. sub dist_ci {
  810.     my($self) = shift;
  811.     my @m;
  812.     push @m, q{
  813. ci :
  814.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=maniread \\
  815.         -e "@all = keys %{ maniread() };" \\
  816.         -e 'print("Executing $(CI) @all\n"); system("$(CI) @all");' \\
  817.         -e 'print("Executing $(RCS_LABEL) ...\n"); system("$(RCS_LABEL) @all");'
  818. };
  819.     join "", @m;
  820. }
  821.  
  822. =item dist_core (o)
  823.  
  824. Defines the targets dist, tardist, zipdist, uutardist, shdist
  825.  
  826. =cut
  827.  
  828. sub dist_core {
  829.     my($self) = shift;
  830.     my @m;
  831.     push @m, q{
  832. dist : $(DIST_DEFAULT)
  833.     }.$self->{NOECHO}.q{$(PERL) -le 'print "Warning: Makefile possibly out of date with $$vf" if ' \
  834.         -e '-e ($$vf="$(VERSION_FROM)") and -M $$vf < -M "}.$self->{MAKEFILE}.q{";'
  835.  
  836. tardist : $(DISTVNAME).tar$(SUFFIX)
  837.  
  838. zipdist : $(DISTVNAME).zip
  839.  
  840. $(DISTVNAME).tar$(SUFFIX) : distdir
  841.     $(PREOP)
  842.     $(TO_UNIX)
  843.     $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
  844.     $(RM_RF) $(DISTVNAME)
  845.     $(COMPRESS) $(DISTVNAME).tar
  846.     $(POSTOP)
  847.  
  848. $(DISTVNAME).zip : distdir
  849.     $(PREOP)
  850.     $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
  851.     $(RM_RF) $(DISTVNAME)
  852.     $(POSTOP)
  853.  
  854. uutardist : $(DISTVNAME).tar$(SUFFIX)
  855.     uuencode $(DISTVNAME).tar$(SUFFIX) \\
  856.         $(DISTVNAME).tar$(SUFFIX) > \\
  857.         $(DISTVNAME).tar$(SUFFIX)_uu
  858.  
  859. shdist : distdir
  860.     $(PREOP)
  861.     $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
  862.     $(RM_RF) $(DISTVNAME)
  863.     $(POSTOP)
  864. };
  865.     join "", @m;
  866. }
  867.  
  868. =item dist_dir (o)
  869.  
  870. Defines the scratch directory target that will hold the distribution
  871. before tar-ing (or shar-ing).
  872.  
  873. =cut
  874.  
  875. sub dist_dir {
  876.     my($self) = shift;
  877.     my @m;
  878.     push @m, q{
  879. distdir :
  880.     $(RM_RF) $(DISTVNAME)
  881.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=manicopy,maniread \\
  882.         -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
  883. };
  884.     join "", @m;
  885. }
  886.  
  887. =item dist_test (o)
  888.  
  889. Defines a target that produces the distribution in the
  890. scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
  891. subdirectory.
  892.  
  893. =cut
  894.  
  895. sub dist_test {
  896.     my($self) = shift;
  897.     my @m;
  898.     push @m, q{
  899. disttest : distdir
  900.     cd $(DISTVNAME) && $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) Makefile.PL
  901.     cd $(DISTVNAME) && $(MAKE)
  902.     cd $(DISTVNAME) && $(MAKE) test
  903. };
  904.     join "", @m;
  905. }
  906.  
  907. =item dlsyms (o)
  908.  
  909. Used by AIX and VMS to define DL_FUNCS and DL_VARS and write the *.exp
  910. files.
  911.  
  912. =cut
  913.  
  914. sub dlsyms {
  915.     my($self,%attribs) = @_;
  916.  
  917.     return '' unless ($^O eq 'aix' && $self->needs_linking() );
  918.  
  919.     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
  920.     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
  921.     my($funclist)  = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
  922.     my(@m);
  923.  
  924.     push(@m,"
  925. dynamic :: $self->{BASEEXT}.exp
  926.  
  927. ") unless $self->{SKIPHASH}{'dynamic'}; # dynamic and static are subs, so...
  928.  
  929.     push(@m,"
  930. static :: $self->{BASEEXT}.exp
  931.  
  932. ") unless $self->{SKIPHASH}{'static'};  # we avoid a warning if we tick them
  933.  
  934.     push(@m,"
  935. $self->{BASEEXT}.exp: Makefile.PL
  936. ",'    $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e \'use ExtUtils::Mksymlists; \\
  937.     Mksymlists("NAME" => "',$self->{NAME},'", "DL_FUNCS" => ',
  938.     neatvalue($funcs), ', "FUNCLIST" => ', neatvalue($funclist),
  939.     ', "DL_VARS" => ', neatvalue($vars), ');\'
  940. ');
  941.  
  942.     join('',@m);
  943. }
  944.  
  945. =item dynamic (o)
  946.  
  947. Defines the dynamic target.
  948.  
  949. =cut
  950.  
  951. sub dynamic {
  952. # --- Dynamic Loading Sections ---
  953.  
  954.     my($self) = shift;
  955.     '
  956. ## $(INST_PM) has been moved to the all: target.
  957. ## It remains here for awhile to allow for old usage: "make dynamic"
  958. #dynamic :: '.$self->{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
  959. dynamic :: '.$self->{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT)
  960.     '.$self->{NOECHO}.'$(NOOP)
  961. ';
  962. }
  963.  
  964. =item dynamic_bs (o)
  965.  
  966. Defines targets for bootstrap files.
  967.  
  968. =cut
  969.  
  970. sub dynamic_bs {
  971.     my($self, %attribs) = @_;
  972.     return '
  973. BOOTSTRAP =
  974. ' unless $self->has_link_code();
  975.  
  976.     return '
  977. BOOTSTRAP = '."$self->{BASEEXT}.bs".'
  978.  
  979. # As Mkbootstrap might not write a file (if none is required)
  980. # we use touch to prevent make continually trying to remake it.
  981. # The DynaLoader only reads a non-empty file.
  982. $(BOOTSTRAP): '."$self->{MAKEFILE} $self->{BOOTDEP}".' $(INST_ARCHAUTODIR)/.exists
  983.     '.$self->{NOECHO}.'echo "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
  984.     '.$self->{NOECHO}.'$(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
  985.         -MExtUtils::Mkbootstrap \
  986.         -e "Mkbootstrap(\'$(BASEEXT)\',\'$(BSLOADLIBS)\');"
  987.     '.$self->{NOECHO}.'$(TOUCH) $(BOOTSTRAP)
  988.     $(CHMOD) $(PERM_RW) $@
  989.  
  990. $(INST_BOOT): $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists
  991.     '."$self->{NOECHO}$self->{RM_RF}".' $(INST_BOOT)
  992.     -'.$self->{CP}.' $(BOOTSTRAP) $(INST_BOOT)
  993.     $(CHMOD) $(PERM_RW) $@
  994. ';
  995. }
  996.  
  997. =item dynamic_lib (o)
  998.  
  999. Defines how to produce the *.so (or equivalent) files.
  1000.  
  1001. =cut
  1002.  
  1003. sub dynamic_lib {
  1004.     my($self, %attribs) = @_;
  1005.     return '' unless $self->needs_linking(); #might be because of a subdir
  1006.  
  1007.     return '' unless $self->has_link_code;
  1008.  
  1009.     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
  1010.     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
  1011.     my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
  1012.     my($ldfrom) = '$(LDFROM)';
  1013.     $armaybe = 'ar' if ($^O eq 'dec_osf' and $armaybe eq ':');
  1014.     my(@m);
  1015.     push(@m,'
  1016. # This section creates the dynamically loadable $(INST_DYNAMIC)
  1017. # from $(OBJECT) and possibly $(MYEXTLIB).
  1018. ARMAYBE = '.$armaybe.'
  1019. OTHERLDFLAGS = '.$otherldflags.'
  1020. INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
  1021.  
  1022. $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
  1023. ');
  1024.     if ($armaybe ne ':'){
  1025.     $ldfrom = 'tmp$(LIB_EXT)';
  1026.     push(@m,'    $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
  1027.     push(@m,'    $(RANLIB) '."$ldfrom\n");
  1028.     }
  1029.     $ldfrom = "-all $ldfrom -none" if ($^O eq 'dec_osf');
  1030.  
  1031.     # Brain dead solaris linker does not use LD_RUN_PATH?
  1032.     # This fixes dynamic extensions which need shared libs
  1033.     my $ldrun = '';
  1034.     $ldrun = join ' ', map "-R$_", split /:/, $self->{LD_RUN_PATH}
  1035.        if ($^O eq 'solaris');
  1036.  
  1037.     # The IRIX linker also doesn't use LD_RUN_PATH
  1038.     $ldrun = qq{-rpath "$self->{LD_RUN_PATH}"}
  1039.     if ($^O eq 'irix' && $self->{LD_RUN_PATH});
  1040.  
  1041.     push(@m,'    LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) -o $@ '.$ldrun.' $(LDDLFLAGS) '.$ldfrom.
  1042.         ' $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) $(EXPORT_LIST)');
  1043.     push @m, '
  1044.     $(CHMOD) $(PERM_RWX) $@
  1045. ';
  1046.  
  1047.     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
  1048.     join('',@m);
  1049. }
  1050.  
  1051. =item exescan
  1052.  
  1053. Deprecated method. Use libscan instead.
  1054.  
  1055. =cut
  1056.  
  1057. sub exescan {
  1058.     my($self,$path) = @_;
  1059.     $path;
  1060. }
  1061.  
  1062. =item extliblist
  1063.  
  1064. Called by init_others, and calls ext ExtUtils::Liblist. See
  1065. L<ExtUtils::Liblist> for details.
  1066.  
  1067. =cut
  1068.  
  1069. sub extliblist {
  1070.     my($self,$libs) = @_;
  1071.     require ExtUtils::Liblist;
  1072.     $self->ext($libs, $Verbose);
  1073. }
  1074.  
  1075. =item file_name_is_absolute
  1076.  
  1077. Takes as argument a path and returns true, if it is an absolute path.
  1078.  
  1079. =cut
  1080.  
  1081. sub file_name_is_absolute {
  1082.     my($self,$file) = @_;
  1083.     if ($Is_Dos){
  1084.         $file =~ m{^([a-z]:)?[\\/]}i ;
  1085.     }
  1086.     else {
  1087.         $file =~ m:^/: ;
  1088.     }
  1089. }
  1090.  
  1091. =item find_perl
  1092.  
  1093. Finds the executables PERL and FULLPERL
  1094.  
  1095. =cut
  1096.  
  1097. sub find_perl {
  1098.     my($self, $ver, $names, $dirs, $trace) = @_;
  1099.     my($name, $dir);
  1100.     if ($trace >= 2){
  1101.     print "Looking for perl $ver by these names:
  1102. @$names
  1103. in these dirs:
  1104. @$dirs
  1105. ";
  1106.     }
  1107.     foreach $dir (@$dirs){
  1108.     next unless defined $dir; # $self->{PERL_SRC} may be undefined
  1109.     foreach $name (@$names){
  1110.         my ($abs, $val);
  1111.         if ($self->file_name_is_absolute($name)) { # /foo/bar
  1112.         $abs = $name;
  1113.         } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # foo
  1114.         $abs = $self->catfile($dir, $name);
  1115.         } else { # foo/bar
  1116.         $abs = $self->canonpath($self->catfile($self->curdir, $name));
  1117.         }
  1118.         print "Checking $abs\n" if ($trace >= 2);
  1119.         next unless $self->maybe_command($abs);
  1120.         print "Executing $abs\n" if ($trace >= 2);
  1121.         $val = `$abs -e 'require $ver; print "VER_OK\\n" ' 2>&1`;
  1122.         if ($val =~ /VER_OK/) {
  1123.             print "Using PERL=$abs\n" if $trace;
  1124.             return $abs;
  1125.         } elsif ($trace >= 2) {
  1126.         print "Result: `$val'\n";
  1127.         }
  1128.     }
  1129.     }
  1130.     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
  1131.     0; # false and not empty
  1132. }
  1133.  
  1134. =back
  1135.  
  1136. =head2 Methods to actually produce chunks of text for the Makefile
  1137.  
  1138. The methods here are called for each MakeMaker object in the order
  1139. specified by @ExtUtils::MakeMaker::MM_Sections.
  1140.  
  1141. =over 2
  1142.  
  1143. =item fixin
  1144.  
  1145. Inserts the sharpbang or equivalent magic number to a script
  1146.  
  1147. =cut
  1148.  
  1149. sub fixin { # stolen from the pink Camel book, more or less
  1150.     my($self,@files) = @_;
  1151.     my($does_shbang) = $Config::Config{'sharpbang'} =~ /^\s*\#\!/;
  1152.     my($file,$interpreter);
  1153.     for $file (@files) {
  1154.     local(*FIXIN);
  1155.     local(*FIXOUT);
  1156.     open(FIXIN, $file) or Carp::croak "Can't process '$file': $!";
  1157.     local $/ = "\n";
  1158.     chomp(my $line = <FIXIN>);
  1159.     next unless $line =~ s/^\s*\#!\s*//;     # Not a shbang file.
  1160.     # Now figure out the interpreter name.
  1161.     my($cmd,$arg) = split ' ', $line, 2;
  1162.     $cmd =~ s!^.*/!!;
  1163.  
  1164.     # Now look (in reverse) for interpreter in absolute PATH (unless perl).
  1165.     if ($cmd eq "perl") {
  1166.             if ($Config{startperl} =~ m,^\#!.*/perl,) {
  1167.                 $interpreter = $Config{startperl};
  1168.                 $interpreter =~ s,^\#!,,;
  1169.             } else {
  1170.                 $interpreter = $Config{perlpath};
  1171.             }
  1172.     } else {
  1173.         my(@absdirs) = reverse grep {$self->file_name_is_absolute} $self->path;
  1174.         $interpreter = '';
  1175.         my($dir);
  1176.         foreach $dir (@absdirs) {
  1177.         if ($self->maybe_command($cmd)) {
  1178.             warn "Ignoring $interpreter in $file\n" if $Verbose && $interpreter;
  1179.             $interpreter = $self->catfile($dir,$cmd);
  1180.         }
  1181.         }
  1182.     }
  1183.     # Figure out how to invoke interpreter on this machine.
  1184.  
  1185.     my($shb) = "";
  1186.     if ($interpreter) {
  1187.         print STDOUT "Changing sharpbang in $file to $interpreter" if $Verbose;
  1188.         # this is probably value-free on DOSISH platforms
  1189.         if ($does_shbang) {
  1190.         $shb .= "$Config{'sharpbang'}$interpreter";
  1191.         $shb .= ' ' . $arg if defined $arg;
  1192.         $shb .= "\n";
  1193.         }
  1194.         $shb .= qq{
  1195. eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
  1196.     if 0; # not running under some shell
  1197. } unless $Is_Win32; # this won't work on win32, so don't
  1198.     } else {
  1199.         warn "Can't find $cmd in PATH, $file unchanged"
  1200.         if $Verbose;
  1201.         next;
  1202.     }
  1203.  
  1204.     unless ( open(FIXOUT,">$file.new") ) {
  1205.         warn "Can't create new $file: $!\n";
  1206.         next;
  1207.     }
  1208.     my($dev,$ino,$mode) = stat FIXIN;
  1209.     # If they override perm_rwx, we won't notice it during fixin,
  1210.     # because fixin is run through a new instance of MakeMaker.
  1211.     # That is why we must run another CHMOD later.
  1212.     $mode = oct($self->perm_rwx) unless $dev;
  1213.     chmod $mode, $file;
  1214.     
  1215.     # Print out the new #! line (or equivalent).
  1216.     local $\;
  1217.     undef $/;
  1218.     print FIXOUT $shb, <FIXIN>;
  1219.     close FIXIN;
  1220.     close FIXOUT;
  1221.     # can't rename open files on some DOSISH platforms
  1222.     unless ( rename($file, "$file.bak") ) {    
  1223.         warn "Can't rename $file to $file.bak: $!";
  1224.         next;
  1225.     }
  1226.     unless ( rename("$file.new", $file) ) {    
  1227.         warn "Can't rename $file.new to $file: $!";
  1228.         unless ( rename("$file.bak", $file) ) {
  1229.             warn "Can't rename $file.bak back to $file either: $!";
  1230.         warn "Leaving $file renamed as $file.bak\n";
  1231.         }
  1232.         next;
  1233.     }
  1234.     unlink "$file.bak";
  1235.     } continue {
  1236.     chmod oct($self->perm_rwx), $file or
  1237.       die "Can't reset permissions for $file: $!\n";
  1238.     system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';;
  1239.     }
  1240. }
  1241.  
  1242. =item force (o)
  1243.  
  1244. Just writes FORCE:
  1245.  
  1246. =cut
  1247.  
  1248. sub force {
  1249.     my($self) = shift;
  1250.     '# Phony target to force checking subdirectories.
  1251. FORCE:
  1252.     '.$self->{NOECHO}.'$(NOOP)
  1253. ';
  1254. }
  1255.  
  1256. =item guess_name
  1257.  
  1258. Guess the name of this package by examining the working directory's
  1259. name. MakeMaker calls this only if the developer has not supplied a
  1260. NAME attribute.
  1261.  
  1262. =cut
  1263.  
  1264. # ';
  1265.  
  1266. sub guess_name {
  1267.     my($self) = @_;
  1268.     use Cwd 'cwd';
  1269.     my $name = basename(cwd());
  1270.     $name =~ s|[\-_][\d\.\-]+$||;   # this is new with MM 5.00, we
  1271.                                     # strip minus or underline
  1272.                                     # followed by a float or some such
  1273.     print "Warning: Guessing NAME [$name] from current directory name.\n";
  1274.     $name;
  1275. }
  1276.  
  1277. =item has_link_code
  1278.  
  1279. Returns true if C, XS, MYEXTLIB or similar objects exist within this
  1280. object that need a compiler. Does not descend into subdirectories as
  1281. needs_linking() does.
  1282.  
  1283. =cut
  1284.  
  1285. sub has_link_code {
  1286.     my($self) = shift;
  1287.     return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
  1288.     if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
  1289.     $self->{HAS_LINK_CODE} = 1;
  1290.     return 1;
  1291.     }
  1292.     return $self->{HAS_LINK_CODE} = 0;
  1293. }
  1294.  
  1295. =item init_dirscan
  1296.  
  1297. Initializes DIR, XS, PM, C, O_FILES, H, PL_FILES, MAN*PODS, EXE_FILES.
  1298.  
  1299. =cut
  1300.  
  1301. sub init_dirscan {    # --- File and Directory Lists (.xs .pm .pod etc)
  1302.     my($self) = @_;
  1303.     my($name, %dir, %xs, %c, %h, %ignore, %pl_files, %manifypods);
  1304.     local(%pm); #the sub in find() has to see this hash
  1305.     @ignore{qw(Makefile.PL test.pl)} = (1,1);
  1306.     $ignore{'makefile.pl'} = 1 if $Is_VMS;
  1307.     foreach $name ($self->lsdir($self->curdir)){
  1308.     next if $name =~ /\#/;
  1309.     next if $name eq $self->curdir or $name eq $self->updir or $ignore{$name};
  1310.     next unless $self->libscan($name);
  1311.     if (-d $name){
  1312.         next if -l $name; # We do not support symlinks at all
  1313.         $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
  1314.     } elsif ($name =~ /\.xs$/){
  1315.         my($c); ($c = $name) =~ s/\.xs$/.c/;
  1316.         $xs{$name} = $c;
  1317.         $c{$c} = 1;
  1318.     } elsif ($name =~ /\.c(pp|xx|c)?$/i){  # .c .C .cpp .cxx .cc
  1319.         $c{$name} = 1
  1320.         unless $name =~ m/perlmain\.c/; # See MAP_TARGET
  1321.     } elsif ($name =~ /\.h$/i){
  1322.         $h{$name} = 1;
  1323.     } elsif ($name =~ /\.PL$/) {
  1324.         ($pl_files{$name} = $name) =~ s/\.PL$// ;
  1325.     } elsif ($Is_VMS && $name =~ /\.pl$/) {  # case-insensitive filesystem
  1326.         local($/); open(PL,$name); my $txt = <PL>; close PL;
  1327.         if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
  1328.         ($pl_files{$name} = $name) =~ s/\.pl$// ;
  1329.         }
  1330.         else { $pm{$name} = $self->catfile('$(INST_LIBDIR)',$name); }
  1331.     } elsif ($name =~ /\.(p[ml]|pod)$/){
  1332.         $pm{$name} = $self->catfile('$(INST_LIBDIR)',$name);
  1333.     }
  1334.     }
  1335.  
  1336.     # Some larger extensions often wish to install a number of *.pm/pl
  1337.     # files into the library in various locations.
  1338.  
  1339.     # The attribute PMLIBDIRS holds an array reference which lists
  1340.     # subdirectories which we should search for library files to
  1341.     # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
  1342.     # recursively search through the named directories (skipping any
  1343.     # which don't exist or contain Makefile.PL files).
  1344.  
  1345.     # For each *.pm or *.pl file found $self->libscan() is called with
  1346.     # the default installation path in $_[1]. The return value of
  1347.     # libscan defines the actual installation location.  The default
  1348.     # libscan function simply returns the path.  The file is skipped
  1349.     # if libscan returns false.
  1350.  
  1351.     # The default installation location passed to libscan in $_[1] is:
  1352.     #
  1353.     #  ./*.pm        => $(INST_LIBDIR)/*.pm
  1354.     #  ./xyz/...    => $(INST_LIBDIR)/xyz/...
  1355.     #  ./lib/...    => $(INST_LIB)/...
  1356.     #
  1357.     # In this way the 'lib' directory is seen as the root of the actual
  1358.     # perl library whereas the others are relative to INST_LIBDIR
  1359.     # (which includes PARENT_NAME). This is a subtle distinction but one
  1360.     # that's important for nested modules.
  1361.  
  1362.     $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}]
  1363.     unless $self->{PMLIBDIRS};
  1364.  
  1365.     #only existing directories that aren't in $dir are allowed
  1366.  
  1367.     # Avoid $_ wherever possible:
  1368.     # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
  1369.     my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
  1370.     my ($pmlibdir);
  1371.     @{$self->{PMLIBDIRS}} = ();
  1372.     foreach $pmlibdir (@pmlibdirs) {
  1373.     -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
  1374.     }
  1375.  
  1376.     if (@{$self->{PMLIBDIRS}}){
  1377.     print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
  1378.         if ($Verbose >= 2);
  1379.     require File::Find;
  1380.     File::Find::find(sub {
  1381.         if (-d $_){
  1382.         if ($_ eq "CVS" || $_ eq "RCS"){
  1383.             $File::Find::prune = 1;
  1384.         }
  1385.         return;
  1386.         }
  1387.         return if /\#/;
  1388.         my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
  1389.         my($striplibpath,$striplibname);
  1390.         $prefix =  '$(INST_LIB)' if (($striplibpath = $path) =~ s:^(\W*)lib\W:$1:i);
  1391.         ($striplibname,$striplibpath) = fileparse($striplibpath);
  1392.         my($inst) = $self->catfile($prefix,$striplibpath,$striplibname);
  1393.         local($_) = $inst; # for backwards compatibility
  1394.         $inst = $self->libscan($inst);
  1395.         print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
  1396.         return unless $inst;
  1397.         $pm{$path} = $inst;
  1398.     }, @{$self->{PMLIBDIRS}});
  1399.     }
  1400.  
  1401.     $self->{DIR} = [sort keys %dir] unless $self->{DIR};
  1402.     $self->{XS}  = \%xs             unless $self->{XS};
  1403.     $self->{PM}  = \%pm             unless $self->{PM};
  1404.     $self->{C}   = [sort keys %c]   unless $self->{C};
  1405.     my(@o_files) = @{$self->{C}};
  1406.     $self->{O_FILES} = [grep s/\.c(pp|xx|c)?$/$self->{OBJ_EXT}/i, @o_files] ;
  1407.     $self->{H}   = [sort keys %h]   unless $self->{H};
  1408.     $self->{PL_FILES} = \%pl_files unless $self->{PL_FILES};
  1409.  
  1410.     # Set up names of manual pages to generate from pods
  1411.     if ($self->{MAN1PODS}) {
  1412.     } elsif ( $self->{INST_MAN1DIR} =~ /^(none|\s*)$/ ) {
  1413.         $self->{MAN1PODS} = {};
  1414.     } else {
  1415.     my %manifypods = ();
  1416.     if ( exists $self->{EXE_FILES} ) {
  1417.         foreach $name (@{$self->{EXE_FILES}}) {
  1418. #        use FileHandle ();
  1419. #        my $fh = new FileHandle;
  1420.         local *FH;
  1421.         my($ispod)=0;
  1422. #        if ($fh->open("<$name")) {
  1423.         if (open(FH,"<$name")) {
  1424. #            while (<$fh>) {
  1425.             while (<FH>) {
  1426.             if (/^=head1\s+\w+/) {
  1427.                 $ispod=1;
  1428.                 last;
  1429.             }
  1430.             }
  1431. #            $fh->close;
  1432.             close FH;
  1433.         } else {
  1434.             # If it doesn't exist yet, we assume, it has pods in it
  1435.             $ispod = 1;
  1436.         }
  1437.         if( $ispod ) {
  1438.             $manifypods{$name} =
  1439.             $self->catfile('$(INST_MAN1DIR)',
  1440.                        basename($name).'.$(MAN1EXT)');
  1441.         }
  1442.         }
  1443.     }
  1444.     $self->{MAN1PODS} = \%manifypods;
  1445.     }
  1446.     if ($self->{MAN3PODS}) {
  1447.     } elsif ( $self->{INST_MAN3DIR} =~ /^(none|\s*)$/ ) {
  1448.         $self->{MAN3PODS} = {};
  1449.     } else {
  1450.     my %manifypods = (); # we collect the keys first, i.e. the files
  1451.                  # we have to convert to pod
  1452.     foreach $name (keys %{$self->{PM}}) {
  1453.         if ($name =~ /\.pod$/ ) {
  1454.         $manifypods{$name} = $self->{PM}{$name};
  1455.         } elsif ($name =~ /\.p[ml]$/ ) {
  1456. #        use FileHandle ();
  1457. #        my $fh = new FileHandle;
  1458.         local *FH;
  1459.         my($ispod)=0;
  1460. #        $fh->open("<$name");
  1461.         if (open(FH,"<$name")) {
  1462.             #        while (<$fh>) {
  1463.             while (<FH>) {
  1464.             if (/^=head1\s+\w+/) {
  1465.                 $ispod=1;
  1466.                 last;
  1467.             }
  1468.             }
  1469.             #        $fh->close;
  1470.             close FH;
  1471.         } else {
  1472.             $ispod = 1;
  1473.         }
  1474.         if( $ispod ) {
  1475.             $manifypods{$name} = $self->{PM}{$name};
  1476.         }
  1477.         }
  1478.     }
  1479.  
  1480.     # Remove "Configure.pm" and similar, if it's not the only pod listed
  1481.     # To force inclusion, just name it "Configure.pod", or override MAN3PODS
  1482.     foreach $name (keys %manifypods) {
  1483.         if ($name =~ /(config|setup).*\.pm/i) {
  1484.         delete $manifypods{$name};
  1485.         next;
  1486.         }
  1487.         my($manpagename) = $name;
  1488.         unless ($manpagename =~ s!^\W*lib\W+!!) { # everything below lib is ok
  1489.         $manpagename = $self->catfile(split(/::/,$self->{PARENT_NAME}),$manpagename);
  1490.         }
  1491.         $manpagename =~ s/\.p(od|m|l)$//;
  1492.         $manpagename = $self->replace_manpage_separator($manpagename);
  1493.         $manifypods{$name} = $self->catfile("\$(INST_MAN3DIR)","$manpagename.\$(MAN3EXT)");
  1494.     }
  1495.     $self->{MAN3PODS} = \%manifypods;
  1496.     }
  1497. }
  1498.  
  1499. =item init_main
  1500.  
  1501. Initializes NAME, FULLEXT, BASEEXT, PARENT_NAME, DLBASE, PERL_SRC,
  1502. PERL_LIB, PERL_ARCHLIB, PERL_INC, INSTALLDIRS, INST_*, INSTALL*,
  1503. PREFIX, CONFIG, AR, AR_STATIC_ARGS, LD, OBJ_EXT, LIB_EXT, EXE_EXT, MAP_TARGET,
  1504. LIBPERL_A, VERSION_FROM, VERSION, DISTNAME, VERSION_SYM.
  1505.  
  1506. =cut
  1507.  
  1508. sub init_main {
  1509.     my($self) = @_;
  1510.  
  1511.     # --- Initialize Module Name and Paths
  1512.  
  1513.     # NAME    = Foo::Bar::Oracle
  1514.     # FULLEXT = Foo/Bar/Oracle
  1515.     # BASEEXT = Oracle
  1516.     # ROOTEXT = Directory part of FULLEXT with leading /. !!! Deprecated from MM 5.32 !!!
  1517.     # PARENT_NAME = Foo::Bar
  1518. ### Only UNIX:
  1519. ###    ($self->{FULLEXT} =
  1520. ###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
  1521.     $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
  1522.  
  1523.  
  1524.     # Copied from DynaLoader:
  1525.  
  1526.     my(@modparts) = split(/::/,$self->{NAME});
  1527.     my($modfname) = $modparts[-1];
  1528.  
  1529.     # Some systems have restrictions on files names for DLL's etc.
  1530.     # mod2fname returns appropriate file base name (typically truncated)
  1531.     # It may also edit @modparts if required.
  1532.     if (defined &DynaLoader::mod2fname) {
  1533.         $modfname = &DynaLoader::mod2fname(\@modparts);
  1534.     }
  1535.  
  1536.     ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)$! ;
  1537.  
  1538.     if (defined &DynaLoader::mod2fname) {
  1539.     # As of 5.001m, dl_os2 appends '_'
  1540.     $self->{DLBASE} = $modfname;
  1541.     } else {
  1542.     $self->{DLBASE} = '$(BASEEXT)';
  1543.     }
  1544.  
  1545.  
  1546.     ### ROOTEXT deprecated from MM 5.32
  1547. ###    ($self->{ROOTEXT} =
  1548. ###     $self->{FULLEXT}) =~ s#/?\Q$self->{BASEEXT}\E$## ;      #eg. /BSD/Foo
  1549. ###    $self->{ROOTEXT} = ($Is_VMS ? '' : '/') . $self->{ROOTEXT} if $self->{ROOTEXT};
  1550.  
  1551.  
  1552.     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
  1553.  
  1554.     # *Real* information: where did we get these two from? ...
  1555.     my $inc_config_dir = dirname($INC{'Config.pm'});
  1556.     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
  1557.  
  1558.     unless ($self->{PERL_SRC}){
  1559.     my($dir);
  1560.     foreach $dir ($self->updir(),$self->catdir($self->updir(),$self->updir()),$self->catdir($self->updir(),$self->updir(),$self->updir())){
  1561.         if (
  1562.         -f $self->catfile($dir,"config.sh")
  1563.         &&
  1564.         -f $self->catfile($dir,"perl.h")
  1565.         &&
  1566.         -f $self->catfile($dir,"lib","Exporter.pm")
  1567.            ) {
  1568.         $self->{PERL_SRC}=$dir ;
  1569.         last;
  1570.         }
  1571.     }
  1572.     }
  1573.     if ($self->{PERL_SRC}){
  1574.     $self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
  1575.     $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
  1576.     $self->{PERL_INC}     = ($Is_Win32) ? $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
  1577.  
  1578.     # catch a situation that has occurred a few times in the past:
  1579.     unless (
  1580.         -s $self->catfile($self->{PERL_SRC},'cflags')
  1581.         or
  1582.         $Is_VMS
  1583.         &&
  1584.         -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
  1585.         or
  1586.         $Is_Mac
  1587.         or
  1588.         $Is_Win32
  1589.         or
  1590.         $Is_RISCOS
  1591.            ){
  1592.         warn qq{
  1593. You cannot build extensions below the perl source tree after executing
  1594. a 'make clean' in the perl source tree.
  1595.  
  1596. To rebuild extensions distributed with the perl source you should
  1597. simply Configure (to include those extensions) and then build perl as
  1598. normal. After installing perl the source tree can be deleted. It is
  1599. not needed for building extensions by running 'perl Makefile.PL'
  1600. usually without extra arguments.
  1601.  
  1602. It is recommended that you unpack and build additional extensions away
  1603. from the perl source tree.
  1604. };
  1605.     }
  1606.     } else {
  1607.     # we should also consider $ENV{PERL5LIB} here
  1608.     $self->{PERL_LIB}     ||= $Config::Config{privlibexp};
  1609.     $self->{PERL_ARCHLIB} ||= $Config::Config{archlibexp};
  1610.     $self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
  1611.     my $perl_h;
  1612.     unless (-f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))){
  1613.         die qq{
  1614. Error: Unable to locate installed Perl libraries or Perl source code.
  1615.  
  1616. It is recommended that you install perl in a standard location before
  1617. building extensions. Some precompiled versions of perl do not contain
  1618. these header files, so you cannot build extensions. In such a case,
  1619. please build and install your perl from a fresh perl distribution. It
  1620. usually solves this kind of problem.
  1621.  
  1622. \(You get this message, because MakeMaker could not find "$perl_h"\)
  1623. };
  1624.     }
  1625. #     print STDOUT "Using header files found in $self->{PERL_INC}\n"
  1626. #         if $Verbose && $self->needs_linking();
  1627.  
  1628.     }
  1629.  
  1630.     # We get SITELIBEXP and SITEARCHEXP directly via
  1631.     # Get_from_Config. When we are running standard modules, these
  1632.     # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
  1633.     # set it to "site". I prefer that INSTALLDIRS be set from outside
  1634.     # MakeMaker.
  1635.     $self->{INSTALLDIRS} ||= "site";
  1636.  
  1637.     # INST_LIB typically pre-set if building an extension after
  1638.     # perl has been built and installed. Setting INST_LIB allows
  1639.     # you to build directly into, say $Config::Config{privlibexp}.
  1640.     unless ($self->{INST_LIB}){
  1641.  
  1642.  
  1643.     ##### XXXXX We have to change this nonsense
  1644.  
  1645.     if (defined $self->{PERL_SRC} and $self->{INSTALLDIRS} eq "perl") {
  1646.         $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
  1647.     } else {
  1648.         $self->{INST_LIB} = $self->catdir($self->curdir,"blib","lib");
  1649.     }
  1650.     }
  1651.     $self->{INST_ARCHLIB} ||= $self->catdir($self->curdir,"blib","arch");
  1652.     $self->{INST_BIN} ||= $self->catdir($self->curdir,'blib','bin');
  1653.  
  1654.     # We need to set up INST_LIBDIR before init_libscan() for VMS
  1655.     my @parentdir = split(/::/, $self->{PARENT_NAME});
  1656.     $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)',@parentdir);
  1657.     $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)',@parentdir);
  1658.     $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)','auto','$(FULLEXT)');
  1659.     $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)');
  1660.  
  1661.     # INST_EXE is deprecated, should go away March '97
  1662.     $self->{INST_EXE} ||= $self->catdir($self->curdir,'blib','script');
  1663.     $self->{INST_SCRIPT} ||= $self->catdir($self->curdir,'blib','script');
  1664.  
  1665.     # The user who requests an installation directory explicitly
  1666.     # should not have to tell us a architecture installation directory
  1667.     # as well. We look if a directory exists that is named after the
  1668.     # architecture. If not we take it as a sign that it should be the
  1669.     # same as the requested installation directory. Otherwise we take
  1670.     # the found one.
  1671.     # We do the same thing twice: for privlib/archlib and for sitelib/sitearch
  1672.     my($libpair);
  1673.     for $libpair ({l=>"privlib", a=>"archlib"}, {l=>"sitelib", a=>"sitearch"}) {
  1674.     my $lib = "install$libpair->{l}";
  1675.     my $Lib = uc $lib;
  1676.     my $Arch = uc "install$libpair->{a}";
  1677.     if( $self->{$Lib} && ! $self->{$Arch} ){
  1678.         my($ilib) = $Config{$lib};
  1679.         $ilib = VMS::Filespec::unixify($ilib) if $Is_VMS;
  1680.  
  1681.         $self->prefixify($Arch,$ilib,$self->{$Lib});
  1682.  
  1683.         unless (-d $self->{$Arch}) {
  1684.         print STDOUT "Directory $self->{$Arch} not found, thusly\n" if $Verbose;
  1685.         $self->{$Arch} = $self->{$Lib};
  1686.         }
  1687.         print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
  1688.     }
  1689.     }
  1690.  
  1691.     # we have to look at the relation between $Config{prefix} and the
  1692.     # requested values. We're going to set the $Config{prefix} part of
  1693.     # all the installation path variables to literally $(PREFIX), so
  1694.     # the user can still say make PREFIX=foo
  1695.     my($configure_prefix) = $Config{'prefix'};
  1696.     $configure_prefix = VMS::Filespec::unixify($configure_prefix) if $Is_VMS;
  1697.     $self->{PREFIX} ||= $configure_prefix;
  1698.  
  1699.  
  1700.     my($install_variable,$search_prefix,$replace_prefix);
  1701.  
  1702.     # The rule, taken from Configure, is that if prefix contains perl,
  1703.     # we shape the tree
  1704.     #    perlprefix/lib/                INSTALLPRIVLIB
  1705.     #    perlprefix/lib/pod/
  1706.     #    perlprefix/lib/site_perl/    INSTALLSITELIB
  1707.     #    perlprefix/bin/        INSTALLBIN
  1708.     #    perlprefix/man/        INSTALLMAN1DIR
  1709.     # else
  1710.     #    prefix/lib/perl5/        INSTALLPRIVLIB
  1711.     #    prefix/lib/perl5/pod/
  1712.     #    prefix/lib/perl5/site_perl/    INSTALLSITELIB
  1713.     #    prefix/bin/            INSTALLBIN
  1714.     #    prefix/lib/perl5/man/        INSTALLMAN1DIR
  1715.  
  1716.     $replace_prefix = qq[\$\(PREFIX\)];
  1717.     for $install_variable (qw/
  1718.                INSTALLBIN
  1719.                INSTALLSCRIPT
  1720.                /) {
  1721.     $self->prefixify($install_variable,$configure_prefix,$replace_prefix);
  1722.     }
  1723.     $search_prefix = $configure_prefix =~ /perl/ ?
  1724.     $self->catdir($configure_prefix,"lib") :
  1725.     $self->catdir($configure_prefix,"lib","perl5");
  1726.     if ($self->{LIB}) {
  1727.     $self->{INSTALLPRIVLIB} = $self->{INSTALLSITELIB} = $self->{LIB};
  1728.     $self->{INSTALLARCHLIB} = $self->{INSTALLSITEARCH} = 
  1729.         $self->catdir($self->{LIB},$Config{'archname'});
  1730.     } else {
  1731.     $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
  1732.         $self->catdir(qq[\$\(PREFIX\)],"lib") :
  1733.         $self->catdir(qq[\$\(PREFIX\)],"lib","perl5");
  1734.     for $install_variable (qw/
  1735.                    INSTALLPRIVLIB
  1736.                    INSTALLARCHLIB
  1737.                    INSTALLSITELIB
  1738.                    INSTALLSITEARCH
  1739.                    /) {
  1740.         $self->prefixify($install_variable,$search_prefix,$replace_prefix);
  1741.     }
  1742.     }
  1743.     $search_prefix = $configure_prefix =~ /perl/ ?
  1744.     $self->catdir($configure_prefix,"man") :
  1745.         $self->catdir($configure_prefix,"lib","perl5","man");
  1746.     $replace_prefix = $self->{PREFIX} =~ /perl/ ? 
  1747.     $self->catdir(qq[\$\(PREFIX\)],"man") :
  1748.         $self->catdir(qq[\$\(PREFIX\)],"lib","perl5","man");
  1749.     for $install_variable (qw/
  1750.                INSTALLMAN1DIR
  1751.                INSTALLMAN3DIR
  1752.                /) {
  1753.     $self->prefixify($install_variable,$search_prefix,$replace_prefix);
  1754.     }
  1755.  
  1756.     # Now we head at the manpages. Maybe they DO NOT want manpages
  1757.     # installed
  1758.     $self->{INSTALLMAN1DIR} = $Config::Config{installman1dir}
  1759.     unless defined $self->{INSTALLMAN1DIR};
  1760.     unless (defined $self->{INST_MAN1DIR}){
  1761.     if ($self->{INSTALLMAN1DIR} =~ /^(none|\s*)$/){
  1762.         $self->{INST_MAN1DIR} = $self->{INSTALLMAN1DIR};
  1763.     } else {
  1764.         $self->{INST_MAN1DIR} = $self->catdir($self->curdir,'blib','man1');
  1765.     }
  1766.     }
  1767.     $self->{MAN1EXT} ||= $Config::Config{man1ext};
  1768.  
  1769.     $self->{INSTALLMAN3DIR} = $Config::Config{installman3dir}
  1770.     unless defined $self->{INSTALLMAN3DIR};
  1771.     unless (defined $self->{INST_MAN3DIR}){
  1772.     if ($self->{INSTALLMAN3DIR} =~ /^(none|\s*)$/){
  1773.         $self->{INST_MAN3DIR} = $self->{INSTALLMAN3DIR};
  1774.     } else {
  1775.         $self->{INST_MAN3DIR} = $self->catdir($self->curdir,'blib','man3');
  1776.     }
  1777.     }
  1778.     $self->{MAN3EXT} ||= $Config::Config{man3ext};
  1779.  
  1780.  
  1781.     # Get some stuff out of %Config if we haven't yet done so
  1782.     print STDOUT "CONFIG must be an array ref\n"
  1783.     if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
  1784.     $self->{CONFIG} = [] unless (ref $self->{CONFIG});
  1785.     push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
  1786.     push(@{$self->{CONFIG}}, 'shellflags') if $Config::Config{shellflags};
  1787.     my(%once_only,$m);
  1788.     foreach $m (@{$self->{CONFIG}}){
  1789.     next if $once_only{$m};
  1790.     print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
  1791.         unless exists $Config::Config{$m};
  1792.     $self->{uc $m} ||= $Config::Config{$m};
  1793.     $once_only{$m} = 1;
  1794.     }
  1795.  
  1796. # This is too dangerous:
  1797. #    if ($^O eq "next") {
  1798. #    $self->{AR} = "libtool";
  1799. #    $self->{AR_STATIC_ARGS} = "-o";
  1800. #    }
  1801. # But I leave it as a placeholder
  1802.  
  1803.     $self->{AR_STATIC_ARGS} ||= "cr";
  1804.  
  1805.     # These should never be needed
  1806.     $self->{LD} ||= 'ld';
  1807.     $self->{OBJ_EXT} ||= '.o';
  1808.     $self->{LIB_EXT} ||= '.a';
  1809.  
  1810.     $self->{MAP_TARGET} ||= "perl";
  1811.  
  1812.     $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
  1813.  
  1814.     # make a simple check if we find Exporter
  1815.     warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
  1816.         (Exporter.pm not found)"
  1817.     unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
  1818.         $self->{NAME} eq "ExtUtils::MakeMaker";
  1819.  
  1820.     # Determine VERSION and VERSION_FROM
  1821.     ($self->{DISTNAME}=$self->{NAME}) =~ s#(::)#-#g unless $self->{DISTNAME};
  1822.     if ($self->{VERSION_FROM}){
  1823.     $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}) or
  1824.         Carp::carp "WARNING: Setting VERSION via file '$self->{VERSION_FROM}' failed\n"
  1825.     }
  1826.  
  1827.     # strip blanks
  1828.     if ($self->{VERSION}) {
  1829.     $self->{VERSION} =~ s/^\s+//;
  1830.     $self->{VERSION} =~ s/\s+$//;
  1831.     }
  1832.  
  1833.     $self->{VERSION} ||= "0.10";
  1834.     ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
  1835.  
  1836.  
  1837.     # Graham Barr and Paul Marquess had some ideas how to ensure
  1838.     # version compatibility between the *.pm file and the
  1839.     # corresponding *.xs file. The bottomline was, that we need an
  1840.     # XS_VERSION macro that defaults to VERSION:
  1841.     $self->{XS_VERSION} ||= $self->{VERSION};
  1842.  
  1843.     # --- Initialize Perl Binary Locations
  1844.  
  1845.     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
  1846.     # will be working versions of perl 5. miniperl has priority over perl
  1847.     # for PERL to ensure that $(PERL) is usable while building ./ext/*
  1848.     my ($component,@defpath);
  1849.     foreach $component ($self->{PERL_SRC}, $self->path(), $Config::Config{binexp}) {
  1850.     push @defpath, $component if defined $component;
  1851.     }
  1852.     $self->{PERL} ||=
  1853.         $self->find_perl(5.0, [ $^X, 'miniperl','perl','perl5',"perl$]" ],
  1854.         \@defpath, $Verbose );
  1855.     # don't check if perl is executable, maybe they have decided to
  1856.     # supply switches with perl
  1857.  
  1858.     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
  1859.     ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/perl/i
  1860.     unless ($self->{FULLPERL});
  1861. }
  1862.  
  1863. =item init_others
  1864.  
  1865. Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH,
  1866. OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, NOOP, FIRST_MAKEFILE,
  1867. MAKEFILE, NOECHO, RM_F, RM_RF, TEST_F, TOUCH, CP, MV, CHMOD, UMASK_NULL
  1868.  
  1869. =cut
  1870.  
  1871. sub init_others {    # --- Initialize Other Attributes
  1872.     my($self) = shift;
  1873.  
  1874.     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
  1875.     # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
  1876.     # undefined. In any case we turn it into an anon array:
  1877.  
  1878.     # May check $Config{libs} too, thus not empty.
  1879.     $self->{LIBS}=[''] unless $self->{LIBS};
  1880.  
  1881.     $self->{LIBS}=[$self->{LIBS}] if ref \$self->{LIBS} eq 'SCALAR';
  1882.     $self->{LD_RUN_PATH} = "";
  1883.     my($libs);
  1884.     foreach $libs ( @{$self->{LIBS}} ){
  1885.     $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
  1886.     my(@libs) = $self->extliblist($libs);
  1887.     if ($libs[0] or $libs[1] or $libs[2]){
  1888.         # LD_RUN_PATH now computed by ExtUtils::Liblist
  1889.         ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
  1890.         last;
  1891.     }
  1892.     }
  1893.  
  1894.     if ( $self->{OBJECT} ) {
  1895.     $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
  1896.     } else {
  1897.     # init_dirscan should have found out, if we have C files
  1898.     $self->{OBJECT} = "";
  1899.     $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
  1900.     }
  1901.     $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
  1902.     $self->{BOOTDEP}  = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
  1903.     $self->{PERLMAINCC} ||= '$(CC)';
  1904.     $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
  1905.  
  1906.     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
  1907.     # the 'dynamic' section of MM.  We don't have this problem with
  1908.     # 'static', since we either must use it (%Config says we can't
  1909.     # use dynamic loading) or the caller asked for it explicitly.
  1910.     if (!$self->{LINKTYPE}) {
  1911.        $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
  1912.                         ? 'static'
  1913.                         : ($Config::Config{usedl} ? 'dynamic' : 'static');
  1914.     };
  1915.  
  1916.     # These get overridden for VMS and maybe some other systems
  1917.     $self->{NOOP}  ||= '$(SHELL) -c true';
  1918.     $self->{FIRST_MAKEFILE} ||= "Makefile";
  1919.     $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
  1920.     $self->{MAKE_APERL_FILE} ||= "Makefile.aperl";
  1921.     $self->{NOECHO} = '@' unless defined $self->{NOECHO};
  1922.     $self->{RM_F}  ||= "rm -f";
  1923.     $self->{RM_RF} ||= "rm -rf";
  1924.     $self->{TOUCH} ||= "touch";
  1925.     $self->{TEST_F} ||= "test -f";
  1926.     $self->{CP} ||= "cp";
  1927.     $self->{MV} ||= "mv";
  1928.     $self->{CHMOD} ||= "chmod";
  1929.     $self->{UMASK_NULL} ||= "umask 0";
  1930.     $self->{DEV_NULL} ||= "> /dev/null 2>&1";
  1931. }
  1932.  
  1933. =item install (o)
  1934.  
  1935. Defines the install target.
  1936.  
  1937. =cut
  1938.  
  1939. sub install {
  1940.     my($self, %attribs) = @_;
  1941.     my(@m);
  1942.  
  1943.     push @m, q{
  1944. install :: all pure_install doc_install
  1945.  
  1946. install_perl :: all pure_perl_install doc_perl_install
  1947.  
  1948. install_site :: all pure_site_install doc_site_install
  1949.  
  1950. install_ :: install_site
  1951.     @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
  1952.  
  1953. pure_install :: pure_$(INSTALLDIRS)_install
  1954.  
  1955. doc_install :: doc_$(INSTALLDIRS)_install
  1956.     }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
  1957.  
  1958. pure__install : pure_site_install
  1959.     @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
  1960.  
  1961. doc__install : doc_site_install
  1962.     @echo INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
  1963.  
  1964. pure_perl_install ::
  1965.     }.$self->{NOECHO}.q{$(MOD_INSTALL) \
  1966.         read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
  1967.         write }.$self->catfile('$(INSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
  1968.         $(INST_LIB) $(INSTALLPRIVLIB) \
  1969.         $(INST_ARCHLIB) $(INSTALLARCHLIB) \
  1970.         $(INST_BIN) $(INSTALLBIN) \
  1971.         $(INST_SCRIPT) $(INSTALLSCRIPT) \
  1972.         $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
  1973.         $(INST_MAN3DIR) $(INSTALLMAN3DIR)
  1974.     }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
  1975.         }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
  1976.  
  1977.  
  1978. pure_site_install ::
  1979.     }.$self->{NOECHO}.q{$(MOD_INSTALL) \
  1980.         read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
  1981.         write }.$self->catfile('$(INSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
  1982.         $(INST_LIB) $(INSTALLSITELIB) \
  1983.         $(INST_ARCHLIB) $(INSTALLSITEARCH) \
  1984.         $(INST_BIN) $(INSTALLBIN) \
  1985.         $(INST_SCRIPT) $(INSTALLSCRIPT) \
  1986.         $(INST_MAN1DIR) $(INSTALLMAN1DIR) \
  1987.         $(INST_MAN3DIR) $(INSTALLMAN3DIR)
  1988.     }.$self->{NOECHO}.q{$(WARN_IF_OLD_PACKLIST) \
  1989.         }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
  1990.  
  1991. doc_perl_install ::
  1992.     -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
  1993.         "Module" "$(NAME)" \
  1994.         "installed into" "$(INSTALLPRIVLIB)" \
  1995.         LINKTYPE "$(LINKTYPE)" \
  1996.         VERSION "$(VERSION)" \
  1997.         EXE_FILES "$(EXE_FILES)" \
  1998.         >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
  1999.  
  2000. doc_site_install ::
  2001.     -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
  2002.         "Module" "$(NAME)" \
  2003.         "installed into" "$(INSTALLSITELIB)" \
  2004.         LINKTYPE "$(LINKTYPE)" \
  2005.         VERSION "$(VERSION)" \
  2006.         EXE_FILES "$(EXE_FILES)" \
  2007.         >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
  2008.  
  2009. };
  2010.  
  2011.     push @m, q{
  2012. uninstall :: uninstall_from_$(INSTALLDIRS)dirs
  2013.  
  2014. uninstall_from_perldirs ::
  2015.     }.$self->{NOECHO}.
  2016.     q{$(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
  2017.  
  2018. uninstall_from_sitedirs ::
  2019.     }.$self->{NOECHO}.
  2020.     q{$(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
  2021. };
  2022.  
  2023.     join("",@m);
  2024. }
  2025.  
  2026. =item installbin (o)
  2027.  
  2028. Defines targets to make and to install EXE_FILES.
  2029.  
  2030. =cut
  2031.  
  2032. sub installbin {
  2033.     my($self) = shift;
  2034.     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
  2035.     return "" unless @{$self->{EXE_FILES}};
  2036.     my(@m, $from, $to, %fromto, @to);
  2037.     push @m, $self->dir_target(qw[$(INST_SCRIPT)]);
  2038.     for $from (@{$self->{EXE_FILES}}) {
  2039.     my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
  2040.     local($_) = $path; # for backwards compatibility
  2041.     $to = $self->libscan($path);
  2042.     print "libscan($from) => '$to'\n" if ($Verbose >=2);
  2043.     $fromto{$from}=$to;
  2044.     }
  2045.     @to   = values %fromto;
  2046.     push(@m, qq{
  2047. EXE_FILES = @{$self->{EXE_FILES}}
  2048.  
  2049. } . ($Is_Win32
  2050.   ? q{FIXIN = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
  2051.     -e "system qq[pl2bat.bat ].shift"
  2052. } : q{FIXIN = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::MakeMaker \
  2053.     -e "MY->fixin(shift)"
  2054. }).qq{
  2055. pure_all :: @to
  2056.     $self->{NOECHO}\$(NOOP)
  2057.  
  2058. realclean ::
  2059.     $self->{RM_F} @to
  2060. });
  2061.  
  2062.     while (($from,$to) = each %fromto) {
  2063.     last unless defined $from;
  2064.     my $todir = dirname($to);
  2065.     push @m, "
  2066. $to: $from $self->{MAKEFILE} " . $self->catdir($todir,'.exists') . "
  2067.     $self->{NOECHO}$self->{RM_F} $to
  2068.     $self->{CP} $from $to
  2069.     \$(FIXIN) $to
  2070.     -$self->{NOECHO}\$(CHMOD) \$(PERM_RWX) $to
  2071. ";
  2072.     }
  2073.     join "", @m;
  2074. }
  2075.  
  2076. =item libscan (o)
  2077.  
  2078. Takes a path to a file that is found by init_dirscan and returns false
  2079. if we don't want to include this file in the library. Mainly used to
  2080. exclude RCS, CVS, and SCCS directories from installation.
  2081.  
  2082. =cut
  2083.  
  2084. # ';
  2085.  
  2086. sub libscan {
  2087.     my($self,$path) = @_;
  2088.     return '' if $path =~ m:\b(RCS|CVS|SCCS)\b: ;
  2089.     $path;
  2090. }
  2091.  
  2092. =item linkext (o)
  2093.  
  2094. Defines the linkext target which in turn defines the LINKTYPE.
  2095.  
  2096. =cut
  2097.  
  2098. sub linkext {
  2099.     my($self, %attribs) = @_;
  2100.     # LINKTYPE => static or dynamic or ''
  2101.     my($linktype) = defined $attribs{LINKTYPE} ?
  2102.       $attribs{LINKTYPE} : '$(LINKTYPE)';
  2103.     "
  2104. linkext :: $linktype
  2105.     $self->{NOECHO}\$(NOOP)
  2106. ";
  2107. }
  2108.  
  2109. =item lsdir
  2110.  
  2111. Takes as arguments a directory name and a regular expression. Returns
  2112. all entries in the directory that match the regular expression.
  2113.  
  2114. =cut
  2115.  
  2116. sub lsdir {
  2117.     my($self) = shift;
  2118.     my($dir, $regex) = @_;
  2119.     my(@ls);
  2120.     my $dh = new DirHandle;
  2121.     $dh->open($dir || ".") or return ();
  2122.     @ls = $dh->read;
  2123.     $dh->close;
  2124.     @ls = grep(/$regex/, @ls) if $regex;
  2125.     @ls;
  2126. }
  2127.  
  2128. =item macro (o)
  2129.  
  2130. Simple subroutine to insert the macros defined by the macro attribute
  2131. into the Makefile.
  2132.  
  2133. =cut
  2134.  
  2135. sub macro {
  2136.     my($self,%attribs) = @_;
  2137.     my(@m,$key,$val);
  2138.     while (($key,$val) = each %attribs){
  2139.     last unless defined $key;
  2140.     push @m, "$key = $val\n";
  2141.     }
  2142.     join "", @m;
  2143. }
  2144.  
  2145. =item makeaperl (o)
  2146.  
  2147. Called by staticmake. Defines how to write the Makefile to produce a
  2148. static new perl.
  2149.  
  2150. By default the Makefile produced includes all the static extensions in
  2151. the perl library. (Purified versions of library files, e.g.,
  2152. DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
  2153.  
  2154. =cut
  2155.  
  2156. sub makeaperl {
  2157.     my($self, %attribs) = @_;
  2158.     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
  2159.     @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
  2160.     my(@m);
  2161.     push @m, "
  2162. # --- MakeMaker makeaperl section ---
  2163. MAP_TARGET    = $target
  2164. FULLPERL      = $self->{FULLPERL}
  2165. ";
  2166.     return join '', @m if $self->{PARENT};
  2167.  
  2168.     my($dir) = join ":", @{$self->{DIR}};
  2169.  
  2170.     unless ($self->{MAKEAPERL}) {
  2171.     push @m, q{
  2172. $(MAP_TARGET) :: static $(MAKE_APERL_FILE)
  2173.     $(MAKE) -f $(MAKE_APERL_FILE) $@
  2174.  
  2175. $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
  2176.     }.$self->{NOECHO}.q{echo Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
  2177.     }.$self->{NOECHO}.q{$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
  2178.         Makefile.PL DIR=}, $dir, q{ \
  2179.         MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
  2180.         MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
  2181.  
  2182.     foreach (@ARGV){
  2183.         if( /\s/ ){
  2184.             s/=(.*)/='$1'/;
  2185.         }
  2186.         push @m, " \\\n\t\t$_";
  2187.     }
  2188. #    push @m, map( " \\\n\t\t$_", @ARGV );
  2189.     push @m, "\n";
  2190.  
  2191.     return join '', @m;
  2192.     }
  2193.  
  2194.  
  2195.  
  2196.     my($cccmd, $linkcmd, $lperl);
  2197.  
  2198.  
  2199.     $cccmd = $self->const_cccmd($libperl);
  2200.     $cccmd =~ s/^CCCMD\s*=\s*//;
  2201.     $cccmd =~ s/\$\(INC\)/ -I$self->{PERL_INC} /;
  2202.     $cccmd .= " $Config::Config{cccdlflags}"
  2203.     if ($Config::Config{useshrplib} eq 'true');
  2204.     $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
  2205.  
  2206.     # The front matter of the linkcommand...
  2207.     $linkcmd = join ' ', "\$(CC)",
  2208.         grep($_, @Config{qw(large split ldflags ccdlflags)});
  2209.     $linkcmd =~ s/\s+/ /g;
  2210.     $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
  2211.  
  2212.     # Which *.a files could we make use of...
  2213.     local(%static);
  2214.     require File::Find;
  2215.     File::Find::find(sub {
  2216.     return unless m/\Q$self->{LIB_EXT}\E$/;
  2217.     return if m/^libperl/;
  2218.     # Skip purified versions of libraries (e.g., DynaLoader_pure_p1_c0_032.a)
  2219.     return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
  2220.  
  2221.     if( exists $self->{INCLUDE_EXT} ){
  2222.         my $found = 0;
  2223.         my $incl;
  2224.         my $xx;
  2225.  
  2226.         ($xx = $File::Find::name) =~ s,.*?/auto/,,;
  2227.         $xx =~ s,/?$_,,;
  2228.         $xx =~ s,/,::,g;
  2229.  
  2230.         # Throw away anything not explicitly marked for inclusion.
  2231.         # DynaLoader is implied.
  2232.         foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
  2233.             if( $xx eq $incl ){
  2234.                 $found++;
  2235.                 last;
  2236.             }
  2237.         }
  2238.         return unless $found;
  2239.     }
  2240.     elsif( exists $self->{EXCLUDE_EXT} ){
  2241.         my $excl;
  2242.         my $xx;
  2243.  
  2244.         ($xx = $File::Find::name) =~ s,.*?/auto/,,;
  2245.         $xx =~ s,/?$_,,;
  2246.         $xx =~ s,/,::,g;
  2247.  
  2248.         # Throw away anything explicitly marked for exclusion
  2249.         foreach $excl (@{$self->{EXCLUDE_EXT}}){
  2250.             return if( $xx eq $excl );
  2251.         }
  2252.     }
  2253.  
  2254.     # don't include the installed version of this extension. I
  2255.     # leave this line here, although it is not necessary anymore:
  2256.     # I patched minimod.PL instead, so that Miniperl.pm won't
  2257.     # enclude duplicates
  2258.  
  2259.     # Once the patch to minimod.PL is in the distribution, I can
  2260.     # drop it
  2261.     return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}$:;
  2262.     use Cwd 'cwd';
  2263.     $static{cwd() . "/" . $_}++;
  2264.     }, grep( -d $_, @{$searchdirs || []}) );
  2265.  
  2266.     # We trust that what has been handed in as argument, will be buildable
  2267.     $static = [] unless $static;
  2268.     @static{@{$static}} = (1) x @{$static};
  2269.  
  2270.     $extra = [] unless $extra && ref $extra eq 'ARRAY';
  2271.     for (sort keys %static) {
  2272.     next unless /\Q$self->{LIB_EXT}\E$/;
  2273.     $_ = dirname($_) . "/extralibs.ld";
  2274.     push @$extra, $_;
  2275.     }
  2276.  
  2277.     grep(s/^/-I/, @{$perlinc || []});
  2278.  
  2279.     $target = "perl" unless $target;
  2280.     $tmp = "." unless $tmp;
  2281.  
  2282. # MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
  2283. # regenerate the Makefiles, MAP_STATIC and the dependencies for
  2284. # extralibs.all are computed correctly
  2285.     push @m, "
  2286. MAP_LINKCMD   = $linkcmd
  2287. MAP_PERLINC   = @{$perlinc || []}
  2288. MAP_STATIC    = ",
  2289. join(" \\\n\t", reverse sort keys %static), "
  2290.  
  2291. MAP_PRELIBS   = $Config::Config{libs} $Config::Config{cryptlib}
  2292. ";
  2293.  
  2294.     if (defined $libperl) {
  2295.     ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
  2296.     }
  2297.     unless ($libperl && -f $lperl) { # Ilya's code...
  2298.     my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
  2299.     $libperl ||= "libperl$self->{LIB_EXT}";
  2300.     $libperl   = "$dir/$libperl";
  2301.     $lperl   ||= "libperl$self->{LIB_EXT}";
  2302.     $lperl     = "$dir/$lperl";
  2303.  
  2304.         if (! -f $libperl and ! -f $lperl) {
  2305.           # We did not find a static libperl. Maybe there is a shared one?
  2306.           if ($^O eq 'solaris' or $^O eq 'sunos') {
  2307.             $lperl  = $libperl = "$dir/$Config::Config{libperl}";
  2308.             # SUNOS ld does not take the full path to a shared library
  2309.             $libperl = '' if $^O eq 'sunos';
  2310.           }
  2311.         }
  2312.  
  2313.     print STDOUT "Warning: $libperl not found
  2314.     If you're going to build a static perl binary, make sure perl is installed
  2315.     otherwise ignore this warning\n"
  2316.         unless (-f $lperl || defined($self->{PERL_SRC}));
  2317.     }
  2318.  
  2319.     push @m, "
  2320. MAP_LIBPERL = $libperl
  2321. ";
  2322.  
  2323.     push @m, "
  2324. \$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)/.exists ".join(" \\\n\t", @$extra)."
  2325.     $self->{NOECHO}$self->{RM_F} \$\@
  2326.     $self->{NOECHO}\$(TOUCH) \$\@
  2327. ";
  2328.  
  2329.     my $catfile;
  2330.     foreach $catfile (@$extra){
  2331.     push @m, "\tcat $catfile >> \$\@\n";
  2332.     }
  2333.     # SUNOS ld does not take the full path to a shared library
  2334.     my $llibperl = ($libperl)?'$(MAP_LIBPERL)':'-lperl';
  2335.  
  2336.     # Brain dead solaris linker does not use LD_RUN_PATH?
  2337.     # This fixes dynamic extensions which need shared libs
  2338.     my $ldfrom = ($^O eq 'solaris')?
  2339.            join(' ', map "-R$_", split /:/, $self->{LD_RUN_PATH}):'';
  2340.  
  2341. push @m, "
  2342. \$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
  2343.     \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) $ldfrom \$(MAP_STATIC) $llibperl `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
  2344.     $self->{NOECHO}echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
  2345.     $self->{NOECHO}echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
  2346.     $self->{NOECHO}echo 'To remove the intermediate files say'
  2347.     $self->{NOECHO}echo '    make -f $makefilename map_clean'
  2348.  
  2349. $tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
  2350. ";
  2351.     push @m, "\tcd $tmp && $cccmd -I\$(PERL_INC) perlmain.c\n";
  2352.  
  2353.     push @m, qq{
  2354. $tmp/perlmain.c: $makefilename}, q{
  2355.     }.$self->{NOECHO}.q{echo Writing $@
  2356.     }.$self->{NOECHO}.q{$(PERL) $(MAP_PERLINC) -MExtUtils::Miniperl \\
  2357.         -e "writemain(grep s#.*/auto/##, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@
  2358.  
  2359. };
  2360.     push @m, "\t",$self->{NOECHO}.q{$(PERL) $(INSTALLSCRIPT)/fixpmain
  2361. } if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
  2362.  
  2363.  
  2364.     push @m, q{
  2365. doc_inst_perl:
  2366.     }.$self->{NOECHO}.q{echo Appending installation info to $(INSTALLARCHLIB)/perllocal.pod
  2367.     -}.$self->{NOECHO}.q{$(DOC_INSTALL) \
  2368.         "Perl binary" "$(MAP_TARGET)" \
  2369.         MAP_STATIC "$(MAP_STATIC)" \
  2370.         MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
  2371.         MAP_LIBPERL "$(MAP_LIBPERL)" \
  2372.         >> }.$self->catfile('$(INSTALLARCHLIB)','perllocal.pod').q{
  2373.  
  2374. };
  2375.  
  2376.     push @m, q{
  2377. inst_perl: pure_inst_perl doc_inst_perl
  2378.  
  2379. pure_inst_perl: $(MAP_TARGET)
  2380.     }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(INSTALLBIN)','$(MAP_TARGET)').q{
  2381.  
  2382. clean :: map_clean
  2383.  
  2384. map_clean :
  2385.     }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
  2386. };
  2387.  
  2388.     join '', @m;
  2389. }
  2390.  
  2391. =item makefile (o)
  2392.  
  2393. Defines how to rewrite the Makefile.
  2394.  
  2395. =cut
  2396.  
  2397. sub makefile {
  2398.     my($self) = shift;
  2399.     my @m;
  2400.     # We do not know what target was originally specified so we
  2401.     # must force a manual rerun to be sure. But as it should only
  2402.     # happen very rarely it is not a significant problem.
  2403.     push @m, '
  2404. $(OBJECT) : $(FIRST_MAKEFILE)
  2405. ' if $self->{OBJECT};
  2406.  
  2407.     push @m, q{
  2408. # We take a very conservative approach here, but it\'s worth it.
  2409. # We move Makefile to Makefile.old here to avoid gnu make looping.
  2410. }.$self->{MAKEFILE}.q{ : Makefile.PL $(CONFIGDEP)
  2411.     }.$self->{NOECHO}.q{echo "Makefile out-of-date with respect to $?"
  2412.     }.$self->{NOECHO}.q{echo "Cleaning current config before rebuilding Makefile..."
  2413.     -}.$self->{NOECHO}.q{$(RM_F) }."$self->{MAKEFILE}.old".q{
  2414.     -}.$self->{NOECHO}.q{$(MV) }."$self->{MAKEFILE} $self->{MAKEFILE}.old".q{
  2415.     -$(MAKE) -f }.$self->{MAKEFILE}.q{.old clean $(DEV_NULL) || $(NOOP)
  2416.     $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
  2417.     }.$self->{NOECHO}.q{echo "==> Your Makefile has been rebuilt. <=="
  2418.     }.$self->{NOECHO}.q{echo "==> Please rerun the make command.  <=="
  2419.     false
  2420.  
  2421. # To change behavior to :: would be nice, but would break Tk b9.02
  2422. # so you find such a warning below the dist target.
  2423. #}.$self->{MAKEFILE}.q{ :: $(VERSION_FROM)
  2424. #    }.$self->{NOECHO}.q{echo "Warning: Makefile possibly out of date with $(VERSION_FROM)"
  2425. };
  2426.  
  2427.     join "", @m;
  2428. }
  2429.  
  2430. =item manifypods (o)
  2431.  
  2432. Defines targets and routines to translate the pods into manpages and
  2433. put them into the INST_* directories.
  2434.  
  2435. =cut
  2436.  
  2437. sub manifypods {
  2438.     my($self, %attribs) = @_;
  2439.     return "\nmanifypods : pure_all\n\t$self->{NOECHO}\$(NOOP)\n" unless
  2440.     %{$self->{MAN3PODS}} or %{$self->{MAN1PODS}};
  2441.     my($dist);
  2442.     my($pod2man_exe);
  2443.     if (defined $self->{PERL_SRC}) {
  2444.     $pod2man_exe = $self->catfile($self->{PERL_SRC},'pod','pod2man');
  2445.     } else {
  2446.     $pod2man_exe = $self->catfile($Config{scriptdirexp},'pod2man');
  2447.     }
  2448.     unless ($self->perl_script($pod2man_exe)) {
  2449.     # No pod2man but some MAN3PODS to be installed
  2450.     print <<END;
  2451.  
  2452. Warning: I could not locate your pod2man program. Please make sure,
  2453.          your pod2man program is in your PATH before you execute 'make'
  2454.  
  2455. END
  2456.         $pod2man_exe = "-S pod2man";
  2457.     }
  2458.     my(@m);
  2459.     push @m,
  2460. qq[POD2MAN_EXE = $pod2man_exe\n],
  2461. qq[POD2MAN = \$(PERL) -we '%m=\@ARGV;for (keys %m){' \\\n],
  2462. q[-e 'next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M "],
  2463.  $self->{MAKEFILE}, q[";' \\
  2464. -e 'print "Manifying $$m{$$_}\n";' \\
  2465. -e 'system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2MAN_EXE) ].qq[$$_>$$m{$$_}])==0 or warn "Couldn\\047t install $$m{$$_}\n";' \\
  2466. -e 'chmod(oct($(PERM_RW))), $$m{$$_} or warn "chmod $(PERM_RW) $$m{$$_}: $$!\n";}'
  2467. ];
  2468.     push @m, "\nmanifypods : pure_all ";
  2469.     push @m, join " \\\n\t", keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}};
  2470.  
  2471.     push(@m,"\n");
  2472.     if (%{$self->{MAN1PODS}} || %{$self->{MAN3PODS}}) {
  2473.     push @m, "\t$self->{NOECHO}\$(POD2MAN) \\\n\t";
  2474.     push @m, join " \\\n\t", %{$self->{MAN1PODS}}, %{$self->{MAN3PODS}};
  2475.     }
  2476.     join('', @m);
  2477. }
  2478.  
  2479. =item maybe_command
  2480.  
  2481. Returns true, if the argument is likely to be a command.
  2482.  
  2483. =cut
  2484.  
  2485. sub maybe_command {
  2486.     my($self,$file) = @_;
  2487.     return $file if -x $file && ! -d $file;
  2488.     return;
  2489. }
  2490.  
  2491. =item maybe_command_in_dirs
  2492.  
  2493. method under development. Not yet used. Ask Ilya :-)
  2494.  
  2495. =cut
  2496.  
  2497. sub maybe_command_in_dirs {    # $ver is optional argument if looking for perl
  2498. # Ilya's suggestion. Not yet used, want to understand it first, but at least the code is here
  2499.     my($self, $names, $dirs, $trace, $ver) = @_;
  2500.     my($name, $dir);
  2501.     foreach $dir (@$dirs){
  2502.     next unless defined $dir; # $self->{PERL_SRC} may be undefined
  2503.     foreach $name (@$names){
  2504.         my($abs,$tryabs);
  2505.         if ($self->file_name_is_absolute($name)) { # /foo/bar
  2506.         $abs = $name;
  2507.         } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # bar
  2508.         $abs = $self->catfile($dir, $name);
  2509.         } else { # foo/bar
  2510.         $abs = $self->catfile($self->curdir, $name);
  2511.         }
  2512.         print "Checking $abs for $name\n" if ($trace >= 2);
  2513.         next unless $tryabs = $self->maybe_command($abs);
  2514.         print "Substituting $tryabs instead of $abs\n"
  2515.         if ($trace >= 2 and $tryabs ne $abs);
  2516.         $abs = $tryabs;
  2517.         if (defined $ver) {
  2518.         print "Executing $abs\n" if ($trace >= 2);
  2519.         if (`$abs -e 'require $ver; print "VER_OK\n" ' 2>&1` =~ /VER_OK/) {
  2520.             print "Using PERL=$abs\n" if $trace;
  2521.             return $abs;
  2522.         }
  2523.         } else { # Do not look for perl
  2524.         return $abs;
  2525.         }
  2526.     }
  2527.     }
  2528. }
  2529.  
  2530. =item needs_linking (o)
  2531.  
  2532. Does this module need linking? Looks into subdirectory objects (see
  2533. also has_link_code())
  2534.  
  2535. =cut
  2536.  
  2537. sub needs_linking {
  2538.     my($self) = shift;
  2539.     my($child,$caller);
  2540.     $caller = (caller(0))[3];
  2541.     Carp::confess("Needs_linking called too early") if $caller =~ /^ExtUtils::MakeMaker::/;
  2542.     return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
  2543.     if ($self->has_link_code or $self->{MAKEAPERL}){
  2544.     $self->{NEEDS_LINKING} = 1;
  2545.     return 1;
  2546.     }
  2547.     foreach $child (keys %{$self->{CHILDREN}}) {
  2548.     if ($self->{CHILDREN}->{$child}->needs_linking) {
  2549.         $self->{NEEDS_LINKING} = 1;
  2550.         return 1;
  2551.     }
  2552.     }
  2553.     return $self->{NEEDS_LINKING} = 0;
  2554. }
  2555.  
  2556. =item nicetext
  2557.  
  2558. misnamed method (will have to be changed). The MM_Unix method just
  2559. returns the argument without further processing.
  2560.  
  2561. On VMS used to insure that colons marking targets are preceded by
  2562. space - most Unix Makes don't need this, but it's necessary under VMS
  2563. to distinguish the target delimiter from a colon appearing as part of
  2564. a filespec.
  2565.  
  2566. =cut
  2567.  
  2568. sub nicetext {
  2569.     my($self,$text) = @_;
  2570.     $text;
  2571. }
  2572.  
  2573. =item parse_version
  2574.  
  2575. parse a file and return what you think is $VERSION in this file set to
  2576.  
  2577. =cut
  2578.  
  2579. sub parse_version {
  2580.     my($self,$parsefile) = @_;
  2581.     my $result;
  2582.     local *FH;
  2583.     local $/ = "\n";
  2584.     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
  2585.     my $inpod = 0;
  2586.     while (<FH>) {
  2587.     $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
  2588.     next if $inpod;
  2589.     chop;
  2590.     # next unless /\$(([\w\:\']*)\bVERSION)\b.*\=/;
  2591.     next unless /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
  2592.     my $eval = qq{
  2593.         package ExtUtils::MakeMaker::_version;
  2594.         no strict;
  2595.  
  2596.         local $1$2;
  2597.         \$$2=undef; do {
  2598.         $_
  2599.         }; \$$2
  2600.     };
  2601.     local($^W) = 0;
  2602.     $result = eval($eval);
  2603.     die "Could not eval '$eval' in $parsefile: $@" if $@;
  2604.     $result = "undef" unless defined $result;
  2605.     last;
  2606.     }
  2607.     close FH;
  2608.     return $result;
  2609. }
  2610.  
  2611. =item parse_abstract
  2612.  
  2613. parse a file and return what you think is the ABSTRACT
  2614.  
  2615. =cut
  2616.  
  2617. sub parse_abstract {
  2618.     my($self,$parsefile) = @_;
  2619.     my $result;
  2620.     local *FH;
  2621.     local $/ = "\n";
  2622.     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
  2623.     my $inpod = 0;
  2624.     my $package = $self->{DISTNAME};
  2625.     $package =~ s/-/::/;
  2626.     while (<FH>) {
  2627.         $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
  2628.         next if !$inpod;
  2629.         chop;
  2630.         next unless /^($package\s-\s)(.*)/;
  2631.         $result = $2;
  2632.         last;
  2633.     }
  2634.     close FH;
  2635.     return $result;
  2636. }
  2637.  
  2638. =item pasthru (o)
  2639.  
  2640. Defines the string that is passed to recursive make calls in
  2641. subdirectories.
  2642.  
  2643. =cut
  2644.  
  2645. sub pasthru {
  2646.     my($self) = shift;
  2647.     my(@m,$key);
  2648.  
  2649.     my(@pasthru);
  2650.     my($sep) = $Is_VMS ? ',' : '';
  2651.     $sep .= "\\\n\t";
  2652.  
  2653.     foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE)){
  2654.     push @pasthru, "$key=\"\$($key)\"";
  2655.     }
  2656.  
  2657.     push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
  2658.     join "", @m;
  2659. }
  2660.  
  2661. =item path
  2662.  
  2663. Takes no argument, returns the environment variable PATH as an array.
  2664.  
  2665. =cut
  2666.  
  2667. sub path {
  2668.     my($self) = @_;
  2669.     my $path_sep = ($Is_OS2 || $Is_Dos) ? ";" : ":";
  2670.     my $path = $ENV{PATH};
  2671.     $path =~ s:\\:/:g if $Is_OS2;
  2672.     my @path = split $path_sep, $path;
  2673.     foreach(@path) { $_ = '.' if $_ eq '' }
  2674.     @path;
  2675. }
  2676.  
  2677. =item perl_script
  2678.  
  2679. Takes one argument, a file name, and returns the file name, if the
  2680. argument is likely to be a perl script. On MM_Unix this is true for
  2681. any ordinary, readable file.
  2682.  
  2683. =cut
  2684.  
  2685. sub perl_script {
  2686.     my($self,$file) = @_;
  2687.     return $file if -r $file && -f _;
  2688.     return;
  2689. }
  2690.  
  2691. =item perldepend (o)
  2692.  
  2693. Defines the dependency from all *.h files that come with the perl
  2694. distribution.
  2695.  
  2696. =cut
  2697.  
  2698. sub perldepend {
  2699.     my($self) = shift;
  2700.     my(@m);
  2701.     push @m, q{
  2702. # Check for unpropogated config.sh changes. Should never happen.
  2703. # We do NOT just update config.h because that is not sufficient.
  2704. # An out of date config.h is not fatal but complains loudly!
  2705. $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
  2706.     -}.$self->{NOECHO}.q{echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
  2707.  
  2708. $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
  2709.     }.$self->{NOECHO}.q{echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
  2710.     cd $(PERL_SRC) && $(MAKE) lib/Config.pm
  2711. } if $self->{PERL_SRC};
  2712.  
  2713.     return join "", @m unless $self->needs_linking;
  2714.  
  2715.     push @m, q{
  2716. PERL_HDRS = \
  2717. $(PERL_INC)/EXTERN.h       $(PERL_INC)/gv.h           $(PERL_INC)/pp.h       \
  2718. $(PERL_INC)/INTERN.h       $(PERL_INC)/handy.h        $(PERL_INC)/proto.h    \
  2719. $(PERL_INC)/XSUB.h         $(PERL_INC)/hv.h           $(PERL_INC)/regcomp.h  \
  2720. $(PERL_INC)/av.h           $(PERL_INC)/keywords.h     $(PERL_INC)/regexp.h   \
  2721. $(PERL_INC)/config.h       $(PERL_INC)/mg.h           $(PERL_INC)/scope.h    \
  2722. $(PERL_INC)/cop.h          $(PERL_INC)/op.h           $(PERL_INC)/sv.h         \
  2723. $(PERL_INC)/cv.h           $(PERL_INC)/opcode.h       $(PERL_INC)/unixish.h  \
  2724. $(PERL_INC)/dosish.h       $(PERL_INC)/patchlevel.h   $(PERL_INC)/util.h     \
  2725. $(PERL_INC)/embed.h        $(PERL_INC)/perl.h         $(PERL_INC)/iperlsys.h \
  2726. $(PERL_INC)/form.h         $(PERL_INC)/perly.h
  2727.  
  2728. $(OBJECT) : $(PERL_HDRS)
  2729. } if $self->{OBJECT};
  2730.  
  2731.     push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
  2732.  
  2733.     join "\n", @m;
  2734. }
  2735.  
  2736. =item ppd
  2737.  
  2738. Defines target that creates a PPD (Perl Package Description) file
  2739. for a binary distribution.
  2740.  
  2741. =cut
  2742.  
  2743. sub ppd {
  2744.     my($self) = @_;
  2745.     my(@m);
  2746.     if ($self->{ABSTRACT_FROM}){
  2747.         $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
  2748.             Carp::carp "WARNING: Setting ABSTRACT via file '$self->{ABSTRACT_FROM}' failed\n";
  2749.     }
  2750.     my ($pack_ver) = join ",", (split (/\./, $self->{VERSION}), (0) x 4) [0 .. 3];
  2751.     push(@m, "# Creates a PPD (Perl Package Description) for a binary distribution.\n");
  2752.     push(@m, "ppd:\n");
  2753.     push(@m, "\t\@\$(PERL) -e \"print qq{<SOFTPKG NAME=\\\"$self->{DISTNAME}\\\" VERSION=\\\"$pack_ver\\\">\\n}");
  2754.     push(@m, ". qq{\\t<TITLE>$self->{DISTNAME}</TITLE>\\n}");
  2755.     my $abstract = $self->{ABSTRACT};
  2756.     $abstract =~ s/\n/\\n/sg;
  2757.     $abstract =~ s/</</g;
  2758.     $abstract =~ s/>/>/g;
  2759.     push(@m, ". qq{\\t<ABSTRACT>$abstract</ABSTRACT>\\n}");
  2760.     my ($author) = $self->{AUTHOR};
  2761.     $author =~ s/</</g;
  2762.     $author =~ s/>/>/g;
  2763.     $author =~ s/@/\\@/g;
  2764.     push(@m, ". qq{\\t<AUTHOR>$author</AUTHOR>\\n}");
  2765.     push(@m, ". qq{\\t<IMPLEMENTATION>\\n}");
  2766.     my ($prereq);
  2767.     foreach $prereq (sort keys %{$self->{PREREQ_PM}}) {
  2768.         my $pre_req = $prereq;
  2769.         $pre_req =~ s/::/-/g;
  2770.         my ($dep_ver) = join ",", (split (/\./, $self->{PREREQ_PM}{$prereq}), (0) x 4) [0 .. 3];
  2771.         push(@m, ". qq{\\t\\t<DEPENDENCY NAME=\\\"$pre_req\\\" VERSION=\\\"$dep_ver\\\" />\\n}");
  2772.     }
  2773.     push(@m, ". qq{\\t\\t<OS NAME=\\\"\$(OSNAME)\\\" />\\n}");
  2774.     push(@m, ". qq{\\t\\t<ARCHITECTURE NAME=\\\"$Config{'archname'}\\\" />\\n}");
  2775.     my ($bin_location) = $self->{BINARY_LOCATION};
  2776.     $bin_location =~ s/\\/\\\\/g;
  2777.     if ($self->{PPM_INSTALL_SCRIPT}) {
  2778.         if ($self->{PPM_INSTALL_EXEC}) {
  2779.             push(@m, " . qq{\\t\\t<INSTALL EXEC=\\\"$self->{PPM_INSTALL_EXEC}\\\">$self->{PPM_INSTALL_SCRIPT}</INSTALL>\\n}");
  2780.         }
  2781.         else {
  2782.             push(@m, " . qq{\\t\\t<INSTALL>$self->{PPM_INSTALL_SCRIPT}</INSTALL>\\n}");
  2783.         }
  2784.     }
  2785.     push(@m, ". qq{\\t\\t<CODEBASE HREF=\\\"$bin_location\\\" />\\n}");
  2786.     push(@m, ". qq{\\t</IMPLEMENTATION>\\n}");
  2787.     push(@m, ". qq{</SOFTPKG>\\n}\" > $self->{DISTNAME}.ppd");
  2788.  
  2789.     join("", @m);   
  2790. }
  2791.  
  2792. =item perm_rw (o)
  2793.  
  2794. Returns the attribute C<PERM_RW> or the string C<644>.
  2795. Used as the string that is passed
  2796. to the C<chmod> command to set the permissions for read/writeable files.
  2797. MakeMaker chooses C<644> because it has turned out in the past that
  2798. relying on the umask provokes hard-to-track bug reports.
  2799. When the return value is used by the perl function C<chmod>, it is
  2800. interpreted as an octal value.
  2801.  
  2802. =cut
  2803.  
  2804. sub perm_rw {
  2805.     shift->{PERM_RW} || "644";
  2806. }
  2807.  
  2808. =item perm_rwx (o)
  2809.  
  2810. Returns the attribute C<PERM_RWX> or the string C<755>,
  2811. i.e. the string that is passed
  2812. to the C<chmod> command to set the permissions for executable files.
  2813. See also perl_rw.
  2814.  
  2815. =cut
  2816.  
  2817. sub perm_rwx {
  2818.     shift->{PERM_RWX} || "755";
  2819. }
  2820.  
  2821. =item pm_to_blib
  2822.  
  2823. Defines target that copies all files in the hash PM to their
  2824. destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
  2825.  
  2826. =cut
  2827.  
  2828. sub pm_to_blib {
  2829.     my $self = shift;
  2830.     my($autodir) = $self->catdir('$(INST_LIB)','auto');
  2831.     return q{
  2832. pm_to_blib: $(TO_INST_PM)
  2833.     }.$self->{NOECHO}.q{$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
  2834.     "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
  2835.         -e "pm_to_blib({qw{$(PM_TO_BLIB)}},'}.$autodir.q{')"
  2836.     }.$self->{NOECHO}.q{$(TOUCH) $@
  2837. };
  2838. }
  2839.  
  2840. =item post_constants (o)
  2841.  
  2842. Returns an empty string per default. Dedicated to overrides from
  2843. within Makefile.PL after all constants have been defined.
  2844.  
  2845. =cut
  2846.  
  2847. sub post_constants{
  2848.     my($self) = shift;
  2849.     "";
  2850. }
  2851.  
  2852. =item post_initialize (o)
  2853.  
  2854. Returns an empty string per default. Used in Makefile.PLs to add some
  2855. chunk of text to the Makefile after the object is initialized.
  2856.  
  2857. =cut
  2858.  
  2859. sub post_initialize {
  2860.     my($self) = shift;
  2861.     "";
  2862. }
  2863.  
  2864. =item postamble (o)
  2865.  
  2866. Returns an empty string. Can be used in Makefile.PLs to write some
  2867. text to the Makefile at the end.
  2868.  
  2869. =cut
  2870.  
  2871. sub postamble {
  2872.     my($self) = shift;
  2873.     "";
  2874. }
  2875.  
  2876. =item prefixify
  2877.  
  2878. Check a path variable in $self from %Config, if it contains a prefix,
  2879. and replace it with another one.
  2880.  
  2881. Takes as arguments an attribute name, a search prefix and a
  2882. replacement prefix. Changes the attribute in the object.
  2883.  
  2884. =cut
  2885.  
  2886. sub prefixify {
  2887.     my($self,$var,$sprefix,$rprefix) = @_;
  2888.     $self->{uc $var} ||= $Config{lc $var};
  2889.     $self->{uc $var} = VMS::Filespec::unixpath($self->{uc $var}) if $Is_VMS;
  2890.     $self->{uc $var} =~ s/\Q$sprefix\E/$rprefix/;
  2891. }
  2892.  
  2893. =item processPL (o)
  2894.  
  2895. Defines targets to run *.PL files.
  2896.  
  2897. =cut
  2898.  
  2899. sub processPL {
  2900.     my($self) = shift;
  2901.     return "" unless $self->{PL_FILES};
  2902.     my(@m, $plfile);
  2903.     foreach $plfile (sort keys %{$self->{PL_FILES}}) {
  2904.         my $list = ref($self->{PL_FILES}->{$plfile})
  2905.         ? $self->{PL_FILES}->{$plfile}
  2906.         : [$self->{PL_FILES}->{$plfile}];
  2907.     foreach $target (@$list) {
  2908.     push @m, "
  2909. all :: $target
  2910.     $self->{NOECHO}\$(NOOP)
  2911.  
  2912. $target :: $plfile
  2913.     \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile $target
  2914. ";
  2915.     }
  2916.     }
  2917.     join "", @m;
  2918. }
  2919.  
  2920. =item realclean (o)
  2921.  
  2922. Defines the realclean target.
  2923.  
  2924. =cut
  2925.  
  2926. sub realclean {
  2927.     my($self, %attribs) = @_;
  2928.     my(@m);
  2929.     push(@m,'
  2930. # Delete temporary files (via clean) and also delete installed files
  2931. realclean purge ::  clean
  2932. ');
  2933.     # realclean subdirectories first (already cleaned)
  2934.     my $sub = "\t-cd %s && \$(TEST_F) %s && \$(MAKE) %s realclean\n";
  2935.     foreach(@{$self->{DIR}}){
  2936.     push(@m, sprintf($sub,$_,"$self->{MAKEFILE}.old","-f $self->{MAKEFILE}.old"));
  2937.     push(@m, sprintf($sub,$_,"$self->{MAKEFILE}",''));
  2938.     }
  2939.     push(@m, "    $self->{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
  2940.     if( $self->has_link_code ){
  2941.         push(@m, "    $self->{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
  2942.         push(@m, "    $self->{RM_F} \$(INST_STATIC)\n");
  2943.     }
  2944.     push(@m, "    $self->{RM_F} " . join(" ", values %{$self->{PM}}) . "\n")
  2945.     if keys %{$self->{PM}};
  2946.     my(@otherfiles) = ($self->{MAKEFILE},
  2947.                "$self->{MAKEFILE}.old"); # Makefiles last
  2948.     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
  2949.     push(@m, "    $self->{RM_RF} @otherfiles\n") if @otherfiles;
  2950.     push(@m, "    $attribs{POSTOP}\n")       if $attribs{POSTOP};
  2951.     join("", @m);
  2952. }
  2953.  
  2954. =item replace_manpage_separator
  2955.  
  2956. Takes the name of a package, which may be a nested package, in the
  2957. form Foo/Bar and replaces the slash with C<::>. Returns the replacement.
  2958.  
  2959. =cut
  2960.  
  2961. sub replace_manpage_separator {
  2962.     my($self,$man) = @_;
  2963.     if ($^O eq 'uwin') {
  2964.         $man =~ s,/+,.,g;
  2965.     } else {
  2966.         $man =~ s,/+,::,g;
  2967.     }
  2968.     $man;
  2969. }
  2970.  
  2971. =item static (o)
  2972.  
  2973. Defines the static target.
  2974.  
  2975. =cut
  2976.  
  2977. sub static {
  2978. # --- Static Loading Sections ---
  2979.  
  2980.     my($self) = shift;
  2981.     '
  2982. ## $(INST_PM) has been moved to the all: target.
  2983. ## It remains here for awhile to allow for old usage: "make static"
  2984. #static :: '.$self->{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
  2985. static :: '.$self->{MAKEFILE}.' $(INST_STATIC)
  2986.     '.$self->{NOECHO}.'$(NOOP)
  2987. ';
  2988. }
  2989.  
  2990. =item static_lib (o)
  2991.  
  2992. Defines how to produce the *.a (or equivalent) files.
  2993.  
  2994. =cut
  2995.  
  2996. sub static_lib {
  2997.     my($self) = @_;
  2998. # Come to think of it, if there are subdirs with linkcode, we still have no INST_STATIC
  2999. #    return '' unless $self->needs_linking(); #might be because of a subdir
  3000.  
  3001.     return '' unless $self->has_link_code;
  3002.  
  3003.     my(@m);
  3004.     push(@m, <<'END');
  3005. $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
  3006.     $(RM_RF) $@
  3007. END
  3008.     # If this extension has it's own library (eg SDBM_File)
  3009.     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
  3010.     push(@m, "\t$self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
  3011.  
  3012.     push @m,
  3013. q{    $(AR) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@
  3014.     $(CHMOD) $(PERM_RWX) $@
  3015.     }.$self->{NOECHO}.q{echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
  3016. };
  3017.     # Old mechanism - still available:
  3018.     push @m,
  3019. "\t$self->{NOECHO}".q{echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
  3020. }    if $self->{PERL_SRC} && $self->{EXTRALIBS};
  3021.     push @m, "\n";
  3022.  
  3023.     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
  3024.     join('', "\n",@m);
  3025. }
  3026.  
  3027. =item staticmake (o)
  3028.  
  3029. Calls makeaperl.
  3030.  
  3031. =cut
  3032.  
  3033. sub staticmake {
  3034.     my($self, %attribs) = @_;
  3035.     my(@static);
  3036.  
  3037.     my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
  3038.  
  3039.     # And as it's not yet built, we add the current extension
  3040.     # but only if it has some C code (or XS code, which implies C code)
  3041.     if (@{$self->{C}}) {
  3042.     @static = $self->catfile($self->{INST_ARCHLIB},
  3043.                  "auto",
  3044.                  $self->{FULLEXT},
  3045.                  "$self->{BASEEXT}$self->{LIB_EXT}"
  3046.                 );
  3047.     }
  3048.  
  3049.     # Either we determine now, which libraries we will produce in the
  3050.     # subdirectories or we do it at runtime of the make.
  3051.  
  3052.     # We could ask all subdir objects, but I cannot imagine, why it
  3053.     # would be necessary.
  3054.  
  3055.     # Instead we determine all libraries for the new perl at
  3056.     # runtime.
  3057.     my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
  3058.  
  3059.     $self->makeaperl(MAKE    => $self->{MAKEFILE},
  3060.              DIRS    => \@searchdirs,
  3061.              STAT    => \@static,
  3062.              INCL    => \@perlinc,
  3063.              TARGET    => $self->{MAP_TARGET},
  3064.              TMP    => "",
  3065.              LIBPERL    => $self->{LIBPERL_A}
  3066.             );
  3067. }
  3068.  
  3069. =item subdir_x (o)
  3070.  
  3071. Helper subroutine for subdirs
  3072.  
  3073. =cut
  3074.  
  3075. sub subdir_x {
  3076.     my($self, $subdir) = @_;
  3077.     my(@m);
  3078.     qq{
  3079.  
  3080. subdirs ::
  3081.     $self->{NOECHO}cd $subdir && \$(MAKE) all \$(PASTHRU)
  3082.  
  3083. };
  3084. }
  3085.  
  3086. =item subdirs (o)
  3087.  
  3088. Defines targets to process subdirectories.
  3089.  
  3090. =cut
  3091.  
  3092. sub subdirs {
  3093. # --- Sub-directory Sections ---
  3094.     my($self) = shift;
  3095.     my(@m,$dir);
  3096.     # This method provides a mechanism to automatically deal with
  3097.     # subdirectories containing further Makefile.PL scripts.
  3098.     # It calls the subdir_x() method for each subdirectory.
  3099.     foreach $dir (@{$self->{DIR}}){
  3100.     push(@m, $self->subdir_x($dir));
  3101. ####    print "Including $dir subdirectory\n";
  3102.     }
  3103.     if (@m){
  3104.     unshift(@m, "
  3105. # The default clean, realclean and test targets in this Makefile
  3106. # have automatically been given entries for each subdir.
  3107.  
  3108. ");
  3109.     } else {
  3110.     push(@m, "\n# none")
  3111.     }
  3112.     join('',@m);
  3113. }
  3114.  
  3115. =item test (o)
  3116.  
  3117. Defines the test targets.
  3118.  
  3119. =cut
  3120.  
  3121. sub test {
  3122. # --- Test and Installation Sections ---
  3123.  
  3124.     my($self, %attribs) = @_;
  3125.     my $tests = $attribs{TESTS};
  3126.     if (!$tests && -d 't') {
  3127.     $tests = $Is_Win32 ? join(' ', <t\\*.t>) : 't/*.t';
  3128.     }
  3129.     # note: 'test.pl' name is also hardcoded in init_dirscan()
  3130.     my(@m);
  3131.     push(@m,"
  3132. TEST_VERBOSE=0
  3133. TEST_TYPE=test_\$(LINKTYPE)
  3134. TEST_FILE = test.pl
  3135. TEST_FILES = $tests
  3136. TESTDB_SW = -d
  3137.  
  3138. testdb :: testdb_\$(LINKTYPE)
  3139.  
  3140. test :: \$(TEST_TYPE)
  3141. ");
  3142.     push(@m, map("\t$self->{NOECHO}cd $_ && \$(TEST_F) $self->{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
  3143.          @{$self->{DIR}}));
  3144.     push(@m, "\t$self->{NOECHO}echo 'No tests defined for \$(NAME) extension.'\n")
  3145.     unless $tests or -f "test.pl" or @{$self->{DIR}};
  3146.     push(@m, "\n");
  3147.  
  3148.     push(@m, "test_dynamic :: pure_all\n");
  3149.     push(@m, $self->test_via_harness('$(FULLPERL)', '$(TEST_FILES)')) if $tests;
  3150.     push(@m, $self->test_via_script('$(FULLPERL)', '$(TEST_FILE)')) if -f "test.pl";
  3151.     push(@m, "\n");
  3152.  
  3153.     push(@m, "testdb_dynamic :: pure_all\n");
  3154.     push(@m, $self->test_via_script('$(FULLPERL) $(TESTDB_SW)', '$(TEST_FILE)'));
  3155.     push(@m, "\n");
  3156.  
  3157.     # Occasionally we may face this degenerate target:
  3158.     push @m, "test_ : test_dynamic\n\n";
  3159.  
  3160.     if ($self->needs_linking()) {
  3161.     push(@m, "test_static :: pure_all \$(MAP_TARGET)\n");
  3162.     push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests;
  3163.     push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl";
  3164.     push(@m, "\n");
  3165.     push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n");
  3166.     push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)'));
  3167.     push(@m, "\n");
  3168.     } else {
  3169.     push @m, "test_static :: test_dynamic\n";
  3170.     push @m, "testdb_static :: testdb_dynamic\n";
  3171.     }
  3172.     join("", @m);
  3173. }
  3174.  
  3175. =item test_via_harness (o)
  3176.  
  3177. Helper method to write the test targets
  3178.  
  3179. =cut
  3180.  
  3181. sub test_via_harness {
  3182.     my($self, $perl, $tests) = @_;
  3183.     $perl = "PERL_DL_NONLAZY=1 $perl" unless $Is_Win32;
  3184.     "\t$perl".q! -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e 'use Test::Harness qw(&runtests $$verbose); $$verbose=$(TEST_VERBOSE); runtests @ARGV;' !."$tests\n";
  3185. }
  3186.  
  3187. =item test_via_script (o)
  3188.  
  3189. Other helper method for test.
  3190.  
  3191. =cut
  3192.  
  3193. sub test_via_script {
  3194.     my($self, $perl, $script) = @_;
  3195.     $perl = "PERL_DL_NONLAZY=1 $perl" unless $Is_Win32;
  3196.     qq{\t$perl}.q{ -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) }.qq{$script
  3197. };
  3198. }
  3199.  
  3200. =item tool_autosplit (o)
  3201.  
  3202. Defines a simple perl call that runs autosplit. May be deprecated by
  3203. pm_to_blib soon.
  3204.  
  3205. =cut
  3206.  
  3207. sub tool_autosplit {
  3208. # --- Tool Sections ---
  3209.  
  3210.     my($self, %attribs) = @_;
  3211.     my($asl) = "";
  3212.     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
  3213.     q{
  3214. # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
  3215. AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
  3216. };
  3217. }
  3218.  
  3219. =item tools_other (o)
  3220.  
  3221. Defines SHELL, LD, TOUCH, CP, MV, RM_F, RM_RF, CHMOD, UMASK_NULL in
  3222. the Makefile. Also defines the perl programs MKPATH,
  3223. WARN_IF_OLD_PACKLIST, MOD_INSTALL. DOC_INSTALL, and UNINSTALL.
  3224.  
  3225. =cut
  3226.  
  3227. sub tools_other {
  3228.     my($self) = shift;
  3229.     my @m;
  3230.     my $bin_sh = $Config{sh} || '/bin/sh';
  3231.     push @m, qq{
  3232. SHELL = $bin_sh
  3233. };
  3234.  
  3235.     for (qw/ CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL/ ) {
  3236.     push @m, "$_ = $self->{$_}\n";
  3237.     }
  3238.  
  3239.     push @m, q{
  3240. # The following is a portable way to say mkdir -p
  3241. # To see which directories are created, change the if 0 to if 1
  3242. MKPATH = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e mkpath
  3243.  
  3244. # This helps us to minimize the effect of the .exists files A yet
  3245. # better solution would be to have a stable file in the perl
  3246. # distribution with a timestamp of zero. But this solution doesn't
  3247. # need any changes to the core distribution and works with older perls
  3248. EQUALIZE_TIMESTAMP = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e eqtime
  3249. };
  3250.  
  3251.  
  3252.     return join "", @m if $self->{PARENT};
  3253.  
  3254.     push @m, q{
  3255. # Here we warn users that an old packlist file was found somewhere,
  3256. # and that they should call some uninstall routine
  3257. WARN_IF_OLD_PACKLIST = $(PERL) -we 'exit unless -f $$ARGV[0];' \\
  3258. -e 'print "WARNING: I have found an old package in\n";' \\
  3259. -e 'print "\t$$ARGV[0].\n";' \\
  3260. -e 'print "Please make sure the two installations are not conflicting\n";'
  3261.  
  3262. UNINST=0
  3263. VERBINST=1
  3264.  
  3265. MOD_INSTALL = $(PERL) -I$(INST_LIB) -I$(PERL_LIB) -MExtUtils::Install \
  3266. -e "install({@ARGV},'$(VERBINST)',0,'$(UNINST)');"
  3267.  
  3268. DOC_INSTALL = $(PERL) -e '$$\="\n\n";' \
  3269. -e 'print "=head2 ", scalar(localtime), ": C<", shift, ">", " L<", shift, ">";' \
  3270. -e 'print "=over 4";' \
  3271. -e 'while (defined($$key = shift) and defined($$val = shift)){print "=item *";print "C<$$key: $$val>";}' \
  3272. -e 'print "=back";'
  3273.  
  3274. UNINSTALL =   $(PERL) -MExtUtils::Install \
  3275. -e 'uninstall($$ARGV[0],1,1); print "\nUninstall is deprecated. Please check the";' \
  3276. -e 'print " packlist above carefully.\n  There may be errors. Remove the";' \
  3277. -e 'print " appropriate files manually.\n  Sorry for the inconveniences.\n"'
  3278. };
  3279.  
  3280.     return join "", @m;
  3281. }
  3282.  
  3283. =item tool_xsubpp (o)
  3284.  
  3285. Determines typemaps, xsubpp version, prototype behaviour.
  3286.  
  3287. =cut
  3288.  
  3289. sub tool_xsubpp {
  3290.     my($self) = shift;
  3291.     return "" unless $self->needs_linking;
  3292.     my($xsdir)  = $self->catdir($self->{PERL_LIB},"ExtUtils");
  3293.     my(@tmdeps) = $self->catdir('$(XSUBPPDIR)','typemap');
  3294.     if( $self->{TYPEMAPS} ){
  3295.     my $typemap;
  3296.     foreach $typemap (@{$self->{TYPEMAPS}}){
  3297.         if( ! -f  $typemap ){
  3298.             warn "Typemap $typemap not found.\n";
  3299.         }
  3300.         else{
  3301.             push(@tmdeps,  $typemap);
  3302.         }
  3303.     }
  3304.     }
  3305.     push(@tmdeps, "typemap") if -f "typemap";
  3306.     my(@tmargs) = map("-typemap $_", @tmdeps);
  3307.     if( exists $self->{XSOPT} ){
  3308.      unshift( @tmargs, $self->{XSOPT} );
  3309.     }
  3310.  
  3311.  
  3312.     my $xsubpp_version = $self->xsubpp_version($self->catfile($xsdir,"xsubpp"));
  3313.  
  3314.     # What are the correct thresholds for version 1 && 2 Paul?
  3315.     if ( $xsubpp_version > 1.923 ){
  3316.     $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
  3317.     } else {
  3318.     if (defined $self->{XSPROTOARG} && $self->{XSPROTOARG} =~ /\-prototypes/) {
  3319.         print STDOUT qq{Warning: This extension wants to pass the switch "-prototypes" to xsubpp.
  3320.     Your version of xsubpp is $xsubpp_version and cannot handle this.
  3321.     Please upgrade to a more recent version of xsubpp.
  3322. };
  3323.     } else {
  3324.         $self->{XSPROTOARG} = "";
  3325.     }
  3326.     }
  3327.  
  3328.     my $xsubpp = $self->{CAPI} ? "xsubpp -object_capi" : "xsubpp";
  3329.  
  3330.     return qq{
  3331. XSUBPPDIR = $xsdir
  3332. XSUBPP = \$(XSUBPPDIR)/$xsubpp
  3333. XSPROTOARG = $self->{XSPROTOARG}
  3334. XSUBPPDEPS = @tmdeps
  3335. XSUBPPARGS = @tmargs
  3336. };
  3337. };
  3338.  
  3339. sub xsubpp_version
  3340. {
  3341.     my($self,$xsubpp) = @_;
  3342.     return $Xsubpp_Version if defined $Xsubpp_Version; # global variable
  3343.  
  3344.     my ($version) ;
  3345.  
  3346.     # try to figure out the version number of the xsubpp on the system
  3347.  
  3348.     # first try the -v flag, introduced in 1.921 & 2.000a2
  3349.  
  3350.     return "" unless $self->needs_linking;
  3351.  
  3352.     my $command = "$self->{PERL} -I$self->{PERL_LIB} $xsubpp -v 2>&1";
  3353.     print "Running $command\n" if $Verbose >= 2;
  3354.     $version = `$command` ;
  3355.     warn "Running '$command' exits with status " . ($?>>8) if $?;
  3356.     chop $version ;
  3357.  
  3358.     return $Xsubpp_Version = $1 if $version =~ /^xsubpp version (.*)/ ;
  3359.  
  3360.     # nope, then try something else
  3361.  
  3362.     my $counter = '000';
  3363.     my ($file) = 'temp' ;
  3364.     $counter++ while -e "$file$counter"; # don't overwrite anything
  3365.     $file .= $counter;
  3366.  
  3367.     open(F, ">$file") or die "Cannot open file '$file': $!\n" ;
  3368.     print F <<EOM ;
  3369. MODULE = fred PACKAGE = fred
  3370.  
  3371. int
  3372. fred(a)
  3373.         int     a;
  3374. EOM
  3375.  
  3376.     close F ;
  3377.  
  3378.     $command = "$self->{PERL} $xsubpp $file 2>&1";
  3379.     print "Running $command\n" if $Verbose >= 2;
  3380.     my $text = `$command` ;
  3381.     warn "Running '$command' exits with status " . ($?>>8) if $?;
  3382.     unlink $file ;
  3383.  
  3384.     # gets 1.2 -> 1.92 and 2.000a1
  3385.     return $Xsubpp_Version = $1 if $text =~ /automatically by xsubpp version ([\S]+)\s*/  ;
  3386.  
  3387.     # it is either 1.0 or 1.1
  3388.     return $Xsubpp_Version = 1.1 if $text =~ /^Warning: ignored semicolon/ ;
  3389.  
  3390.     # none of the above, so 1.0
  3391.     return $Xsubpp_Version = "1.0" ;
  3392. }
  3393.  
  3394. =item top_targets (o)
  3395.  
  3396. Defines the targets all, subdirs, config, and O_FILES
  3397.  
  3398. =cut
  3399.  
  3400. sub top_targets {
  3401. # --- Target Sections ---
  3402.  
  3403.     my($self) = shift;
  3404.     my(@m);
  3405.     push @m, '
  3406. #all ::    config $(INST_PM) subdirs linkext manifypods
  3407. ';
  3408.  
  3409.     push @m, '
  3410. all :: pure_all manifypods
  3411.     '.$self->{NOECHO}.'$(NOOP)
  3412.       unless $self->{SKIPHASH}{'all'};
  3413.     
  3414.     push @m, '
  3415. pure_all :: config pm_to_blib subdirs linkext
  3416.     '.$self->{NOECHO}.'$(NOOP)
  3417.  
  3418. subdirs :: $(MYEXTLIB)
  3419.     '.$self->{NOECHO}.'$(NOOP)
  3420.  
  3421. config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)/.exists
  3422.     '.$self->{NOECHO}.'$(NOOP)
  3423.  
  3424. config :: $(INST_ARCHAUTODIR)/.exists
  3425.     '.$self->{NOECHO}.'$(NOOP)
  3426.  
  3427. config :: $(INST_AUTODIR)/.exists
  3428.     '.$self->{NOECHO}.'$(NOOP)
  3429. ';
  3430.  
  3431.     push @m, qq{
  3432. config :: Version_check
  3433.     $self->{NOECHO}\$(NOOP)
  3434.  
  3435. } unless $self->{PARENT} or ($self->{PERL_SRC} && $self->{INSTALLDIRS} eq "perl") or $self->{NO_VC};
  3436.  
  3437.     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
  3438.  
  3439.     if (%{$self->{MAN1PODS}}) {
  3440.     push @m, qq[
  3441. config :: \$(INST_MAN1DIR)/.exists
  3442.     $self->{NOECHO}\$(NOOP)
  3443.  
  3444. ];
  3445.     push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
  3446.     }
  3447.     if (%{$self->{MAN3PODS}}) {
  3448.     push @m, qq[
  3449. config :: \$(INST_MAN3DIR)/.exists
  3450.     $self->{NOECHO}\$(NOOP)
  3451.  
  3452. ];
  3453.     push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
  3454.     }
  3455.  
  3456.     push @m, '
  3457. $(O_FILES): $(H_FILES)
  3458. ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
  3459.  
  3460.     push @m, q{
  3461. help:
  3462.     perldoc ExtUtils::MakeMaker
  3463. };
  3464.  
  3465.     push @m, q{
  3466. Version_check:
  3467.     }.$self->{NOECHO}.q{$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
  3468.         -MExtUtils::MakeMaker=Version_check \
  3469.         -e "Version_check('$(MM_VERSION)')"
  3470. };
  3471.  
  3472.     join('',@m);
  3473. }
  3474.  
  3475. =item writedoc
  3476.  
  3477. Obsolete, deprecated method. Not used since Version 5.21.
  3478.  
  3479. =cut
  3480.  
  3481. sub writedoc {
  3482. # --- perllocal.pod section ---
  3483.     my($self,$what,$name,@attribs)=@_;
  3484.     my $time = localtime;
  3485.     print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
  3486.     print join "\n\n=item *\n\n", map("C<$_>",@attribs);
  3487.     print "\n\n=back\n\n";
  3488. }
  3489.  
  3490. =item xs_c (o)
  3491.  
  3492. Defines the suffix rules to compile XS files to C.
  3493.  
  3494. =cut
  3495.  
  3496. sub xs_c {
  3497.     my($self) = shift;
  3498.     return '' unless $self->needs_linking();
  3499.     '
  3500. .xs.c:
  3501.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.c
  3502. ';
  3503. }
  3504.  
  3505. =item xs_cpp (o)
  3506.  
  3507. Defines the suffix rules to compile XS files to C++.
  3508.  
  3509. =cut
  3510.  
  3511. sub xs_cpp {
  3512.     my($self) = shift;
  3513.     return '' unless $self->needs_linking();
  3514.     '
  3515. .xs.cpp:
  3516.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.cpp
  3517. ';
  3518. }
  3519.  
  3520. =item xs_o (o)
  3521.  
  3522. Defines suffix rules to go from XS to object files directly. This is
  3523. only intended for broken make implementations.
  3524.  
  3525. =cut
  3526.  
  3527. sub xs_o {    # many makes are too dumb to use xs_c then c_o
  3528.     my($self) = shift;
  3529.     return '' unless $self->needs_linking();
  3530.     '
  3531. .xs$(OBJ_EXT):
  3532.     $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) $(XSPROTOARG) $(XSUBPPARGS) $*.xs >xstmp.c && $(MV) xstmp.c $*.c
  3533.     $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
  3534. ';
  3535. }
  3536.  
  3537. =item perl_archive
  3538.  
  3539. This is internal method that returns path to libperl.a equivalent
  3540. to be linked to dynamic extensions. UNIX does not have one but OS2
  3541. and Win32 do.
  3542.  
  3543. =cut 
  3544.  
  3545. sub perl_archive
  3546. {
  3547.  return '$(PERL_INC)' . "/$Config{libperl}" if $^O eq "beos";
  3548.  return "";
  3549. }
  3550.  
  3551. =item export_list
  3552.  
  3553. This is internal method that returns name of a file that is
  3554. passed to linker to define symbols to be exported.
  3555. UNIX does not have one but OS2 and Win32 do.
  3556.  
  3557. =cut 
  3558.  
  3559. sub export_list
  3560. {
  3561.  return "";
  3562. }
  3563.  
  3564.  
  3565. 1;
  3566.  
  3567. =back
  3568.  
  3569. =head1 SEE ALSO
  3570.  
  3571. L<ExtUtils::MakeMaker>
  3572.  
  3573. =cut
  3574.  
  3575. __END__
  3576.