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