1 package ExtUtils::MakeMaker;
3 $Version = 4.01; # Last edited 25th Jan 1995 by Tim Bunce
11 @EXPORT = qw(&WriteMakefile &mkbootstrap $Verbose);
12 @EXPORT_OK = qw($Version %att %skip %Recognized_Att_Keys
13 @MM_Sections %MM_Sections
16 $Is_VMS = $Config{'osname'} eq 'VMS';
17 require ExtUtils::MM_VMS if $Is_VMS;
21 $Version = $Version;# avoid typo warning
28 ExtUtils::MakeMaker - create an extension Makefile
32 use ExtUtils::MakeMaker;
34 WriteMakefile( ATTRIBUTE => VALUE [, ...] );
38 This utility is designed to write a Makefile for an extension module
39 from a Makefile.PL. It is based on the Makefile.SH model provided by
40 Andy Dougherty and the perl5-porters.
42 It splits the task of generating the Makefile into several subroutines
43 that can be individually overridden. Each subroutine returns the text
44 it wishes to have written to the Makefile.
46 =head2 Default Makefile Behaviour
48 The automatically generated Makefile enables the user of the extension
54 make install # May need to invoke as root to write into INST_LIB
56 The Makefile to be produced may be altered by adding arguments of the
57 form C<KEY=VALUE>. If the user wants to have the extension installed
58 into a directory different from C<$Config{"installprivlib"}> it can be
61 perl Makefile.PL INST_LIB=~/myperllib
63 Note, that in this example MakeMaker does the tilde expansion for you
64 and INST_ARCHLIB is set to either C<INST_LIB/$Config{"osname"}> if
65 that directory exists and otherwise to INST_LIB.
67 Other interesting targets in the generated Makefile are
69 make config # to check if the Makefile is up-to-date
70 make clean # delete local temporary files (Makefile gets renamed)
71 make realclean # delete all derived files (including installed files)
72 make distclean # produce a gzipped file ready for shipping
74 The macros in the produced Makefile may be overriden on the command
75 line to the make call like:
77 make INST_LIB=/some/where INST_ARCHLIB=/some/where
79 Note, that this is a solution provided by C<make> in general, so tilde
80 expansion will probably not be available and INST_ARCHLIB will not be
81 set automatically when INST_LIB is given as argument.
83 (This section is yet to be completed ...)
85 =head2 Determination of Perl Library and Installation Locations
87 MakeMaker needs to know, or to guess, where certain things are located.
88 Especially INST_LIB, INST_ARCHLIB, PERL_LIB, PERL_ARCHLIB and PERL_SRC.
90 Extensions may be built either using the contents of the perl source
91 directory tree or from an installed copy of the perl library.
93 If an extension is being built below the C<ext/> directory of the perl
94 source then MakeMaker will set PERL_SRC automatically (e.g., C<../..>).
95 If PERL_SRC is defined then other variables default to the following:
98 PERL_LIB = PERL_SRC/lib
99 PERL_ARCHLIB = PERL_SRC/lib
101 INST_ARCHLIB = PERL_ARCHLIB
103 If an extension is being built away from the perl source then MakeMaker
104 will leave PERL_SRC undefined and default to using the installed copy
105 of the perl library. The other variables default to the following:
107 PERL_INC = $archlib/CORE
109 PERL_ARCHLIB = $archlib
111 INST_ARCHLIB = ./blib
113 If perl has not yet been installed then PERL_SRC can be defined on the
114 command line as shown in the previous section.
116 =head2 Useful Default Makefile Macros
118 FULLEXT = Pathname for extension directory (eg DBD/Oracle).
120 BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
122 ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
124 PERL_LIB = Directory where we read the perl library files
126 PERL_ARCHLIB = Same as above for architecture dependent files
128 INST_LIB = Directory where we put library files of this extension
129 while building it. If we are building below PERL_SRC/ext
130 we default to PERL_SRC/lib, else we default to ./blib.
132 INST_ARCHLIB = Same as above for architecture dependent files
134 INST_LIBDIR = $(INST_LIB)$(ROOTEXT)
136 INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
138 INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
140 =head2 Customizing The Generated Makefile
142 If the Makefile generated does not fit your purpose you can change it
143 using the mechanisms described below.
145 =head2 Using Attributes (and Parameters)
147 The following attributes can be specified as arguments to WriteMakefile()
148 or as NAME=VALUE pairs on the command line:
150 This description is not yet documented; you can get at the description
152 perl Makefile.PL help (if you already have a basic Makefile.PL)
153 or perl -e 'use ExtUtils::MakeMaker qw(&help); &help;'
155 =head2 Overriding MakeMaker Methods
157 If you cannot achieve the desired Makefile behaviour by specifying
158 attributes you may define private subroutines in the Makefile.PL.
159 Each subroutines returns the text it wishes to have written to
160 the Makefile. To override a section of the Makefile you can
163 sub MY::c_o { "new literal text" }
165 or you can edit the default by saying something like:
167 sub MY::c_o { $_=MM->c_o; s/old text/new text/; $_ }
169 If you still need a different solution, try to develop another
170 subroutine, that fits your needs and submit the diffs to
171 perl5-porters@nicoh.com or comp.lang.perl as appropriate.
176 Andy Dougherty <doughera@lafcol.lafayette.edu>, Andreas Koenig
177 <k@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk>
179 =head1 MODIFICATION HISTORY
181 v1, August 1994; by Andreas Koenig. Based on Andy Dougherty's Makefile.SH.
182 v2, September 1994 by Tim Bunce.
183 v3.0 October 1994 by Tim Bunce.
184 v3.1 November 11th 1994 by Tim Bunce.
185 v3.2 November 18th 1994 by Tim Bunce.
186 v3.3 November 27th 1994 by Andreas Koenig.
187 v3.4 December 7th 1994 by Andreas Koenig and Tim Bunce.
188 v3.5 December 15th 1994 by Tim Bunce.
189 v3.6 December 15th 1994 by Tim Bunce.
190 v3.7 December 30th 1994 By Tim Bunce
191 v3.8 January 17th 1995 By Andreas Koenig and Tim Bunce
193 - Introduces ./blib as the directory, where the ready-to-use module
194 will live for the time of the building process if PERL_SRC/lib is not
195 available. ./blib is turned into an absolute pathname and gets passed
196 to subdirectories when writing the Makefile.
198 - INST_ARCHLIB will now be set equal to INST_LIB if we cannot
199 determine it with the methods near line 620 (in the intialize
202 - Introduced the install subroutine, that calls another make
203 recursively with INST_LIB, and INST_ARCHLIB set according to the local
206 - Since version 3.6 all *.al and *.ix files are installed into
207 $installprivlib. In perl5.000 they were installed into
208 $installarchlib. Version 3.8 takes precautions to delete old *.{al,ix}
209 files that are left over in $installarchlib. Installperl is also
210 patched to both delete old *.al and *.ix files, that were put into
211 $installarchlib, and to install them properly from now on.
213 - h2xs is patched by Dean Roehrich to reintroduce the C<-A> option and
214 reconsiders the use of the AutoLoader. Also podifies h2xs.
216 - Patches to {DB_File,Fcntl,GDBM_File,POSIX,Socket}.pm, eliminating
217 AutoLoader from @ISA (by Dean Roehrich).
219 - A patch to AutoSplit.pm makes sure, the target directory of the
222 - installperl now installs all *.h files into $installarchlib/CORE.
224 - added a simple help function
228 Turned two constants into package variables.
229 Modified the default for &autosplit to be $CheckModTime=1.
230 Added warning and comment if auto dir does not exist.
231 Enhanced AutoLoader check (POSIX.pm was not getting AutoSplit!)
232 Improved logging if $Verbose>=2.
236 EXPORT_OK lsdir(), it's very handy.
237 Deleted much of the early revision history.
238 Changed LDTARGET (bad name) to LDFROM (better, but not great :)
239 INST_ARCHLIB for ./blib found via mapping from INST_LIB ./blib
240 (this allows error message if INST_ARCHLIB still undefined)
241 Added optional regex filter to &lsdir.
242 Added cute auto handling of a ./$(BASEEXT)/*.pm directory as
243 per recent messages with Nick re ext/nTk/nTk/Text.pm
244 Added NOOP, RM_F, RM_RF, TOUCH, CP to %att.
245 NOOP is now "" on Unix, "<tab>" caused problems (see makefile section)
246 RM_F etc now expanded when Makefile written.
247 Old AUTOSPLITLIB definition deleted.
248 See new dynamic_lib section for new ARMAYBE handling.
249 install section now uses $(INSTALLPRIVLIB) because on some
250 systems INSTALLPRIVLIB != PRIVLIB (ditto for archlib)
252 v3.9 January 19th 1995 By Tim Bunce
254 Added ~ processing to parse_args to allow perl Makefile.PL X=~/path.
255 Added warning about LDTARGET to LDFROM attribute name change.
256 Fallback INST_ARCHLIB is INST_LIB, or INST_LIB/$archname if it exists.
257 Tightened up dependency checking of Makefile against config.sh etc.
258 INST_STATIC is now INST_ARCHLIBDIR/BASEEXT.a for later make-a-perl.
259 AUTOSPLITFILE tidied up (AutoSplit patch included in this version).
260 MKPATH now skips inner loop if directory already exists.
261 The dynamic_lib section was revised with explicit dec_osf support added.
262 Make clean now renames Makefile to Makefile.old (make_ext also patched).
263 The large initialize function has been split into smaller pieces.
264 Added I_PERL_LIBS to simplify -I paths for PERL_*LIB.
266 v3.10 January 23rd 1995 By Tim Bunce
268 miniperl now given preference when defining PERL. This improves the
269 reliability of ext/*/Makefile's recreating themselves if needed.
270 $(XS), $(C) and $(H) renamed to XS_FILES C_FILES and H_FILES.
271 INST_STATIC now INST_ARCHLIBDIR/BASEEXT.a (alongside INST_DYNAMIC).
272 Static lib no longer copied back to local directory.
274 v3.11 January 24th 1995 By Andreas Koenig
276 DynaLoader.c was not deleted by clean target, now fixed.
277 Added PMDIR attribute that allows directories to be named that contain
278 only *.p[pl] files to be installed into INST_LIB. Added some documentation.
280 v4.00 January 24th 1995 By Tim Bunce
282 Revised some of the documentation. Changed version number to 4.00 to
283 avoid problems caused by my earlier poor choice of 3.10! Renamed PMDIR
284 to PMLIBDIRS and restructured find code to use inherited MY->libscan.
285 Added ability to say: "perl Makefile.PL help" to get help.
286 Added ability to say: "perl Makefile.PL verbose" to get debugging.
287 Added MakeMaker version number to generated Makefiles.
291 MakeMaker development work still to be done:
293 Needs more complete documentation.
295 Add method to take a list of files and wrap it in a Makefile
296 compatible way (<space><backslash><newline><tab>).
298 Add a html: target when there has been found a general solution to
299 installing html files.
304 # Setup dummy package:
305 # MY exists for overriding methods to be defined within
306 unshift(@MY::ISA, qw(MM));
308 # Dummy package MM inherits actual methods from OS-specific
309 # default packages. We use this intermediate package so
310 # MY->func() can call MM->func() and get the proper
311 # default routine without having to know under what OS
313 unshift(@MM::ISA, $Is_VMS ? qw(ExtUtils::MM_VMS MM_Unix) : qw(MM_Unix));
315 $Attrib_Help = <<'END';
316 NAME: Perl module name for this extension (DBD::Oracle)
317 This will default to the directory name but should
318 be explicitly defined in the Makefile.PL.
320 DISTNAME: Your name for distributing the package (by tar file)
321 This defaults to NAME above.
323 VERSION: Your version number for distributing the package.
324 This defaults to 0.1.
326 INST_LIB: Perl library directory to install the module into.
327 INST_ARCHLIB: Perl architecture-dependent library to install into
328 (defaults to INST_LIB)
330 PERL_LIB: Directory containing the Perl library to use.
331 PERL_SRC: Directory containing the Perl source code
332 (use of this should be avoided, it may be undefined)
334 INC: Include file dirs eg: '-I/usr/5include -I/path/to/inc'
335 DEFINE: something like "-DHAVE_UNISTD_H"
336 OBJECT: List of object files, defaults to '$(BASEEXT).o',
337 but can be a long string containing all object files,
338 e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
339 MYEXTLIB: If the extension links to a library that it builds
340 set this to the name of the library (see SDBM_File)
342 LIBS: An anonymous array of alternative library specifications
343 to be searched for (in order) until at least one library
345 'LIBS' => [ "-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs" ]
346 Mind, that any element of the array contains a complete
347 set of arguments for the ld command. So do not specify
348 'LIBS' => ["-ltcl", "-ltk", "-lX11" ], #wrong
349 See ODBM_File/Makefile.PL for an example, where an
350 array is needed. If you specify a scalar as in
351 'LIBS' => "-ltcl -ltk -lX11"
352 MakeMaker will turn it into an array with one element.
354 LDFROM: defaults to "$(OBJECT)" and is used in the ld command
355 to specify what files to link/load from
356 (also see dynamic_lib below for how to specify ld flags)
358 DIR: Ref to array of subdirectories containing Makefile.PLs
359 e.g. [ 'sdbm' ] in ext/SDBM_File
361 PMLIBDIRS: Ref to array of subdirectories containing library files.
362 Defaults to [ 'lib', $(BASEEXT) ]. The directories will
363 be scanned and any *.pm and *.pl files they contain will
364 be installed in the corresponding location in the library.
365 A MY::libscan() function can be used to alter the behaviour.
366 Defining PM in the Makefile.PL will override PMLIBDIRS.
368 PM: Hashref of .pm files and *.pl files to be installed.
369 e.g. { 'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm' }
370 By default this will include *.pm and *.pl. If a lib directory
371 exists and is not listed in DIR (above) then any *.pm and
372 *.pl files it contains will also be included by default.
373 Defining PM in the Makefile.PL will override PMLIBDIRS.
375 XS: Hashref of .xs files. MakeMaker will default this.
376 e.g. { 'name_of_file.xs' => 'name_of_file.c' }
377 The .c files will automatically be included in the list
378 of files deleted by a make clean.
380 C: Ref to array of *.c file names. Initialised from a directory scan
381 and the values portion of the XS attribute hash. This is not
382 currently used by MakeMaker but may be handy in Makefile.PLs.
384 H: Ref to array of *.h file names. Similar to C: above.
386 LINKTYPE: =>'static' or 'dynamic' (default unless usedl=undef in config.sh)
387 Should only be used to force static linking (also see linkext below).
389 CONFIG: =>[qw(archname manext)] defines ARCHNAME & MANEXT from config.sh
390 SKIP: =>[qw(name1 name2)] skip (do not write) sections of the Makefile
395 Additional lowercase attributes can be used to pass parameters to the
396 methods which implement that part of the Makefile. These are not
399 installpm: {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'}
400 linkext: {LINKTYPE => 'static', 'dynamic' or ''}
401 dynamic_lib: {ARMAYBE => 'ar', OTHERLDFLAGS => '...'}
402 clean: {FILES => "*.xyz foo"}
403 realclean: {FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
404 distclean: {TARNAME=>'MyTarFile', TARFLAGS=>'cvfF', COMPRESS=>'gzip'}
405 tool_autosplit: {MAXLEN => 8}
408 sub help {print $Attrib_Help;}
410 @MM_Sections_spec = (
411 'post_initialize' => {},
413 'const_config' => {},
414 'const_loadlibs' => {},
416 'tool_autosplit' => {},
419 'post_constants' => {},
442 %MM_Sections = @MM_Sections_spec; # looses section ordering
443 @MM_Sections = grep(!ref, @MM_Sections_spec); # keeps order
445 %Recognized_Att_Keys = %MM_Sections; # All sections are valid keys.
446 foreach(split(/\n/,$Attrib_Help)){
448 next unless m/^\s*(\w+):\s*(.*)/;
449 $Recognized_Att_Keys{$1} = $2;
450 print "Attribute '$1' => '$2'\n" if ($Verbose >= 2);
458 return 'skipped' if $skip{$section};
467 print STDOUT "MakeMaker" if $Verbose;
469 parse_args(\%att, @ARGV);
470 my(%initial_att) = %att; # record initial attributes
474 print STDOUT "Writing Makefile for $att{NAME}";
479 unlink("Makefile", "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : '');
480 open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!";
481 select MAKE; $|=1; select STDOUT;
483 print MAKE "# This Makefile is for the $att{NAME} extension to perl.\n#";
484 print MAKE "# It was generated automatically by MakeMaker version $Version from the contents";
485 print MAKE "# of Makefile.PL. Don't edit this file, edit Makefile.PL instead.";
486 print MAKE "#\n# ANY CHANGES MADE HERE WILL BE LOST! \n#";
487 print MAKE "# MakeMaker Parameters: ";
488 foreach $key (sort keys %initial_att){
489 my($v) = neatvalue($initial_att{$key});
491 print MAKE "# $key => $v";
494 # build hash for SKIP to make testing easy
495 %skip = map( ($_,1), @{$att{'SKIP'} || []});
497 foreach $section ( @MM_Sections ){
498 print "Processing Makefile '$section' section" if ($Verbose >= 2);
499 my($skipit) = skipcheck($section);
501 print MAKE "\n# --- MakeMaker $section section $skipit.";
503 my(%a) = %{$att{$section} || {}};
504 print MAKE "\n# --- MakeMaker $section section:";
505 print MAKE "# ",%a if $Verbose;
506 print(MAKE MY->nicetext(MY->$section( %a )));
511 print MAKE "\n# Full list of MakeMaker attribute values:";
512 foreach $key (sort keys %att){
513 my($v) = neatvalue($att{$key});
515 print MAKE "# $key => $v";
519 print MAKE "\n# End.";
521 my($finalname) = $Is_VMS ? "Descrip.MMS" : "Makefile";
522 rename("MakeMaker.tmp", $finalname);
524 chmod 0644, $finalname;
525 system("$Config{'eunicefix'} $finalname") unless $Config{'eunicefix'} eq ":";
532 parse_args(\%att, @ARGV);
538 my($attr, @args) = @_;
540 unless (m/(.*?)=(.*)/){
541 help(),exit 1 if m/^help$/;
542 ++$Verbose if m/^verb/;
545 my($name, $value) = ($1, $2);
546 if ($value =~ m/^~(\w+)?/){ # tilde with optional username
547 my($home) = ($1) ? (getpwnam($1))[7] : (getpwuid($>))[7];
548 $value =~ s/^~(\w+)?/$home/;
550 $$attr{$name} = $value;
552 # catch old-style 'potential_libs' and inform user how to 'upgrade'
553 if (defined $$attr{'potential_libs'}){
554 my($msg)="'potential_libs' => '$$attr{potential_libs}' should be";
555 if ($$attr{'potential_libs'}){
556 print STDERR "$msg changed to:\n\t'LIBS' => ['$$attr{potential_libs}']\n";
558 print STDERR "$msg deleted.\n";
560 $$attr{LIBS} = [$$attr{'potential_libs'}];
561 delete $$attr{'potential_libs'};
563 # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
564 if (defined $$attr{'ARMAYBE'}){
565 my($armaybe) = $$attr{'ARMAYBE'};
566 print STDERR "ARMAYBE => '$armaybe' should be changed to:\n",
567 "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
568 my(%dl) = %{$$attr{'dynamic_lib'} || {}};
569 $$attr{'dynamic_lib'} = { %dl, ARMAYBE => $armaybe};
570 delete $$attr{'ARMAYBE'};
572 if (defined $$attr{'LDTARGET'}){
573 print STDERR "LDTARGET should be changed to LDFROM\n";
574 $$attr{'LDFROM'} = $$attr{'LDTARGET'};
575 delete $$attr{'LDTARGET'};
577 foreach(sort keys %{$attr}){
578 print STDOUT " $_ => ".neatvalue($$attr{$_}) if ($Verbose);
579 warn "'$_' is not a known MakeMaker parameter name.\n"
580 unless exists $Recognized_Att_Keys{$_};
588 return "'$v'" unless $t;
589 return "[ ".join(', ',map("'$_'",@$v))." ]" if ($t eq 'ARRAY');
590 return "$v" unless $t eq 'HASH';
592 push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v);
593 return "{ ".join(', ',@m)." }";
597 # ------ Define the MakeMaker default methods in package MM_Unix ------
606 Exporter::import('ExtUtils::MakeMaker',
607 qw(%att %skip %Recognized_Att_Keys $Verbose));
609 # These attributes cannot be overridden externally
610 @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3;
612 if ($Is_VMS = $Config{'osname'} eq 'VMS') {
613 require File::VMSspec;
614 import File::VMSspec 'vmsify';
619 # Find out directory name. This may contain the extension name.
620 my($pwd) = fastcwd(); # from Cwd.pm
622 # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
624 # *Real* information: where did we get these two from? ...
625 $inc_config_dir = dirname($INC{'Config.pm'});
626 $inc_carp_dir = dirname($INC{'Carp.pm'});
628 # Typically PERL_* and INST_* will be identical but that need
629 # not be the case (e.g., installing into project libraries etc).
631 # Perl Macro: With source No source
632 # PERL_LIB ../../lib /usr/local/lib/perl5
633 # PERL_ARCHLIB ../../lib /usr/local/lib/perl5/sun4-sunos
634 # PERL_SRC ../.. (undefined)
636 # INST Macro: Locally Publically
637 # INST_LIB ../../lib ./blib
638 # INST_ARCHLIB ../../lib ./blib
640 unless ($att{PERL_SRC}){
641 foreach(qw(../.. ../../.. ../../../..)){
642 ($att{PERL_SRC}=$_, last) if -f "$_/config.sh";
645 unless ($att{PERL_SRC}){
646 warn "Unable to locate perl source.\n";
647 # we should also consider $ENV{PERL5LIB} here
648 $att{PERL_LIB} = $Config{'privlib'} unless $att{PERL_LIB};
649 $att{PERL_ARCHLIB} = $Config{'archlib'} unless $att{PERL_ARCHLIB};
650 $att{PERL_INC} = "$att{PERL_ARCHLIB}/CORE"; # wild guess for now
651 die "Try setting PERL_SRC in Makefile.PL or on command line.\n"
652 unless (-f "$att{PERL_INC}/perl.h");
654 $att{PERL_LIB} = "$att{PERL_SRC}/lib" unless $att{PERL_LIB};
655 $att{PERL_ARCHLIB} = $att{PERL_LIB};
656 $att{PERL_INC} = $att{PERL_SRC};
659 # INST_LIB typically pre-set if building an extension after
660 # perl has been built and installed. Setting INST_LIB allows
661 # you to build directly into privlib and avoid installperl.
662 unless ($att{INST_LIB}){
663 if (defined $att{PERL_SRC}) {
664 $att{INST_LIB} = $att{PERL_LIB};
666 $att{INST_LIB} = "$pwd/blib";
669 # Try to work out what INST_ARCHLIB should be if not set:
670 unless ($att{INST_ARCHLIB}){
672 "$pwd/blib" => "$pwd/blib", # our private build lib
673 $att{PERL_LIB} => $att{PERL_ARCHLIB},
674 $Config{'privlib'} => $Config{'archlib'},
675 $Config{'installprivlib'} => $Config{'installarchlib'},
676 $inc_carp_dir => $inc_config_dir,
678 $att{INST_ARCHLIB} = $archmap{$att{INST_LIB}};
679 unless($att{INST_ARCHLIB}){
680 # Oh dear, we'll have to default it and warn the user
681 my($archname) = $Config{'archname'};
682 if (-d "$att{INST_LIB}/$archname"){
683 $att{INST_ARCHLIB} = "$att{INST_LIB}/$archname";
684 warn "Defaulting INST_ARCHLIB to INST_LIB/$archname\n";
686 $att{INST_ARCHLIB} = $att{INST_LIB};
687 warn "Warning: Defaulting INST_ARCHLIB to INST_LIB ",
688 "(not architecture independent).\n";
693 # make a few simple checks
694 die "PERL_LIB ($att{PERL_LIB}) is not a perl library directory"
695 unless (-f "$att{PERL_LIB}/Exporter.pm");
697 # --- Initialize Module Name and Paths
699 # NAME = The perl module name for this extension (eg DBD::Oracle).
700 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
701 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
702 # ROOTEXT = Directory part of FULLEXT with leading /.
703 unless($att{NAME}){ # we have to guess our name
706 $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.::);
707 ($att{NAME}=$name) =~ s#[.\]]#::#g;
709 $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::);
710 ($att{NAME} =$name) =~ s#/#::#g;
713 ($att{FULLEXT} =$att{NAME}) =~ s#::#/#g ; #eg. BSD/Foo/Socket
714 ($att{BASEEXT} =$att{NAME}) =~ s#.*::##; #eg. Socket
715 ($att{ROOTEXT} =$att{FULLEXT}) =~ s#/?\Q$att{BASEEXT}\E$## ; # eg. /BSD/Foo
716 $att{ROOTEXT} = "/$att{ROOTEXT}" if $att{ROOTEXT};
717 $att{ROOTEXT} = "" if $Is_VMS;
719 ($att{DISTNAME}=$att{NAME}) =~ s#(::)#-#g;
720 $att{VERSION} = "0.1" unless $att{VERSION};
723 # --- Initialize Perl Binary Locations
725 # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
726 # will be working versions of perl 5. miniperl has priority over perl
727 # for PERL to ensure that $(PERL) is usable while building ./ext/*
728 $att{'PERL'} = MY->find_perl(5.0, [ qw(miniperl perl) ],
729 [ $att{PERL_SRC}, split(":", $ENV{PATH}), $Config{'bin'} ], 0 )
730 unless ($att{'PERL'} && -x $att{'PERL'});
732 # Define 'FULLPERL' to be a non-miniperl (used in test: target)
733 ($att{'FULLPERL'} = $att{'PERL'}) =~ s/miniperl/perl/
734 unless ($att{'FULLPERL'} && -x $att{'FULLPERL'});
737 ($att{'PERL'} = 'MCR ' . vmsify($att{'PERL'})) =~ s:.*/::;
738 ($att{'FULLPERL'} = 'MCR ' . vmsify($att{'FULLPERL'})) =~ s:.*/::;
743 sub init_dirscan { # --- File and Directory Lists (.xs .pm etc)
745 my($name, %dir, %xs, %c, %h, %ignore);
746 local(%pm); #the sub in find() has to see this hash
747 $ignore{'test.pl'} = 1;
748 $ignore{'makefile.pl'} = 1 if $Is_VMS;
749 foreach $name (lsdir(".")){
750 next if ($name =~ /^\./ or $ignore{$name});
752 $dir{$name} = $name if (-f "$name/Makefile.PL");
753 } elsif ($name =~ /\.xs$/){
754 my($c); ($c = $name) =~ s/\.xs$/.c/;
757 } elsif ($name =~ /\.c$/){
759 } elsif ($name =~ /\.h$/){
761 } elsif ($name =~ /\.p[ml]$/){
762 $pm{$name} = "\$(INST_LIBDIR)/$name";
766 # Some larger extensions often wish to install a number of *.pm/pl
767 # files into the library in various locations.
769 # The attribute PMLIBDIRS holds an array reference which lists
770 # subdirectories which we should search for library files to
771 # install. PMLIBDIRS defaults to [ 'lib', $att{BASEEXT} ].
772 # We recursively search through the named directories (skipping
773 # any which don't exist or contain Makefile.PL files).
775 # For each *.pm or *.pl file found MY->libscan() is called with
776 # the default installation path in $_. The return value of libscan
777 # defines the actual installation location.
778 # The default libscan function simply returns $_.
779 # The file is skipped if libscan returns false.
781 # The default installation location passed to libscan in $_ is:
783 # ./*.pm => $(INST_LIBDIR)/*.pm
784 # ./xyz/... => $(INST_LIBDIR)/xyz/...
785 # ./lib/... => $(INST_LIB)/...
787 # In this way the 'lib' directory is seen as the root of the actual
788 # perl library whereas the others are relative to INST_LIBDIR
789 # (which includes ROOTEXT). This is a subtle distinction but one
790 # that's important for nested modules.
792 $att{PMLIBDIRS} = [ 'lib', $att{BASEEXT} ] unless $att{PMLIBDIRS};
794 #only existing directories that aren't in $dir are allowed
795 @{$att{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$att{PMLIBDIRS}};
797 if (@{$att{PMLIBDIRS}}){
798 print "Searching PMLIBDIRS: @{$att{PMLIBDIRS}}"
800 use File::Find; # try changing to require !
801 File::Find::find(sub {
802 return unless m/\.p[ml]$/;
803 my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
804 $prefix = '$(INST_LIB)' if ($path =~ s:^lib/::);
805 local($_) = "$prefix/$path";
806 my($inst) = MY->libscan();
807 print "libscan($path) => '$inst'" if ($Verbose >= 2);
809 $pm{$path} = "$inst";
810 }, @{$att{PMLIBDIRS}});
813 $att{DIR} = [sort keys %dir] unless $att{DIRS};
814 $att{XS} = \%xs unless $att{XS};
815 $att{PM} = \%pm unless $att{PM};
816 $att{C} = [sort keys %c] unless $att{C};
817 $att{H} = [sort keys %h] unless $att{H};
826 sub init_others { # --- Initialize Other Attributes
828 for $key (keys(%Recognized_Att_Keys), keys(%Other_Att_Keys)){
829 # avoid warnings for uninitialized vars
830 next if exists $att{$key};
834 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $att{'LIBS'}
835 # Lets look at $att{LIBS} carefully: It may be an anon array, a string or
836 # undefined. In any case we turn it into an anon array:
837 $att{LIBS}=[] unless $att{LIBS};
838 $att{LIBS}=[$att{LIBS}] if ref \$att{LIBS} eq SCALAR;
839 foreach ( @{$att{'LIBS'}} ){
840 s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
841 my(@libs) = MY->extliblist($_);
842 if ($libs[0] or $libs[1] or $libs[2]){
843 @att{EXTRALIBS, BSLOADLIBS, LDLOADLIBS} = @libs;
848 warn "CONFIG must be an array ref\n"
849 if ($att{CONFIG} and ref $att{CONFIG} ne 'ARRAY');
850 $att{CONFIG} = [] unless (ref $att{CONFIG});
851 push(@{$att{CONFIG}},
852 qw( cc libc ldflags lddlflags ccdlflags cccdlflags
853 ranlib so dlext dlsrc installprivlib installarchlib
855 push(@{$att{CONFIG}}, 'shellflags') if $Config{'shellflags'};
858 # This will not make other Makefile.PLs portable. Any Makefile.PL
859 # which says OBJECT => "foo.o bar.o" will fail on VMS. It might
860 # be better to fix the c_o section to produce .o files.
861 $att{OBJECT} = '$(BASEEXT).obj' unless $att{OBJECT};
862 $att{OBJECT} =~ s/[^,\s]\s+/, /g;
863 $att{OBJECT} =~ s/\n+/, /g;
865 $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT};
866 $att{OBJECT} =~ s/\n+/ \\\n\t/g;
868 $att{BOOTDEP} = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
869 $att{LD} = ($Config{'ld'} || 'ld') unless $att{LD};
870 $att{LDFROM} = '$(OBJECT)' unless $att{LDFROM};
871 $att{LINKTYPE} = ($Config{'usedl'}) ? 'dynamic' : 'static'
872 unless $att{LINKTYPE};
874 # These get overridden for VMS and maybe some other systems
876 $att{RM_F} = "rm -f";
877 $att{RM_RF} = "rm -rf";
878 $att{TOUCH} = "touch";
885 my($dir, $regex) = @_;
887 opendir(DIR, $_[0] || ".") or die "opendir: $!";
890 @ls = grep(/$regex/, @ls) if $regex;
896 my($self, $ver, $names, $dirs, $trace) = @_;
898 print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n"
900 foreach $dir (@$dirs){
901 next unless defined $dir; # $att{PERL_SRC} may be undefined
902 foreach $name (@$names){
903 print "checking $dir/$name\n" if ($trace >= 2);
905 $name .= ".exe" unless -x "$dir/$name";
907 next unless -x "$dir/$name";
908 print "executing $dir/$name\n" if ($trace);
911 my($vmscmd) = 'MCR ' . vmsify("$dir/$name");
912 $out = `$vmscmd -e "require $ver; print ""VER_OK\n"""`;
914 $out = `$dir/$name -e 'require $ver; print "VER_OK\n" ' 2>&1`;
916 return "$dir/$name" if $out =~ /VER_OK/;
919 warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
920 0; # false and not empty
934 DISTNAME = $att{DISTNAME}
935 VERSION = $att{VERSION}
937 # In which library should we install this extension?
938 # This is typically the same as PERL_LIB.
939 # (also see INST_LIBDIR and relationship to ROOTEXT)
940 INST_LIB = $att{INST_LIB}
941 INST_ARCHLIB = $att{INST_ARCHLIB}
943 # Perl library to use when building the extension
944 PERL_LIB = $att{PERL_LIB}
945 PERL_ARCHLIB = $att{PERL_ARCHLIB}
948 # Define I_PERL_LIBS to include the required -Ipaths
949 # To be cute we only include PERL_ARCHLIB if different
950 # To be portable we add quotes for VMS
951 my(@i_perl_libs) = qw{-I$(PERL_ARCHLIB) -I$(PERL_LIB)};
952 shift(@i_perl_libs) if ($att{PERL_ARCHLIB} eq $att{PERL_LIB});
954 push @m, "I_PERL_LIBS = \"".join('" "',@i_perl_libs)."\"\n";
956 push @m, "I_PERL_LIBS = ".join(' ',@i_perl_libs)."\n";
960 # Where is the perl source code located? (Eventually we should
961 # be able to build extensions without requiring the perl source
962 # but that's a way off yet).
963 PERL_SRC = $att{PERL_SRC}
964 # Perl header files (will eventually be under PERL_LIB)
965 PERL_INC = $att{PERL_INC}
968 FULLPERL = $att{'FULLPERL'}
971 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
972 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
973 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
974 FULLEXT = $att{FULLEXT}
975 BASEEXT = $att{BASEEXT}
976 ROOTEXT = $att{ROOTEXT}
980 DEFINE = $att{DEFINE}
981 OBJECT = $att{OBJECT}
982 LDFROM = $att{LDFROM}
983 LINKTYPE = $att{LINKTYPE}
985 # Handy lists of source code files:
986 XS_FILES= ".join(" \\\n\t", sort keys %{$att{XS}})."
987 C_FILES = ".join(" \\\n\t", @{$att{C}})."
988 H_FILES = ".join(" \\\n\t", @{$att{H}})."
994 .PHONY: all config static dynamic test linkext
996 # This extension may link to it's own library (see SDBM_File)
997 MYEXTLIB = $att{MYEXTLIB}
999 # Where is the Config information that we are using/depend on
1000 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
1004 # Where to put things:
1005 INST_LIBDIR = $(INST_LIB)$(ROOTEXT)
1006 INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT)
1008 INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
1009 INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
1013 INST_STATIC = $(INST_ARCHAUTODIR)/$(BASEEXT).a
1014 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(BASEEXT).$(DLEXT)
1015 INST_BOOT = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
1016 INST_PM = '.join(" \\\n\t", sort values %{$att{PM}}).'
1024 # This is implemented in the same manner as extliblist,
1025 # e.g., do both and compare results during the transition period.
1026 my($cc,$ccflags,$optimize,$large,$split, $shflags)
1027 = @Config{qw(cc ccflags optimize large split shellflags)};
1028 $shflags = '' unless $shflags;
1031 chop($old = `cd $att{PERL_SRC}; sh $shflags ./cflags $att{BASEEXT}.c 2>/dev/null`)
1034 if ($prog = $Config{"$att{BASEEXT}_cflags"}) {
1035 # Expand hints for this extension via the shell
1036 print STDERR "Processing $att{BASEEXT}_cflags hint:\n" if $Verbose;
1038 ccflags=\"$ccflags\"
1039 optimize=\"$optimize\"
1044 echo ccflags=\$ccflags
1045 echo optimize=\$optimize
1052 if ($line =~ /(.*?)=\s*(.*)\s*$/){
1054 print STDERR " $1 = $2" if $Verbose;
1056 print STDERR "Unrecognised result from hint: '$line'\n";
1059 ($cc,$ccflags,$optimize,$large,$split)=@cflags{qw(cc ccflags optimize large split)};
1062 my($new) = "$cc -c $ccflags $optimize $large $split";
1063 if (defined($old) and $new ne $old) {
1064 warn "Warning (non-fatal): cflags evaluation in MakeMaker differs from shell output\n"
1065 ." package: $att{NAME}\n"
1068 ." Using 'old' set.\n"
1069 ."Please notify perl5-porters\@nicoh.com\n";
1071 my($cccmd)=($old) ? $old : $new;
1076 # --- Constants Sections ---
1080 push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
1082 foreach $m (@{$att{'CONFIG'}}){
1083 next if $once_only{$m};
1084 warn "CONFIG key '$m' does not exist in Config.pm\n"
1085 unless exists $Config{$m};
1086 push @m, "\U$m\E = $Config{$m}\n";
1095 # $att{NAME} might depend on some other libraries:
1096 # (These comments may need revising:)
1098 # Dependent libraries can be linked in one of three ways:
1100 # 1. (For static extensions) by the ld command when the perl binary
1101 # is linked with the extension library. See EXTRALIBS below.
1103 # 2. (For dynamic extensions) by the ld command when the shared
1104 # object is built/linked. See LDLOADLIBS below.
1106 # 3. (For dynamic extensions) by the DynaLoader when the shared
1107 # object is loaded. See BSLOADLIBS below.
1109 # EXTRALIBS = List of libraries that need to be linked with when
1110 # linking a perl binary which includes this extension
1111 # Only those libraries that actually exist are included.
1112 # These are written to a file and used when linking perl.
1114 # LDLOADLIBS = List of those libraries which can or must be linked into
1115 # the shared library when created using ld. These may be
1116 # static or dynamic libraries.
1118 # BSLOADLIBS = List of those libraries that are needed but can be
1119 # linked in dynamically at run time on this platform.
1120 # SunOS/Solaris does not need this because ld records
1121 # the information (from LDLOADLIBS) into the object file.
1122 # This list is used to create a .bs (bootstrap) file.
1124 EXTRALIBS = $att{'EXTRALIBS'}
1125 LDLOADLIBS = $att{'LDLOADLIBS'}
1126 BSLOADLIBS = $att{'BSLOADLIBS'}
1131 # --- Tool Sections ---
1134 my($self, %attribs) = @_;
1136 $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
1138 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1139 # Remark: the "" around the -I switches are helpful for the VMS support
1140 AUTOSPLITFILE = $(PERL) $(I_PERL_LIBS) -e 'use AutoSplit;}.$asl.q{ autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
1146 my($xsdir) = '$(PERL_LIB)/ExtUtils';
1147 # drop back to old location if xsubpp is not in new location yet
1148 $xsdir = '$(PERL_SRC)/ext' unless (-f "$att{PERL_LIB}/ExtUtils/xsubpp");
1149 my(@tmdeps) = ('$(XSUBPPDIR)/typemap');
1150 push(@tmdeps, "typemap") if -f "typemap";
1151 my(@tmargs) = map("-typemap $_", @tmdeps);
1154 XSUBPP = \$(XSUBPPDIR)/xsubpp
1155 XSUBPPDEPS = @tmdeps
1156 XSUBPPARGS = @tmargs
1171 # The following is a portable way to say mkdir -p
1172 MKPATH = $(PERL) -wle '$$"="/"; foreach $$p (@ARGV){ next if -d $$p; my(@p); foreach(split(/\//,$$p)){ push(@p,$$_); next if -d "@p/"; print "mkdir @p"; mkdir("@p",0777)||die $$! }} exit 0;'
1182 # --- Translation Sections ---
1187 $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1194 $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $@
1198 sub xs_o { # many makes are too dumb to use xs_c then c_o
1201 $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
1202 $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1207 # --- Target Sections ---
1211 all :: config linkext $(INST_PM)
1215 @$(MKPATH) $(INST_LIBDIR) $(INST_ARCHAUTODIR)
1220 my($self, %attribs) = @_;
1221 # LINKTYPE => static or dynamic
1222 my($linktype) = $attribs{LINKTYPE} || '$(LINKTYPE)';
1224 linkext :: $linktype
1230 # --- Dynamic Loading Sections ---
1234 # $(INST_PM) has been moved to the all: target.
1235 # It remains here for awhile to allow for old usage: "make dynamic"
1236 dynamic :: Makefile $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
1242 my($self, %attribs) = @_;
1244 BOOTSTRAP = '."$att{BASEEXT}.bs".'
1246 # As MakeMaker mkbootstrap might not write a file (if none is required)
1247 # we use touch to prevent make continually trying to remake it.
1248 # The DynaLoader only reads a non-empty file.
1249 $(BOOTSTRAP): Makefile '.$att{BOOTDEP}.'
1250 $(PERL) $(I_PERL_LIBS) \
1251 -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(BSLOADLIBS)");\' \
1252 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) PERL_SRC=$(PERL_SRC) NAME=$(NAME)
1253 @$(TOUCH) $(BOOTSTRAP)
1255 $(INST_BOOT): $(BOOTSTRAP)
1256 @'.$att{RM_RF}.' $(INST_BOOT)
1257 '.$att{CP}.' $(BOOTSTRAP) $(INST_BOOT)
1263 my($self, %attribs) = @_;
1264 my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
1265 my($armaybe) = $attribs{ARMAYBE} || $att{ARMAYBE} || ":";
1266 my($ldfrom) = '$(LDFROM)';
1267 my($osname) = $Config{'osname'};
1268 $armaybe = 'ar' if ($osname eq 'dec_osf' and $armaybe eq ':');
1271 # This section creates the dynamically loadable $(INST_DYNAMIC)
1272 # from $(OBJECT) and possibly $(MYEXTLIB).
1273 ARMAYBE = '.$armaybe.'
1274 OTHERLDFLAGS = '.$otherldflags.'
1276 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP)
1277 @$(MKPATH) $(INST_ARCHAUTODIR)
1279 if ($armaybe ne ':'){
1281 push(@m,' $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
1282 push(@m,' $(RANLIB) '."$ldfrom\n");
1284 $ldfrom = "-all $ldfrom -none" if ($osname eq 'dec_osf');
1285 push(@m,' $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
1286 ' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS)'."\n");
1291 # --- Static Loading Sections ---
1295 # $(INST_PM) has been moved to the all: target.
1296 # It remains here for awhile to allow for old usage: "make static"
1297 static :: Makefile $(INST_STATIC) $(INST_PM)
1305 $(INST_STATIC): $(OBJECT) $(MYEXTLIB)
1307 # If this extension has it's own library (eg SDBM_File)
1308 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
1309 push(@m, " $att{CP} \$(MYEXTLIB) \$\@\n") if $att{MYEXTLIB};
1312 ar cr $@ $(OBJECT) && $(RANLIB) $@
1313 @echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
1315 push(@m, <<'END') if $att{PERL_SRC};
1316 @: Old mechanism - still needed:
1317 @echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
1324 my($self, %attribs) = @_;
1325 # By default .pm files are split into the architecture independent
1326 # library. This is a good thing. If a specific module requires that
1327 # it's .pm files are split into the architecture specific library
1328 # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'}
1329 # Note that installperl currently interferes with this (Config.pm)
1330 # User can disable split by saying: installpm => {SPLITLIB=>''}
1331 my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default
1332 $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB};
1334 foreach $dist (sort keys %{$att{PM}}){
1335 my($inst) = $att{PM}->{$dist};
1336 push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n");
1337 push(@m, MY->installpm_x($dist, $inst, $splitlib));
1343 sub installpm_x { # called by installpm per file
1344 my($self, $dist, $inst, $splitlib) = @_;
1345 my($instdir) = $inst =~ m|(.*)/|;
1349 ".' @'.$att{RM_F}.' $@
1350 @$(MKPATH) '.$instdir.'
1353 push(@m, "\t\$(AUTOSPLITFILE) \$@ $splitlib/auto\n")
1354 if ($splitlib and $inst =~ m/\.pm$/);
1359 # --- Sub-directory Sections ---
1363 # This method provides a mechanism to automatically deal with
1364 # subdirectories containing further Makefile.PL scripts.
1365 # It calls the subdir_x() method for each subdirectory.
1366 foreach(<*/Makefile.PL>){
1367 s:/Makefile\.PL$:: ;
1368 print "Including $_ subdirectory" if ($Verbose);
1369 push(@m, MY->subdir_x($_));
1373 # The default clean, realclean and test targets in this Makefile
1374 # have automatically been given entries for each subdir.
1379 push(@m, "\n# none")
1384 sub runsubdirpl{ # Experimental! See subdir_x section
1385 my($self,$subdir) = @_;
1386 chdir($subdir) or die "chdir($subdir): $!";
1387 require "Makefile.PL";
1391 my($self, $subdir) = @_;
1393 # The intention is that the calling Makefile.PL should define the
1394 # $(SUBDIR_MAKEFILE_PL_ARGS) make macro to contain whatever
1395 # information needs to be passed down to the other Makefile.PL scripts.
1396 # If this does not suit your needs you'll need to write your own
1397 # MY::subdir_x() method to override this one.
1399 config :: $subdir/Makefile
1400 cd $subdir ; \$(MAKE) config INST_LIB=\$(INST_LIB) INST_ARCHLIB=\$(INST_ARCHLIB) LINKTYPE=\$(LINKTYPE)
1402 $subdir/Makefile: $subdir/Makefile.PL \$(CONFIGDEP)
1403 }.' @echo "Rebuilding $@ ..."
1404 $(PERL) $(I_PERL_LIBS) \\
1405 -e "use ExtUtils::MakeMaker; MM->runsubdirpl(qw('.$subdir.'))" \\
1406 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) $(SUBDIR_MAKEFILE_PL_ARGS)
1407 @echo "Rebuild of $@ complete."
1411 cd $subdir ; \$(MAKE) all LINKTYPE=\$(LINKTYPE)
1417 # --- Cleanup and Distribution Sections ---
1420 my($self, %attribs) = @_;
1423 # Delete temporary files but do not touch installed files. We don\'t delete
1424 # the Makefile here so a later make realclean still has a makefile to use.
1428 # clean subdirectories first
1429 push(@m, map("\t-cd $_ && test -f Makefile && \$(MAKE) clean\n",@{$att{DIR}}));
1430 my(@otherfiles) = values %{$att{XS}}; # .c files from *.xs files
1431 push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1432 push(@m, " -$att{RM_RF} *~ t/*~ *.o *.a mon.out core so_locations "
1433 ."\$(BOOTSTRAP) \$(BASEEXT).bso @otherfiles\n");
1434 # See realclean and ext/utils/make_ext for usage of Makefile.old
1435 push(@m, " -$att{MV} Makefile Makefile.old 2>/dev/null\n");
1436 push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP};
1441 my($self, %attribs) = @_;
1444 # Delete temporary files (via clean) and also delete installed files
1445 realclean purge :: clean
1447 # realclean subdirectories first (already cleaned)
1448 $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
1449 foreach(@{$att{DIR}}){
1450 push(@m, sprintf($sub,$_,'Makefile.old','-f Makefile.old'));
1451 push(@m, sprintf($sub,$_,'Makefile',''));
1453 push(@m, " $att{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
1454 push(@m, " $att{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
1455 push(@m, " $att{RM_F} \$(INST_STATIC) \$(INST_PM)\n");
1456 my(@otherfiles) = qw(Makefile Makefile.old); # Makefiles last
1457 push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1458 push(@m, " $att{RM_RF} @otherfiles\n") if @otherfiles;
1459 push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP};
1465 my($self, %attribs) = @_;
1466 # VERSION should be sanitised before use as a file name
1467 my($tarname) = $attribs{TARNAME} || '$(DISTNAME)-$(VERSION)';
1468 my($tarflags) = $attribs{TARFLAGS} || 'cvf';
1469 my($compress) = $attribs{COMPRESS} || 'compress'; # eg gzip
1470 my($preop) = $attribs{PREOP} || '@:'; # e.g., update MANIFEST
1471 my($postop) = $attribs{POSTOP} || '@:';
1472 my($mkfiles) = join(' ', map("$_/Makefile", ".", @{$att{DIR}}));
1477 cd ..; tar $tarflags $tarname.tar \$(BASEEXT)
1478 cd ..; $compress $tarname.tar
1484 # --- Test and Installation Sections ---
1487 my($self, %attribs) = @_;
1488 my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
1493 push(@m, <<"END") if $tests;
1494 \$(FULLPERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) -e 'use Test::Harness; runtests \@ARGV;' $tests
1496 push(@m, <<'END') if -f "test.pl";
1497 $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) $(I_PERL_LIBS) test.pl
1499 push(@m, map("\tcd $_ && test -f Makefile && \$(MAKE) test LINKTYPE=\$(LINKTYPE)\n",@{$att{DIR}}));
1500 push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n") unless @m > 1;
1506 my($self, %attribs) = @_;
1511 # install subdirectories first
1512 push(@m, map("\tcd $_ && test -f Makefile && \$(MAKE) install\n",@{$att{DIR}}));
1514 push(@m, "\t: perl5.000 and MM pre 3.8 autosplit into INST_ARCHLIB, we delete these old files here
1515 $att{RM_F} \$(INSTALLARCHLIB)/auto/\$(FULLEXT)/*.al \$(INSTALLARCHLIB)/auto/\$(FULLEXT)/*.ix
1516 \$(MAKE) INST_LIB=\$(INSTALLPRIVLIB) INST_ARCHLIB=\$(INSTALLARCHLIB)
1523 '# Phony target to force checking subdirectories.
1532 PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \
1533 $(PERL_INC)/XSUB.h $(PERL_INC)/av.h $(PERL_INC)/cop.h \
1534 $(PERL_INC)/cv.h $(PERL_INC)/dosish.h $(PERL_INC)/embed.h \
1535 $(PERL_INC)/form.h $(PERL_INC)/gv.h $(PERL_INC)/handy.h \
1536 $(PERL_INC)/hv.h $(PERL_INC)/keywords.h $(PERL_INC)/mg.h \
1537 $(PERL_INC)/op.h $(PERL_INC)/opcode.h $(PERL_INC)/patchlevel.h \
1538 $(PERL_INC)/perl.h $(PERL_INC)/perly.h $(PERL_INC)/pp.h \
1539 $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h $(PERL_INC)/regexp.h \
1540 $(PERL_INC)/scope.h $(PERL_INC)/sv.h $(PERL_INC)/unixish.h \
1541 $(PERL_INC)/util.h $(PERL_INC)/config.h
1543 $(OBJECT) : $(PERL_HDRS)
1547 # Check for unpropogated config.sh changes. Should never happen.
1548 # We do NOT just update config.h because that is not sufficient.
1549 # An out of date config.h is not fatal but complains loudly!
1550 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
1551 -@echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
1553 # An out of date Config.pm is fatal.
1554 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
1555 @echo "$(PERL_ARCHLIB)/Config.pm out of date with $(PERL_SRC)/config.sh"
1557 ') if $att{PERL_SRC};
1559 push(@m, join(" ", values %{$att{XS}})." : \$(XSUBPPDEPS)\n")
1566 # We do not know what target was originally specified so we
1567 # must force a manual rerun to be sure. But as it should only
1568 # happen very rarely it is not a significant problem.
1570 $(OBJECT) : Makefile
1572 # We take a very conservative approach here, but it\'s worth it.
1573 # We move Makefile to Makefile.old here to avoid gnu make looping.
1574 Makefile: Makefile.PL $(CONFIGDEP)
1575 @echo "Makefile out-of-date with respect to $?"
1576 @echo "Cleaning current config before rebuilding Makefile..."
1577 -@mv Makefile Makefile.old
1578 -$(MAKE) -f Makefile.old clean >/dev/null 2>&1 || true
1579 $(PERL) $(I_PERL_LIBS) Makefile.PL
1580 @echo "Now you must rerun make."; false
1590 # --- Determine libraries to use and how to use them ---
1593 my($self, $libs) = @_;
1594 return ("", "", "") unless $libs;
1595 print STDERR "Potential libraries are '$libs':" if $Verbose;
1596 my(@new) = MY->new_extliblist($libs);
1598 if ($att{PERL_SRC}){
1599 my(@old) = MY->old_extliblist($libs);
1600 my($oldlibs) = join(" : ",@old);
1601 my($newlibs) = join(" : ",@new);
1602 warn "Warning (non-fatal): $att{NAME} extliblist consistency check failed:\n".
1605 "Using 'new' set. Please notify perl5-porters\@nicoh.com.\n"
1606 if ("$newlibs" ne "$oldlibs");
1612 sub old_extliblist {
1613 my($self, $potential_libs)=@_;
1614 return ("", "", "") unless $potential_libs;
1615 die "old_extliblist requires PERL_SRC" unless $att{PERL_SRC};
1618 # Now run ext/util/extliblist to discover what *libs definitions
1619 # are required for the needs of $potential_libs
1620 $ENV{'potential_libs'} = $potential_libs;
1621 my(@o)=`. $att{PERL_SRC}/config.sh
1622 . $att{PERL_SRC}/ext/util/extliblist;
1623 echo EXTRALIBS=\$extralibs
1624 echo BSLOADLIBS=\$dynaloadlibs
1625 echo LDLOADLIBS=\$statloadlibs
1629 if ($line =~ /(.*)\s*=\s*(.*)\s*$/){
1631 print STDERR " $1 = $2" if $Verbose;
1636 print STDERR "Messages from extliblist:\n", join("\n",@w,'')
1638 @attrib{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)};
1642 sub new_extliblist {
1643 my($self, $potential_libs)=@_;
1644 return ("", "", "") unless $potential_libs;
1646 my($so) = $Config{'so'};
1647 my($libs) = $Config{'libs'};
1649 # compute $extralibs, $bsloadlibs and $ldloadlibs from
1651 # this is a rewrite of Andy Dougherty's extliblist in perl
1652 # its home is in <distribution>/ext/util
1654 my(@searchpath); # from "-L/path" entries in $potential_libs
1655 my(@libpath) = split " ", $Config{'libpth'};
1660 my($pwd) = fastcwd(); # from Cwd.pm
1662 foreach $thislib (split ' ', $potential_libs){
1664 # Handle possible linker path arguments.
1665 if ($thislib =~ s/^(-[LR])//){ # save path flag type
1667 unless (-d $thislib){
1668 warn "$ptype$thislib ignored, directory does not exist\n"
1672 if ($thislib !~ m|^/|) {
1673 warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
1674 $thislib = "$pwd/$thislib";
1676 push(@searchpath, $thislib);
1677 push(@extralibs, "$ptype$thislib");
1678 push(@ldloadlibs, "$ptype$thislib");
1682 # Handle possible library arguments.
1683 unless ($thislib =~ s/^-l//){
1684 warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
1689 foreach $thispth (@searchpath, @libpath){
1691 if (@fullname=<${thispth}/lib${thislib}.${so}.[0-9]*>){
1692 $fullname=$fullname[-1]; #ATTN: 10 looses against 9!
1693 } elsif (-f ($fullname="$thispth/lib$thislib.$so")){
1694 } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")
1695 && ($thislib .= "_s") ){ # we must explicitly ask for _s version
1696 } elsif (-f ($fullname="$thispth/lib$thislib.a")){
1697 } elsif (-f ($fullname="$thispth/Slib$thislib.a")){
1699 warn "$thislib not found in $thispth\n" if $Verbose;
1702 warn "'-l$thislib' found at $fullname\n" if $Verbose;
1705 # Now update library lists
1707 # what do we know about this library...
1708 my $is_dyna = ($fullname !~ /\.a$/);
1709 my $in_perl = ($libs =~ /\B-l${thislib}\b/s);
1711 # Do not add it into the list if it is already linked in
1712 # with the main perl executable.
1713 # We have to special-case the NeXT, because all the math is also in libsys_s
1714 unless ( $in_perl || ($Config{'osname'} eq 'next' && $thislib eq 'm') ){
1715 push(@extralibs, "-l$thislib");
1719 # We might be able to load this archive file dynamically
1720 if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){
1721 # We push -l$thislib instead of $fullname because
1722 # it avoids hardwiring a fixed path into the .bs file.
1723 # mkbootstrap will automatically add dl_findfile() to
1724 # the .bs file if it sees a name in the -l format.
1725 # USE THIS LATER: push(@bsloadlibs, "-l$thislib"); # " $fullname";
1726 # USE THIS while checking results against old_extliblist
1727 push(@bsloadlibs, "$fullname");
1730 # For SunOS4, do not add in this shared library if
1731 # it is already linked in the main perl executable
1732 push(@ldloadlibs, "-l$thislib")
1733 unless ($in_perl and $Config{'osname'} eq 'sunos');
1735 push(@ldloadlibs, "-l$thislib");
1738 last; # found one here so don't bother looking further
1740 warn "Warning (non-fatal): No library found for -l$thislib\n" unless $found_lib>0;
1742 ("@extralibs", "@bsloadlibs", "@ldloadlibs");
1746 # --- Write a DynaLoader bootstrap file if required
1756 Make a bootstrap file for use by this system's DynaLoader.
1757 It typically gets called from an extension Makefile.
1759 There is no .bs file supplied with the extension. Instead a _BS file
1760 which has code for the special cases, like posix for berkeley db on the
1763 This file will get parsed, and produce a maybe empty
1764 @DynaLoader::dl_resolve_using array for the current architecture.
1765 That will be extended by $BSLOADLIBS, which was computed by Andy's
1766 extliblist script. If this array still is empty, we do nothing, else
1767 we write a .bs file with an @DynaLoader::dl_resolve_using array, but
1768 without any C<if>s, because there is no longer a need to deal with
1771 The _BS file can put some code into the generated .bs file by placing
1772 it in $bscode. This is a handy 'escape' mechanism that may prove
1773 useful in complex situations.
1775 If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
1776 mkbootstrap will automatically add a dl_findfile() call to the
1781 Andreas Koenig <k@otto.ww.TU-Berlin.DE>, Tim Bunce
1782 <Tim.Bunce@ig.co.uk>, Andy Dougherty <doughera@lafcol.lafayette.edu>
1786 my($self, @bsloadlibs)=@_;
1788 @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
1790 print STDERR " bsloadlibs=@bsloadlibs\n" if $Verbose;
1792 # We need DynaLoader here because we and/or the *_BS file may
1793 # call dl_findfile(). We don't say `use' here because when
1794 # first building perl extensions the DynaLoader will not have
1795 # been built when MakeMaker gets first used.
1799 init_main() unless defined $att{'BASEEXT'};
1801 rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
1803 if (-f "$att{BASEEXT}_BS"){
1804 $_ = "$att{BASEEXT}_BS";
1805 package DynaLoader; # execute code as if in DynaLoader
1806 local($osname, $dlsrc) = (); # avoid warnings
1807 ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
1814 if ($Config{'dlsrc'} =~ /^dl_dld/){
1816 push(@dl_resolve_using, dl_findfile('-lc'));
1819 my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
1822 open BS, ">$att{BASEEXT}.bs"
1823 or die "Unable to open $att{BASEEXT}.bs: $!";
1824 print STDOUT "Writing $att{BASEEXT}.bs\n";
1825 print STDOUT " containing: @all" if $Verbose;
1826 print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
1827 print BS "# Do not edit this file, changes will be lost.\n";
1828 print BS "# This file was automatically generated by the\n";
1829 print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
1830 print BS "\@DynaLoader::dl_resolve_using = ";
1831 # If @all contains names in the form -lxxx or -Lxxx then it's asking for
1832 # runtime library location so we automatically add a call to dl_findfile()
1833 if (" @all" =~ m/ -[lLR]/){
1834 print BS " dl_findfile(qw(\n @all\n ));\n";
1836 print BS " qw(@all);\n";
1838 # write extra code if *_BS says so
1839 print BS $DynaLoader::bscode if $DynaLoader::bscode;
1844 # special handling for systems which needs a list of all global
1845 # symbols exported by a modules to be dynamically linked.
1846 if ($Config{'dlsrc'} =~ /^dl_aix/){
1848 ($bootfunc = $att{NAME}) =~ s/\W/_/g;
1849 open EXP, ">$att{BASEEXT}.exp";
1850 print EXP "#!\nboot_$bootfunc\n";
1856 # --- Output postprocessing section ---
1857 #nicetext is included to make VMS support easier
1858 sub nicetext { # Just return the input - no action needed
1859 my($self,$text) = @_;
1863 # the following keeps AutoSplit happy
1864 package ExtUtils::MakeMaker;