1 package ExtUtils::MakeMaker;
3 $Version = 4.03; # Last edited 30th Jan 1995 by Andreas Koenig
12 @EXPORT = qw(&WriteMakefile &mkbootstrap &mksymlists $Verbose);
13 @EXPORT_OK = qw($Version %att %skip %Recognized_Att_Keys
14 @MM_Sections %MM_Sections
15 &help &lsdir &neatvalue);
17 $Is_VMS = $Config{'osname'} eq 'VMS';
18 require ExtUtils::MM_VMS if $Is_VMS;
22 $Version = $Version;# avoid typo warning
29 ExtUtils::MakeMaker - create an extension Makefile
33 C<use ExtUtils::MakeMaker;>
35 C<WriteMakefile( ATTRIBUTE => VALUE [, ...] );>
39 This utility is designed to write a Makefile for an extension module
40 from a Makefile.PL. It is based on the Makefile.SH model provided by
41 Andy Dougherty and the perl5-porters.
43 It splits the task of generating the Makefile into several subroutines
44 that can be individually overridden. Each subroutine returns the text
45 it wishes to have written to the Makefile.
47 MakeMaker.pm uses the architecture specific information from
48 Config.pm. In addition the extension may contribute to the C<%Config>
49 hash table of Config.pm by supplying hints files in a C<hints/>
50 directory. The hints files are expected to be named like their
51 counterparts in PERL_SRC/hints (eg. next_3_2.sh). They are both
52 executed by the shell and parsed by MakeMaker to include the variables
53 in C<%Config>. If there is no hintsfile for the actual system, but for
54 some previous releases of the same operating system, the latest one of
57 =head2 Default Makefile Behaviour
59 The automatically generated Makefile enables the user of the extension
65 make install # May need to invoke as root to write into INST_LIB
67 The Makefile to be produced may be altered by adding arguments of the
68 form C<KEY=VALUE>. If the user wants to have the extension installed
69 into a directory different from C<$Config{"installprivlib"}> it can be
72 perl Makefile.PL INST_LIB=~/myperllib
74 Note, that in this example MakeMaker does the tilde expansion for you
75 and INST_ARCHLIB is set to either C<INST_LIB/$Config{"osname"}> if
76 that directory exists and otherwise to INST_LIB.
78 Other interesting targets in the generated Makefile are
80 make config # to check if the Makefile is up-to-date
81 make clean # delete local temporary files (Makefile gets renamed)
82 make realclean # delete all derived files (including installed files)
83 make distclean # produce a gzipped file ready for shipping
85 The macros in the produced Makefile may be overridden on the command
86 line to the make call as in the following example:
88 make INST_LIB=/some/where INST_ARCHLIB=/some/where
90 Note, that this is a solution provided by C<make> in general, so tilde
91 expansion will probably not be available and INST_ARCHLIB will not be
92 set automatically when INST_LIB is given as argument.
94 The generated Makefile does not set any permissions. The installer has
95 to decide, which umask should be in effect.
97 =head2 Determination of Perl Library and Installation Locations
99 MakeMaker needs to know, or to guess, where certain things are
100 located. Especially INST_LIB and INST_ARCHLIB (where to install files
101 into), PERL_LIB and PERL_ARCHLIB (where to read existing modules
102 from), and PERL_INC (header files and C<libperl*.*>).
104 Extensions may be built either using the contents of the perl source
105 directory tree or from an installed copy of the perl library.
107 If an extension is being built below the C<ext/> directory of the perl
108 source then MakeMaker will set PERL_SRC automatically (e.g., C<../..>).
109 If PERL_SRC is defined then other variables default to the following:
112 PERL_LIB = PERL_SRC/lib
113 PERL_ARCHLIB = PERL_SRC/lib
115 INST_ARCHLIB = PERL_ARCHLIB
117 If an extension is being built away from the perl source then MakeMaker
118 will leave PERL_SRC undefined and default to using the installed copy
119 of the perl library. The other variables default to the following:
121 PERL_INC = $archlib/CORE
123 PERL_ARCHLIB = $archlib
125 INST_ARCHLIB = ./blib
127 If perl has not yet been installed then PERL_SRC can be defined on the
128 command line as shown in the previous section.
130 =head2 Useful Default Makefile Macros
132 FULLEXT = Pathname for extension directory (eg DBD/Oracle).
134 BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
136 ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
138 PERL_LIB = Directory where we read the perl library files
140 PERL_ARCHLIB = Same as above for architecture dependent files
142 INST_LIB = Directory where we put library files of this extension
143 while building it. If we are building below PERL_SRC/ext
144 we default to PERL_SRC/lib, else we default to ./blib.
146 INST_ARCHLIB = Same as above for architecture dependent files
148 INST_LIBDIR = $(INST_LIB)$(ROOTEXT)
150 INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
152 INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
154 =head2 Customizing The Generated Makefile
156 If the Makefile generated does not fit your purpose you can change it
157 using the mechanisms described below.
159 =head2 Using Attributes (and Parameters)
161 The following attributes can be specified as arguments to WriteMakefile()
162 or as NAME=VALUE pairs on the command line:
164 This description is not yet documented; you can get at the description
166 C<perl Makefile.PL help> (if you already have a basic Makefile.PL)
168 C<perl -e 'use ExtUtils::MakeMaker qw(&help); &help;'>
170 =head2 Overriding MakeMaker Methods
172 If you cannot achieve the desired Makefile behaviour by specifying
173 attributes you may define private subroutines in the Makefile.PL.
174 Each subroutines returns the text it wishes to have written to
175 the Makefile. To override a section of the Makefile you can
178 sub MY::c_o { "new literal text" }
180 or you can edit the default by saying something like:
182 sub MY::c_o { $_=MM->c_o; s/old text/new text/; $_ }
184 If you still need a different solution, try to develop another
185 subroutine, that fits your needs and submit the diffs to
186 perl5-porters@nicoh.com or comp.lang.perl as appropriate.
191 Andy Dougherty <doughera@lafcol.lafayette.edu>, Andreas Koenig
192 <k@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk>
194 =head1 MODIFICATION HISTORY
196 v1, August 1994; by Andreas Koenig. Based on Andy Dougherty's Makefile.SH.
197 v2, September 1994 by Tim Bunce.
198 v3.0 October 1994 by Tim Bunce.
199 v3.1 November 11th 1994 by Tim Bunce.
200 v3.2 November 18th 1994 by Tim Bunce.
201 v3.3 November 27th 1994 by Andreas Koenig.
202 v3.4 December 7th 1994 by Andreas Koenig and Tim Bunce.
203 v3.5 December 15th 1994 by Tim Bunce.
204 v3.6 December 15th 1994 by Tim Bunce.
205 v3.7 December 30th 1994 By Tim Bunce
206 v3.8 January 17th 1995 By Andreas Koenig and Tim Bunce
208 v3.9 January 19th 1995 By Tim Bunce
210 Added ~ processing to parse_args to allow perl Makefile.PL X=~/path.
211 Added warning about LDTARGET to LDFROM attribute name change.
212 Fallback INST_ARCHLIB is INST_LIB, or INST_LIB/$archname if it exists.
213 Tightened up dependency checking of Makefile against config.sh etc.
214 INST_STATIC is now INST_ARCHLIBDIR/BASEEXT.a for later make-a-perl.
215 AUTOSPLITFILE tidied up (AutoSplit patch included in this version).
216 MKPATH now skips inner loop if directory already exists.
217 The dynamic_lib section was revised with explicit dec_osf support added.
218 Make clean now renames Makefile to Makefile.old (make_ext also patched).
219 The large initialize function has been split into smaller pieces.
220 Added I_PERL_LIBS to simplify -I paths for PERL_*LIB.
222 v3.10 January 23rd 1995 By Tim Bunce
224 miniperl now given preference when defining PERL. This improves the
225 reliability of ext/*/Makefile's recreating themselves if needed.
226 $(XS), $(C) and $(H) renamed to XS_FILES C_FILES and H_FILES.
227 INST_STATIC now INST_ARCHLIBDIR/BASEEXT.a (alongside INST_DYNAMIC).
228 Static lib no longer copied back to local directory.
230 v3.11 January 24th 1995 By Andreas Koenig
232 DynaLoader.c was not deleted by clean target, now fixed.
233 Added PMDIR attribute that allows directories to be named that contain
234 only *.p[pl] files to be installed into INST_LIB. Added some documentation.
236 v4.00 January 24th 1995 By Tim Bunce
238 Revised some of the documentation. Changed version number to 4.00 to
239 avoid problems caused by my earlier poor choice of 3.10! Renamed PMDIR
240 to PMLIBDIRS and restructured find code to use inherited MY->libscan.
241 Added ability to say: "perl Makefile.PL help" to get help.
242 Added ability to say: "perl Makefile.PL verbose" to get debugging.
243 Added MakeMaker version number to generated Makefiles.
245 v4.01 January 25th 1995 By Tim Bunce
247 Changes in the section that deals with PMLIBDIRS: some pm files were
248 put into INST_LIB instead of INST_LIBDIR.
250 v4.02 January 29th 1995 By Andreas Koenig
252 Enabled the use of the XXX_cflags variable from Config.pm for nested
253 extensions: to change e.g. the $Config{"ccflags"} variable on the NeXT
254 for the nTk::pTk extension, say
255 nTk__pTk_cflags='ccflags="-posix $ccflags"'
258 Hints may now be put in a hints/*.sh file within the the module's
259 directory tree. Any *.sh file in that directory acts as if it had been
260 parsed during the perl build process.
262 Added O_FILES, which is an array like C_FILES. Done so to add a
263 dependency O_FILES from H_FILES. This has the effect, that the
264 extension gets rebuilt after some headerfiles have changed.
266 Made life easier in some "I've just edited config.sh" situations and
267 reduce the risk of "MakeMaker is being pedantic" complaints by letting
268 the Makefile proceed with a warning if Config.pm is out of date (Tim's
271 $Verbose now passed to the findperl routine, to get debugging output
274 Make clean now also deletes the ./blib directory.
276 Added lots of ideas of Charles Bailey that enable VMS support.
278 v4.03 January 30th 1995 By Andreas Koenig
280 check_hints() now also called within runsubdirpl(). More VMS code
281 included. Trivial cosmetics.
285 MakeMaker development work still to be done:
287 Needs more complete documentation.
289 Add a html: target when there has been found a general solution to
290 installing html files.
295 # We allow extension-specific hints files. If we find one we act as if Config.pm
296 # had read the contents
298 # First we look for the best hintsfile we have
300 my($hint)="$Config{'osname'}_$Config{'osvers'}";
303 opendir DIR, "hints";
304 while (defined ($_ = readdir DIR)) {
306 next unless s/\.sh$//;
307 next unless /^$Config{'osname'}/;
308 # Don't trust a hintfile for a later OS version:
317 return unless @goodhints; # There was no hintsfile
318 # the last one in lexical ordering is our choice:
319 $hint=(reverse sort @goodhints)[0];
321 # execute the hintsfile:
322 system "/bin/sh hints/$hint.sh" unless $Is_VMS;
323 # Read the hintsfile and process it similarly as in configpm
324 open HINT, "hints/$hint.sh";
327 next if /^\s*$/; # empty lines
328 next if /^\s*#/; # comments
329 s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/;
330 next unless (m/^(\w+)='(.*)'\s*$/);
335 # The lines we found take precedence over those in Config.pm:
336 $Config::config_sh = "@v_others" . $Config::config_sh;
339 # Setup dummy package:
340 # MY exists for overriding methods to be defined within
341 unshift(@MY::ISA, qw(MM));
343 # Dummy package MM inherits actual methods from OS-specific
344 # default packages. We use this intermediate package so
345 # MY->func() can call MM->func() and get the proper
346 # default routine without having to know under what OS
348 unshift(@MM::ISA, $Is_VMS ? qw(ExtUtils::MM_VMS MM_Unix) : qw(MM_Unix));
350 $Attrib_Help = <<'END';
351 NAME: Perl module name for this extension (DBD::Oracle)
352 This will default to the directory name but should
353 be explicitly defined in the Makefile.PL.
355 DISTNAME: Your name for distributing the package (by tar file)
356 This defaults to NAME above.
358 VERSION: Your version number for distributing the package.
359 This defaults to 0.1.
361 INST_LIB: Perl library directory to install the module into.
362 INST_ARCHLIB: Perl architecture-dependent library to install into
363 (defaults to INST_LIB)
365 PERL_LIB: Directory containing the Perl library to use.
366 PERL_SRC: Directory containing the Perl source code
367 (use of this should be avoided, it may be undefined)
369 INC: Include file dirs eg: '-I/usr/5include -I/path/to/inc'
370 DEFINE: something like "-DHAVE_UNISTD_H"
371 OBJECT: List of object files, defaults to '$(BASEEXT).o',
372 but can be a long string containing all object files,
373 e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
374 MYEXTLIB: If the extension links to a library that it builds
375 set this to the name of the library (see SDBM_File)
377 LIBS: An anonymous array of alternative library specifications
378 to be searched for (in order) until at least one library
380 'LIBS' => [ "-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs" ]
381 Mind, that any element of the array contains a complete
382 set of arguments for the ld command. So do not specify
383 'LIBS' => ["-ltcl", "-ltk", "-lX11" ], #wrong
384 See ODBM_File/Makefile.PL for an example, where an
385 array is needed. If you specify a scalar as in
386 'LIBS' => "-ltcl -ltk -lX11"
387 MakeMaker will turn it into an array with one element.
389 LDFROM: defaults to "$(OBJECT)" and is used in the ld command
390 to specify what files to link/load from
391 (also see dynamic_lib below for how to specify ld flags)
393 DIR: Ref to array of subdirectories containing Makefile.PLs
394 e.g. [ 'sdbm' ] in ext/SDBM_File
396 PMLIBDIRS: Ref to array of subdirectories containing library files.
397 Defaults to [ 'lib', $(BASEEXT) ]. The directories will
398 be scanned and any *.pm and *.pl files they contain will
399 be installed in the corresponding location in the library.
400 A MY::libscan() function can be used to alter the behaviour.
401 Defining PM in the Makefile.PL will override PMLIBDIRS.
403 PM: Hashref of .pm files and *.pl files to be installed.
404 e.g. { 'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm' }
405 By default this will include *.pm and *.pl. If a lib directory
406 exists and is not listed in DIR (above) then any *.pm and
407 *.pl files it contains will also be included by default.
408 Defining PM in the Makefile.PL will override PMLIBDIRS.
410 XS: Hashref of .xs files. MakeMaker will default this.
411 e.g. { 'name_of_file.xs' => 'name_of_file.c' }
412 The .c files will automatically be included in the list
413 of files deleted by a make clean.
415 C: Ref to array of *.c file names. Initialised from a directory scan
416 and the values portion of the XS attribute hash. This is not
417 currently used by MakeMaker but may be handy in Makefile.PLs.
419 H: Ref to array of *.h file names. Similar to C: above.
421 LINKTYPE: =>'static' or 'dynamic' (default unless usedl=undef in config.sh)
422 Should only be used to force static linking (also see linkext below).
424 DL_FUNCS: Hashref of symbol names for routines to be made available as
425 universal symbols. Each key/value pair consists of the package
426 name and an array of routine names in that package. Used only
427 under AIX (export lists) and VMS (linker options) at present.
428 The routine names supplied will be expanded in the same way
429 as XSUB names are expanded by the XS() macro.
430 Defaults to { "$(NAME)" => [ "boot_$(NAME)" ] }.
431 (e.g. { "RPC" => [qw( boot_rpcb rpcb_gettime getnetconfigent )],
432 "NetconfigPtr" => [ 'DESTROY'] } )
434 DL_VARS: Array of symbol names for variables to be made available as
435 universal symbols. Used only under AIX (export lists) and VMS
436 (linker options) at present. Defaults to [].
437 (e.g. [ qw( Foo_version Foo_numstreams Foo_tree ) ])
439 CONFIG: =>[qw(archname manext)] defines ARCHNAME & MANEXT from config.sh
440 SKIP: =>[qw(name1 name2)] skip (do not write) sections of the Makefile
445 Additional lowercase attributes can be used to pass parameters to the
446 methods which implement that part of the Makefile. These are not
449 installpm: {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'}
450 linkext: {LINKTYPE => 'static', 'dynamic' or ''}
451 dynamic_lib: {ARMAYBE => 'ar', OTHERLDFLAGS => '...'}
452 clean: {FILES => "*.xyz foo"}
453 realclean: {FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
454 distclean: {TARNAME=>'MyTarFile', TARFLAGS=>'cvfF', COMPRESS=>'gzip'}
455 tool_autosplit: {MAXLEN => 8}
458 sub help {print $Attrib_Help;}
460 @MM_Sections_spec = (
461 'post_initialize' => {},
462 'const_config' => {},
464 'const_loadlibs' => {},
466 'tool_autosplit' => {},
469 'post_constants' => {},
493 %MM_Sections = @MM_Sections_spec; # looses section ordering
494 @MM_Sections = grep(!ref, @MM_Sections_spec); # keeps order
496 %Recognized_Att_Keys = %MM_Sections; # All sections are valid keys.
497 foreach(split(/\n/,$Attrib_Help)){
499 next unless m/^\s*(\w+):\s*(.*)/;
500 $Recognized_Att_Keys{$1} = $2;
501 print "Attribute '$1' => '$2'\n" if ($Verbose >= 2);
509 if ($section eq 'dynamic') {
510 warn "Warning (non-fatal): Target 'dynamic' depends on targets "
511 . "in skipped section 'dynamic_bs'\n"
512 if $skip{'dynamic_bs'} && $Verbose;
513 warn "Warning (non-fatal): Target 'dynamic' depends on targets "
514 . "in skipped section 'dynamic_lib'\n"
515 if $skip{'dynamic_lib'} && $Verbose;
517 if ($section eq 'dynamic_lib') {
518 warn "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on "
519 . "targets in skipped section 'dynamic_bs'\n"
520 if $skip{'dynamic_bs'} && $Verbose;
522 if ($section eq 'static') {
523 warn "Warning (non-fatal): Target 'static' depends on targets "
524 . "in skipped section 'static_lib'\n"
525 if $skip{'static_lib'} && $Verbose;
527 return 'skipped' if $skip{$section};
536 print STDOUT "MakeMaker" if $Verbose;
538 parse_args(\%att, @ARGV);
539 my(%initial_att) = %att; # record initial attributes
543 print STDOUT "Writing Makefile for $att{NAME}";
548 unlink("Makefile", "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : '');
549 open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!";
550 select MAKE; $|=1; select STDOUT;
552 print MAKE "# This Makefile is for the $att{NAME} extension to perl.\n#";
553 print MAKE "# It was generated automatically by MakeMaker version $Version from the contents";
554 print MAKE "# of Makefile.PL. Don't edit this file, edit Makefile.PL instead.";
555 print MAKE "#\n# ANY CHANGES MADE HERE WILL BE LOST! \n#";
556 print MAKE "# MakeMaker Parameters: ";
557 foreach $key (sort keys %initial_att){
558 my($v) = neatvalue($initial_att{$key});
560 print MAKE "# $key => $v";
563 # build hash for SKIP to make testing easy
564 %skip = map( ($_,1), @{$att{'SKIP'} || []});
566 foreach $section ( @MM_Sections ){
567 print "Processing Makefile '$section' section" if ($Verbose >= 2);
568 my($skipit) = skipcheck($section);
570 print MAKE "\n# --- MakeMaker $section section $skipit.";
572 my(%a) = %{$att{$section} || {}};
573 print MAKE "\n# --- MakeMaker $section section:";
574 print MAKE "# ",%a if $Verbose;
575 print(MAKE MY->nicetext(MY->$section( %a )));
580 print MAKE "\n# Full list of MakeMaker attribute values:";
581 foreach $key (sort keys %att){
582 my($v) = neatvalue($att{$key});
584 print MAKE "# $key => $v";
588 print MAKE "\n# End.";
590 my($finalname) = $Is_VMS ? "Descrip.MMS" : "Makefile";
591 rename("MakeMaker.tmp", $finalname);
593 chmod 0644, $finalname;
594 system("$Config{'eunicefix'} $finalname") unless $Config{'eunicefix'} eq ":";
601 parse_args(\%att, @ARGV);
607 parse_args(\%att, @ARGV);
612 my($attr, @args) = @_;
614 unless (m/(.*?)=(.*)/){
615 help(),exit 1 if m/^help$/;
616 ++$Verbose if m/^verb/;
619 my($name, $value) = ($1, $2);
620 if ($value =~ m/^~(\w+)?/){ # tilde with optional username
621 my($home) = ($1) ? (getpwnam($1))[7] : (getpwuid($>))[7];
622 $value =~ s/^~(\w+)?/$home/;
624 $$attr{$name} = $value;
626 # catch old-style 'potential_libs' and inform user how to 'upgrade'
627 if (defined $$attr{'potential_libs'}){
628 my($msg)="'potential_libs' => '$$attr{potential_libs}' should be";
629 if ($$attr{'potential_libs'}){
630 print STDERR "$msg changed to:\n\t'LIBS' => ['$$attr{potential_libs}']\n";
632 print STDERR "$msg deleted.\n";
634 $$attr{LIBS} = [$$attr{'potential_libs'}];
635 delete $$attr{'potential_libs'};
637 # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
638 if (defined $$attr{'ARMAYBE'}){
639 my($armaybe) = $$attr{'ARMAYBE'};
640 print STDERR "ARMAYBE => '$armaybe' should be changed to:\n",
641 "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
642 my(%dl) = %{$$attr{'dynamic_lib'} || {}};
643 $$attr{'dynamic_lib'} = { %dl, ARMAYBE => $armaybe};
644 delete $$attr{'ARMAYBE'};
646 if (defined $$attr{'LDTARGET'}){
647 print STDERR "LDTARGET should be changed to LDFROM\n";
648 $$attr{'LDFROM'} = $$attr{'LDTARGET'};
649 delete $$attr{'LDTARGET'};
651 foreach(sort keys %{$attr}){
652 print STDOUT " $_ => ".neatvalue($$attr{$_}) if ($Verbose);
653 warn "'$_' is not a known MakeMaker parameter name.\n"
654 unless exists $Recognized_Att_Keys{$_};
662 return "'$v'" unless $t;
663 return "[ ".join(', ',map("'$_'",@$v))." ]" if ($t eq 'ARRAY');
664 return "$v" unless $t eq 'HASH';
666 push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v);
667 return "{ ".join(', ',@m)." }";
671 # ------ Define the MakeMaker default methods in package MM_Unix ------
680 Exporter::import('ExtUtils::MakeMaker',
681 qw(%att %skip %Recognized_Att_Keys $Verbose));
683 # These attributes cannot be overridden externally
684 @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3;
686 if ($Is_VMS = $Config{'osname'} eq 'VMS') {
687 require File::VMSspec;
688 import File::VMSspec 'vmsify';
693 # Find out directory name. This may contain the extension name.
694 my($pwd) = fastcwd(); # from Cwd.pm
696 # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
698 # *Real* information: where did we get these two from? ...
699 $inc_config_dir = dirname($INC{'Config.pm'});
700 $inc_carp_dir = dirname($INC{'Carp.pm'});
702 # Typically PERL_* and INST_* will be identical but that need
703 # not be the case (e.g., installing into project libraries etc).
705 # Perl Macro: With source No source
706 # PERL_LIB ../../lib /usr/local/lib/perl5
707 # PERL_ARCHLIB ../../lib /usr/local/lib/perl5/sun4-sunos
708 # PERL_SRC ../.. (undefined)
710 # INST Macro: Locally Publically
711 # INST_LIB ../../lib ./blib
712 # INST_ARCHLIB ../../lib ./blib
714 unless ($att{PERL_SRC}){
715 foreach(qw(../.. ../../.. ../../../..)){
716 ($att{PERL_SRC}=$_, last) if -f "$_/config.sh";
719 unless ($att{PERL_SRC}){
720 warn "Unable to locate perl source.\n";
721 # we should also consider $ENV{PERL5LIB} here
722 $att{PERL_LIB} = $Config{'privlib'} unless $att{PERL_LIB};
723 $att{PERL_ARCHLIB} = $Config{'archlib'} unless $att{PERL_ARCHLIB};
724 $att{PERL_INC} = "$att{PERL_ARCHLIB}/CORE"; # wild guess for now
725 die "Try setting PERL_SRC in Makefile.PL or on command line.\n"
726 unless (-f "$att{PERL_INC}/perl.h");
728 $att{PERL_LIB} = "$att{PERL_SRC}/lib" unless $att{PERL_LIB};
729 $att{PERL_ARCHLIB} = $att{PERL_LIB};
730 $att{PERL_INC} = $att{PERL_SRC};
733 # INST_LIB typically pre-set if building an extension after
734 # perl has been built and installed. Setting INST_LIB allows
735 # you to build directly into privlib and avoid installperl.
736 unless ($att{INST_LIB}){
737 if (defined $att{PERL_SRC}) {
738 $att{INST_LIB} = $att{PERL_LIB};
740 $att{INST_LIB} = "$pwd/blib";
743 # Try to work out what INST_ARCHLIB should be if not set:
744 unless ($att{INST_ARCHLIB}){
746 "$pwd/blib" => "$pwd/blib", # our private build lib
747 $att{PERL_LIB} => $att{PERL_ARCHLIB},
748 $Config{'privlib'} => $Config{'archlib'},
749 $Config{'installprivlib'} => $Config{'installarchlib'},
750 $inc_carp_dir => $inc_config_dir,
752 $att{INST_ARCHLIB} = $archmap{$att{INST_LIB}};
753 unless($att{INST_ARCHLIB}){
754 # Oh dear, we'll have to default it and warn the user
755 my($archname) = $Config{'archname'};
756 if (-d "$att{INST_LIB}/$archname"){
757 $att{INST_ARCHLIB} = "$att{INST_LIB}/$archname";
758 warn "Defaulting INST_ARCHLIB to INST_LIB/$archname\n";
760 $att{INST_ARCHLIB} = $att{INST_LIB};
761 warn "Warning: Defaulting INST_ARCHLIB to INST_LIB ",
762 "(not architecture independent).\n";
767 # make a few simple checks
768 die "PERL_LIB ($att{PERL_LIB}) is not a perl library directory"
769 unless (-f "$att{PERL_LIB}/Exporter.pm");
771 # --- Initialize Module Name and Paths
773 # NAME = The perl module name for this extension (eg DBD::Oracle).
774 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
775 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
776 # ROOTEXT = Directory part of FULLEXT with leading /.
777 unless($att{NAME}){ # we have to guess our name
780 $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.(.*)\]:$1:i);
781 ($att{NAME}=$name) =~ s#[.\]]#::#g;
783 $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::);
784 ($att{NAME} =$name) =~ s#/#::#g;
787 ($att{FULLEXT} =$att{NAME}) =~ s#::#/#g ; #eg. BSD/Foo/Socket
788 ($att{BASEEXT} =$att{NAME}) =~ s#.*::##; #eg. Socket
789 ($att{ROOTEXT} =$att{FULLEXT}) =~ s#/?\Q$att{BASEEXT}\E$## ; # eg. /BSD/Foo
790 $att{ROOTEXT} = ($Is_VMS ? '' : '/') . $att{ROOTEXT} if $att{ROOTEXT};
792 ($att{DISTNAME}=$att{NAME}) =~ s#(::)#-#g;
793 $att{VERSION} = "0.1" unless $att{VERSION};
796 # --- Initialize Perl Binary Locations
798 # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
799 # will be working versions of perl 5. miniperl has priority over perl
800 # for PERL to ensure that $(PERL) is usable while building ./ext/*
801 $att{'PERL'} = MY->find_perl(5.0, [ qw(miniperl perl) ],
802 [ $att{PERL_SRC}, split(":", $ENV{PATH}), $Config{'bin'} ], $Verbose )
803 unless ($att{'PERL'} && -x $att{'PERL'});
805 # Define 'FULLPERL' to be a non-miniperl (used in test: target)
806 ($att{'FULLPERL'} = $att{'PERL'}) =~ s/miniperl/perl/
807 unless ($att{'FULLPERL'} && -x $att{'FULLPERL'});
810 $att{'PERL'} = 'MCR ' . vmsify($att{'PERL'});
811 $att{'FULLPERL'} = 'MCR ' . vmsify($att{'FULLPERL'});
816 sub init_dirscan { # --- File and Directory Lists (.xs .pm etc)
818 my($name, %dir, %xs, %c, %h, %ignore);
819 local(%pm); #the sub in find() has to see this hash
820 $ignore{'test.pl'} = 1;
821 $ignore{'makefile.pl'} = 1 if $Is_VMS;
822 foreach $name (lsdir(".")){
823 next if ($name =~ /^\./ or $ignore{$name});
825 $dir{$name} = $name if (-f "$name/Makefile.PL");
826 } elsif ($name =~ /\.xs$/){
827 my($c); ($c = $name) =~ s/\.xs$/.c/;
830 } elsif ($name =~ /\.c$/){
832 } elsif ($name =~ /\.h$/){
834 } elsif ($name =~ /\.p[ml]$/){
835 $pm{$name} = "\$(INST_LIBDIR)/$name";
839 # Some larger extensions often wish to install a number of *.pm/pl
840 # files into the library in various locations.
842 # The attribute PMLIBDIRS holds an array reference which lists
843 # subdirectories which we should search for library files to
844 # install. PMLIBDIRS defaults to [ 'lib', $att{BASEEXT} ].
845 # We recursively search through the named directories (skipping
846 # any which don't exist or contain Makefile.PL files).
848 # For each *.pm or *.pl file found MY->libscan() is called with
849 # the default installation path in $_. The return value of libscan
850 # defines the actual installation location.
851 # The default libscan function simply returns $_.
852 # The file is skipped if libscan returns false.
854 # The default installation location passed to libscan in $_ is:
856 # ./*.pm => $(INST_LIBDIR)/*.pm
857 # ./xyz/... => $(INST_LIBDIR)/xyz/...
858 # ./lib/... => $(INST_LIB)/...
860 # In this way the 'lib' directory is seen as the root of the actual
861 # perl library whereas the others are relative to INST_LIBDIR
862 # (which includes ROOTEXT). This is a subtle distinction but one
863 # that's important for nested modules.
865 $att{PMLIBDIRS} = [ 'lib', $att{BASEEXT} ] unless $att{PMLIBDIRS};
867 #only existing directories that aren't in $dir are allowed
868 @{$att{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$att{PMLIBDIRS}};
870 if (@{$att{PMLIBDIRS}}){
871 print "Searching PMLIBDIRS: @{$att{PMLIBDIRS}}"
873 use File::Find; # try changing to require !
874 File::Find::find(sub {
875 return unless m/\.p[ml]$/;
876 my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
877 $prefix = '$(INST_LIB)' if ($path =~ s:^lib/::);
878 local($_) = "$prefix/$path";
879 my($inst) = MY->libscan();
880 print "libscan($path) => '$inst'" if ($Verbose >= 2);
883 }, @{$att{PMLIBDIRS}});
886 $att{DIR} = [sort keys %dir] unless $att{DIRS};
887 $att{XS} = \%xs unless $att{XS};
888 $att{PM} = \%pm unless $att{PM};
889 $att{C} = [sort keys %c] unless $att{C};
890 my(@o_files) = @{$att{C}};
891 my($sufx) = $Is_VMS ? '.obj' : '.o';
892 $att{O_FILES} = [grep s/\.c$/$sufx/, @o_files] ;
893 $att{H} = [sort keys %h] unless $att{H};
901 sub init_others { # --- Initialize Other Attributes
903 for $key (keys(%Recognized_Att_Keys), keys(%Other_Att_Keys)){
904 # avoid warnings for uninitialized vars
905 next if exists $att{$key};
909 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $att{'LIBS'}
910 # Lets look at $att{LIBS} carefully: It may be an anon array, a string or
911 # undefined. In any case we turn it into an anon array:
912 $att{LIBS}=[] unless $att{LIBS};
913 $att{LIBS}=[$att{LIBS}] if ref \$att{LIBS} eq SCALAR;
914 foreach ( @{$att{'LIBS'}} ){
915 s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
916 my(@libs) = MY->extliblist($_);
917 if ($libs[0] or $libs[1] or $libs[2]){
918 @att{EXTRALIBS, BSLOADLIBS, LDLOADLIBS} = @libs;
923 warn "CONFIG must be an array ref\n"
924 if ($att{CONFIG} and ref $att{CONFIG} ne 'ARRAY');
925 $att{CONFIG} = [] unless (ref $att{CONFIG});
926 push(@{$att{CONFIG}},
927 qw( cc libc ldflags lddlflags ccdlflags cccdlflags
928 ranlib so dlext dlsrc installprivlib installarchlib
930 push(@{$att{CONFIG}}, 'shellflags') if $Config{'shellflags'};
933 $att{OBJECT} = '$(BASEEXT).obj' unless $att{OBJECT};
934 $att{OBJECT} =~ s/[^,\s]\s+/, /g;
935 $att{OBJECT} =~ s/\n+/, /g;
936 $att{OBJECT} =~ s#\.o,#\.obj,#;
938 $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT};
939 $att{OBJECT} =~ s/\n+/ \\\n\t/g;
941 $att{BOOTDEP} = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
942 $att{LD} = ($Config{'ld'} || 'ld') unless $att{LD};
943 $att{LDFROM} = '$(OBJECT)' unless $att{LDFROM};
944 # Sanity check: don't define LINKTYPE = dynamic if we're skipping
945 # the 'dynamic' section of MM. We don't have this problem with
946 # 'static', since we either must use it (%Config says we can't
947 # use dynamic loading) or the caller asked for it explicitly.
948 if (!$att{LINKTYPE}) {
949 $att{LINKTYPE} = grep(/dynamic/,@{$att{SKIP} || []})
951 : ($Config{'usedl'} ? 'dynamic' : 'static');
954 # These get overridden for VMS and maybe some other systems
956 $att{MAKEFILE} = "Makefile";
957 $att{RM_F} = "rm -f";
958 $att{RM_RF} = "rm -rf";
959 $att{TOUCH} = "touch";
966 my($dir, $regex) = @_;
968 opendir(DIR, $_[0] || ".") or die "opendir: $!";
971 @ls = grep(/$regex/, @ls) if $regex;
977 my($self, $ver, $names, $dirs, $trace) = @_;
979 print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n"
981 foreach $dir (@$dirs){
982 next unless defined $dir; # $att{PERL_SRC} may be undefined
983 foreach $name (@$names){
984 print "checking $dir/$name\n" if ($trace >= 2);
986 $name .= ".exe" unless -x "$dir/$name";
988 next unless -x "$dir/$name";
989 print "executing $dir/$name\n" if ($trace);
992 my($vmscmd) = 'MCR ' . vmsify("$dir/$name");
993 $out = `$vmscmd -e "require $ver; print ""VER_OK\n"""`;
995 $out = `$dir/$name -e 'require $ver; print "VER_OK\n" ' 2>&1`;
997 return "$dir/$name" if $out =~ /VER_OK/;
1000 warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1001 0; # false and not empty
1005 sub post_initialize{
1015 DISTNAME = $att{DISTNAME}
1016 VERSION = $att{VERSION}
1018 # In which library should we install this extension?
1019 # This is typically the same as PERL_LIB.
1020 # (also see INST_LIBDIR and relationship to ROOTEXT)
1021 INST_LIB = $att{INST_LIB}
1022 INST_ARCHLIB = $att{INST_ARCHLIB}
1024 # Perl library to use when building the extension
1025 PERL_LIB = $att{PERL_LIB}
1026 PERL_ARCHLIB = $att{PERL_ARCHLIB}
1029 # Define I_PERL_LIBS to include the required -Ipaths
1030 # To be cute we only include PERL_ARCHLIB if different
1031 # To be portable we add quotes for VMS
1032 my(@i_perl_libs) = qw{-I$(PERL_ARCHLIB) -I$(PERL_LIB)};
1033 shift(@i_perl_libs) if ($att{PERL_ARCHLIB} eq $att{PERL_LIB});
1035 push @m, "I_PERL_LIBS = \"".join('" "',@i_perl_libs)."\"\n";
1037 push @m, "I_PERL_LIBS = ".join(' ',@i_perl_libs)."\n";
1041 # Where is the perl source code located? (Eventually we should
1042 # be able to build extensions without requiring the perl source
1043 # but that's a way off yet).
1044 PERL_SRC = $att{PERL_SRC}
1045 # Perl header files (will eventually be under PERL_LIB)
1046 PERL_INC = $att{PERL_INC}
1049 FULLPERL = $att{'FULLPERL'}
1052 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
1053 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
1054 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
1055 FULLEXT = $att{FULLEXT}
1056 BASEEXT = $att{BASEEXT}
1057 ROOTEXT = $att{ROOTEXT}
1061 DEFINE = $att{DEFINE}
1062 OBJECT = $att{OBJECT}
1063 LDFROM = $att{LDFROM}
1064 LINKTYPE = $att{LINKTYPE}
1066 # Handy lists of source code files:
1067 XS_FILES= ".join(" \\\n\t", sort keys %{$att{XS}})."
1068 C_FILES = ".join(" \\\n\t", @{$att{C}})."
1069 O_FILES = ".join(" \\\n\t", @{$att{O_FILES}})."
1070 H_FILES = ".join(" \\\n\t", @{$att{H}})."
1076 .PHONY: all config static dynamic test linkext
1078 # This extension may link to it's own library (see SDBM_File)
1079 MYEXTLIB = $att{MYEXTLIB}
1081 # Where is the Config information that we are using/depend on
1082 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
1086 # Where to put things:
1087 INST_LIBDIR = $(INST_LIB)$(ROOTEXT)
1088 INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT)
1090 INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
1091 INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
1095 INST_STATIC = $(INST_ARCHAUTODIR)/$(BASEEXT).a
1096 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(BASEEXT).$(DLEXT)
1097 INST_BOOT = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
1098 INST_PM = '.join(" \\\n\t", sort values %{$att{PM}}).'
1106 # This is implemented in the same manner as extliblist,
1107 # e.g., do both and compare results during the transition period.
1108 my($cc,$ccflags,$optimize,$large,$split, $shflags)
1109 = @Config{qw(cc ccflags optimize large split shellflags)};
1110 $shflags = '' unless $shflags;
1113 chop($old = `cd $att{PERL_SRC}; sh $shflags ./cflags $att{BASEEXT}.c 2>/dev/null`)
1117 ( $name = $att{NAME} . "_cflags" ) =~ s/:/_/g ;
1118 if ($prog = $Config{$name}) {
1119 # Expand hints for this extension via the shell
1120 print STDERR "Processing $name hint:\n" if $Verbose;
1122 ccflags=\"$ccflags\"
1123 optimize=\"$optimize\"
1128 echo ccflags=\$ccflags
1129 echo optimize=\$optimize
1136 if ($line =~ /(.*?)=\s*(.*)\s*$/){
1138 print STDERR " $1 = $2" if $Verbose;
1140 print STDERR "Unrecognised result from hint: '$line'\n";
1143 ($cc,$ccflags,$optimize,$large,$split)=@cflags{qw(cc ccflags optimize large split)};
1146 my($new) = "$cc -c $ccflags $optimize $large $split";
1147 if (defined($old) and $new ne $old) {
1148 warn "Warning (non-fatal): cflags evaluation in MakeMaker differs from shell output\n"
1149 ." package: $att{NAME}\n"
1152 ." Using 'old' set.\n"
1153 ."Please notify perl5-porters\@nicoh.com\n";
1155 my($cccmd)=($old) ? $old : $new;
1160 # --- Constants Sections ---
1164 push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
1166 foreach $m (@{$att{'CONFIG'}}){
1167 next if $once_only{$m};
1168 warn "CONFIG key '$m' does not exist in Config.pm\n"
1169 unless exists $Config{$m};
1170 push @m, "\U$m\E = $Config{$m}\n";
1179 # $att{NAME} might depend on some other libraries:
1180 # (These comments may need revising:)
1182 # Dependent libraries can be linked in one of three ways:
1184 # 1. (For static extensions) by the ld command when the perl binary
1185 # is linked with the extension library. See EXTRALIBS below.
1187 # 2. (For dynamic extensions) by the ld command when the shared
1188 # object is built/linked. See LDLOADLIBS below.
1190 # 3. (For dynamic extensions) by the DynaLoader when the shared
1191 # object is loaded. See BSLOADLIBS below.
1193 # EXTRALIBS = List of libraries that need to be linked with when
1194 # linking a perl binary which includes this extension
1195 # Only those libraries that actually exist are included.
1196 # These are written to a file and used when linking perl.
1198 # LDLOADLIBS = List of those libraries which can or must be linked into
1199 # the shared library when created using ld. These may be
1200 # static or dynamic libraries.
1202 # BSLOADLIBS = List of those libraries that are needed but can be
1203 # linked in dynamically at run time on this platform.
1204 # SunOS/Solaris does not need this because ld records
1205 # the information (from LDLOADLIBS) into the object file.
1206 # This list is used to create a .bs (bootstrap) file.
1208 EXTRALIBS = $att{'EXTRALIBS'}
1209 LDLOADLIBS = $att{'LDLOADLIBS'}
1210 BSLOADLIBS = $att{'BSLOADLIBS'}
1215 # --- Tool Sections ---
1218 my($self, %attribs) = @_;
1220 $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
1222 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1223 # Remark: the "" around the -I switches are helpful for the VMS support
1224 AUTOSPLITFILE = $(PERL) $(I_PERL_LIBS) -e 'use AutoSplit;}.$asl.q{ \
1225 AutoSplit::autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
1231 my($xsdir) = '$(PERL_LIB)/ExtUtils';
1232 # drop back to old location if xsubpp is not in new location yet
1233 $xsdir = '$(PERL_SRC)/ext' unless (-f "$att{PERL_LIB}/ExtUtils/xsubpp");
1234 my(@tmdeps) = ('$(XSUBPPDIR)/typemap');
1235 push(@tmdeps, "typemap") if -f "typemap";
1236 my(@tmargs) = map("-typemap $_", @tmdeps);
1239 XSUBPP = \$(XSUBPPDIR)/xsubpp
1240 XSUBPPDEPS = @tmdeps
1241 XSUBPPARGS = @tmargs
1256 # The following is a portable way to say mkdir -p
1257 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;'
1267 # --- Translation Sections ---
1271 $(O_FILES): $(H_FILES)
1274 $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1281 $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $@
1285 sub xs_o { # many makes are too dumb to use xs_c then c_o
1288 $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
1289 $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1294 # --- Target Sections ---
1298 all :: config linkext $(INST_PM)
1301 config :: '.$att{MAKEFILE}.'
1302 @$(MKPATH) $(INST_LIBDIR) $(INST_ARCHAUTODIR)
1307 my($self, %attribs) = @_;
1308 # LINKTYPE => static or dynamic
1309 my($linktype) = $attribs{LINKTYPE} || '$(LINKTYPE)';
1311 linkext :: $linktype
1317 my($self,%attribs) = @_;
1319 return '' if ($Config{'osname'} ne 'AIX');
1321 my($funcs) = $attribs{DL_FUNCS} || $att{DL_FUNCS} || {};
1322 my($vars) = $attribs{DL_VARS} || $att{DL_VARS} || [];
1326 dynamic :: $att{BASEEXT}.exp
1328 ") unless $skip{'dynamic'};
1331 static :: $att{BASEEXT}.exp
1333 ") unless $skip{'static'};
1336 $att{BASEEXT}.exp: Makefile.PL
1337 ",' $(PERL) $(I_PERL_LIBS) -e \'use ExtUtils::MakeMaker; \\
1338 mksymlists(DL_FUNCS => ',neatvalue($att{DL_FUNCS}),', DL_VARS => ',neatvalue($att{DL_VARS}),')\'
1344 # --- Dynamic Loading Sections ---
1348 # $(INST_PM) has been moved to the all: target.
1349 # It remains here for awhile to allow for old usage: "make dynamic"
1350 dynamic :: '.$att{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
1356 my($self, %attribs) = @_;
1358 BOOTSTRAP = '."$att{BASEEXT}.bs".'
1360 # As MakeMaker mkbootstrap might not write a file (if none is required)
1361 # we use touch to prevent make continually trying to remake it.
1362 # The DynaLoader only reads a non-empty file.
1363 $(BOOTSTRAP): '."$att{MAKEFILE} $att{BOOTDEP}".'
1364 $(PERL) $(I_PERL_LIBS) \
1365 -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(BSLOADLIBS)");\' \
1366 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) PERL_SRC=$(PERL_SRC) NAME=$(NAME)
1367 @$(TOUCH) $(BOOTSTRAP)
1369 $(INST_BOOT): $(BOOTSTRAP)
1370 @'.$att{RM_RF}.' $(INST_BOOT)
1371 '.$att{CP}.' $(BOOTSTRAP) $(INST_BOOT)
1377 my($self, %attribs) = @_;
1378 my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
1379 my($armaybe) = $attribs{ARMAYBE} || $att{ARMAYBE} || ":";
1380 my($ldfrom) = '$(LDFROM)';
1381 my($osname) = $Config{'osname'};
1382 $armaybe = 'ar' if ($osname eq 'dec_osf' and $armaybe eq ':');
1385 # This section creates the dynamically loadable $(INST_DYNAMIC)
1386 # from $(OBJECT) and possibly $(MYEXTLIB).
1387 ARMAYBE = '.$armaybe.'
1388 OTHERLDFLAGS = '.$otherldflags.'
1390 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP)
1391 @$(MKPATH) $(INST_ARCHAUTODIR)
1393 if ($armaybe ne ':'){
1395 push(@m,' $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
1396 push(@m,' $(RANLIB) '."$ldfrom\n");
1398 $ldfrom = "-all $ldfrom -none" if ($osname eq 'dec_osf');
1399 push(@m,' $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
1400 ' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS)'."\n");
1405 # --- Static Loading Sections ---
1409 # $(INST_PM) has been moved to the all: target.
1410 # It remains here for awhile to allow for old usage: "make static"
1411 static :: '.$att{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
1419 $(INST_STATIC): $(OBJECT) $(MYEXTLIB)
1421 # If this extension has it's own library (eg SDBM_File)
1422 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
1423 push(@m, " $att{CP} \$(MYEXTLIB) \$\@\n") if $att{MYEXTLIB};
1426 ar cr $@ $(OBJECT) && $(RANLIB) $@
1427 @echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
1429 push(@m, <<'END') if $att{PERL_SRC};
1430 @: Old mechanism - still needed:
1431 @echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
1438 my($self, %attribs) = @_;
1439 # By default .pm files are split into the architecture independent
1440 # library. This is a good thing. If a specific module requires that
1441 # it's .pm files are split into the architecture specific library
1442 # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'}
1443 # Note that installperl currently interferes with this (Config.pm)
1444 # User can disable split by saying: installpm => {SPLITLIB=>''}
1445 my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default
1446 $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB};
1448 foreach $dist (sort keys %{$att{PM}}){
1449 my($inst) = $att{PM}->{$dist};
1450 push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n");
1451 push(@m, MY->installpm_x($dist, $inst, $splitlib));
1457 sub installpm_x { # called by installpm per file
1458 my($self, $dist, $inst, $splitlib) = @_;
1459 my($instdir) = $inst =~ m|(.*)/|;
1463 ".' @'.$att{RM_F}.' $@
1464 @$(MKPATH) '.$instdir.'
1467 push(@m, "\t\$(AUTOSPLITFILE) \$@ $splitlib/auto\n")
1468 if ($splitlib and $inst =~ m/\.pm$/);
1473 # --- Sub-directory Sections ---
1477 # This method provides a mechanism to automatically deal with
1478 # subdirectories containing further Makefile.PL scripts.
1479 # It calls the subdir_x() method for each subdirectory.
1480 foreach(<*/Makefile.PL>){
1481 s:/Makefile\.PL$:: ;
1482 print "Including $_ subdirectory" if ($Verbose);
1483 push(@m, MY->subdir_x($_));
1487 # The default clean, realclean and test targets in this Makefile
1488 # have automatically been given entries for each subdir.
1493 push(@m, "\n# none")
1498 sub runsubdirpl{ # Experimental! See subdir_x section
1499 my($self,$subdir) = @_;
1500 chdir($subdir) or die "chdir($subdir): $!";
1501 ExtUtils::MakeMaker::check_hints();
1502 require "Makefile.PL";
1506 my($self, $subdir) = @_;
1508 # The intention is that the calling Makefile.PL should define the
1509 # $(SUBDIR_MAKEFILE_PL_ARGS) make macro to contain whatever
1510 # information needs to be passed down to the other Makefile.PL scripts.
1511 # If this does not suit your needs you'll need to write your own
1512 # MY::subdir_x() method to override this one.
1514 config :: $subdir/$att{MAKEFILE}
1515 cd $subdir ; \$(MAKE) config INST_LIB=\$(INST_LIB) INST_ARCHLIB=\$(INST_ARCHLIB) LINKTYPE=\$(LINKTYPE)
1517 $subdir/$att{MAKEFILE}: $subdir/Makefile.PL \$(CONFIGDEP)
1518 }.' @echo "Rebuilding $@ ..."
1519 $(PERL) $(I_PERL_LIBS) \\
1520 -e "use ExtUtils::MakeMaker; MM->runsubdirpl(qw('.$subdir.'))" \\
1521 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) $(SUBDIR_MAKEFILE_PL_ARGS)
1522 @echo "Rebuild of $@ complete."
1526 cd $subdir ; \$(MAKE) all LINKTYPE=\$(LINKTYPE)
1532 # --- Cleanup and Distribution Sections ---
1535 my($self, %attribs) = @_;
1538 # Delete temporary files but do not touch installed files. We don\'t delete
1539 # the Makefile here so a later make realclean still has a makefile to use.
1543 # clean subdirectories first
1544 push(@m, map("\t-cd $_ && test -f $att{MAKEFILE} && \$(MAKE) clean\n",@{$att{DIR}}));
1545 my(@otherfiles) = values %{$att{XS}}; # .c files from *.xs files
1546 push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1547 push(@otherfiles, "./blib");
1548 push(@m, " -$att{RM_RF} *~ t/*~ *.o *.a mon.out core so_locations "
1549 ."\$(BOOTSTRAP) \$(BASEEXT).bso @otherfiles\n");
1550 # See realclean and ext/utils/make_ext for usage of Makefile.old
1551 push(@m, " -$att{MV} $att{MAKEFILE} $att{MAKEFILE}.old 2>/dev/null\n");
1552 push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP};
1557 my($self, %attribs) = @_;
1560 # Delete temporary files (via clean) and also delete installed files
1561 realclean purge :: clean
1563 # realclean subdirectories first (already cleaned)
1564 $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
1565 foreach(@{$att{DIR}}){
1566 push(@m, sprintf($sub,$_,"$att{MAKEFILE}.old","-f $att{MAKEFILE}.old"));
1567 push(@m, sprintf($sub,$_,"$att{MAKEFILE}",''));
1569 push(@m, " $att{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
1570 push(@m, " $att{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
1571 push(@m, " $att{RM_F} \$(INST_STATIC) \$(INST_PM)\n");
1572 my(@otherfiles) = ($att{MAKEFILE}, "$att{MAKEFILE}.old"); # Makefiles last
1573 push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1574 push(@m, " $att{RM_RF} @otherfiles\n") if @otherfiles;
1575 push(@m, " $attribs{POSTOP}\n") if $attribs{POSTOP};
1581 my($self, %attribs) = @_;
1582 # VERSION should be sanitised before use as a file name
1583 my($tarname) = $attribs{TARNAME} || '$(DISTNAME)-$(VERSION)';
1584 my($tarflags) = $attribs{TARFLAGS} || 'cvf';
1585 my($compress) = $attribs{COMPRESS} || 'compress'; # eg gzip
1586 my($preop) = $attribs{PREOP} || '@:'; # e.g., update MANIFEST
1587 my($postop) = $attribs{POSTOP} || '@:';
1588 my($mkfiles) = join(' ', map("$_/$att{MAKEFILE}", ".", @{$att{DIR}}));
1593 cd ..; tar $tarflags $tarname.tar \$(BASEEXT)
1594 cd ..; $compress $tarname.tar
1600 # --- Test and Installation Sections ---
1603 my($self, %attribs) = @_;
1604 my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
1609 push(@m, <<"END") if $tests;
1610 \$(FULLPERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) -e 'use Test::Harness; runtests \@ARGV;' $tests
1612 push(@m, <<'END') if -f "test.pl";
1613 $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) $(I_PERL_LIBS) test.pl
1615 push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) test LINKTYPE=\$(LINKTYPE)\n",@{$att{DIR}}));
1616 push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n") unless @m > 1;
1622 my($self, %attribs) = @_;
1627 # install subdirectories first
1628 push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) install\n",@{$att{DIR}}));
1630 push(@m, "\t: perl5.000 and MM pre 3.8 autosplit into INST_ARCHLIB, we delete these old files here
1631 $att{RM_F} \$(INST_ARCHLIB)/auto/\$(FULLEXT)/*.al \$(INST_ARCHLIB)/auto/\$(FULLEXT)/*.ix
1632 \$(MAKE) INST_LIB=\$(INST_PRIVLIB) INST_ARCHLIB=\$(INST_ARCHLIB)
1639 '# Phony target to force checking subdirectories.
1648 PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \
1649 $(PERL_INC)/XSUB.h $(PERL_INC)/av.h $(PERL_INC)/cop.h \
1650 $(PERL_INC)/cv.h $(PERL_INC)/dosish.h $(PERL_INC)/embed.h \
1651 $(PERL_INC)/form.h $(PERL_INC)/gv.h $(PERL_INC)/handy.h \
1652 $(PERL_INC)/hv.h $(PERL_INC)/keywords.h $(PERL_INC)/mg.h \
1653 $(PERL_INC)/op.h $(PERL_INC)/opcode.h $(PERL_INC)/patchlevel.h \
1654 $(PERL_INC)/perl.h $(PERL_INC)/perly.h $(PERL_INC)/pp.h \
1655 $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h $(PERL_INC)/regexp.h \
1656 $(PERL_INC)/scope.h $(PERL_INC)/sv.h $(PERL_INC)/unixish.h \
1657 $(PERL_INC)/util.h $(PERL_INC)/config.h
1659 $(OBJECT) : $(PERL_HDRS)
1663 # Check for unpropogated config.sh changes. Should never happen.
1664 # We do NOT just update config.h because that is not sufficient.
1665 # An out of date config.h is not fatal but complains loudly!
1666 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
1667 -@echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
1669 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
1670 @echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
1671 cd $(PERL_SRC); $(MAKE) lib/Config.pm
1672 ') if $att{PERL_SRC};
1674 push(@m, join(" ", values %{$att{XS}})." : \$(XSUBPPDEPS)\n")
1681 # We do not know what target was originally specified so we
1682 # must force a manual rerun to be sure. But as it should only
1683 # happen very rarely it is not a significant problem.
1685 $(OBJECT) : '.$att{MAKEFILE}.'
1687 # We take a very conservative approach here, but it\'s worth it.
1688 # We move Makefile to Makefile.old here to avoid gnu make looping.
1689 '.$att{MAKEFILE}.': Makefile.PL $(CONFIGDEP)
1690 @echo "Makefile out-of-date with respect to $?"
1691 @echo "Cleaning current config before rebuilding Makefile..."
1692 -@mv '."$att{MAKEFILE} $att{MAKEFILE}.old".'
1693 -$(MAKE) -f '.$att{MAKEFILE}.'.old clean >/dev/null 2>&1 || true
1694 $(PERL) $(I_PERL_LIBS) Makefile.PL
1695 @echo "Now you must rerun make."; false
1705 # --- Determine libraries to use and how to use them ---
1708 my($self, $libs) = @_;
1709 return ("", "", "") unless $libs;
1710 print STDERR "Potential libraries are '$libs':" if $Verbose;
1711 my(@new) = MY->new_extliblist($libs);
1713 if ($att{PERL_SRC}){
1714 my(@old) = MY->old_extliblist($libs);
1715 my($oldlibs) = join(" : ",@old);
1716 my($newlibs) = join(" : ",@new);
1717 warn "Warning (non-fatal): $att{NAME} extliblist consistency check failed:\n".
1720 "Using 'new' set. Please notify perl5-porters\@nicoh.com.\n"
1721 if ("$newlibs" ne "$oldlibs");
1727 sub old_extliblist {
1728 my($self, $potential_libs)=@_;
1729 return ("", "", "") unless $potential_libs;
1730 die "old_extliblist requires PERL_SRC" unless $att{PERL_SRC};
1733 # Now run ext/util/extliblist to discover what *libs definitions
1734 # are required for the needs of $potential_libs
1735 $ENV{'potential_libs'} = $potential_libs;
1736 my(@o)=`. $att{PERL_SRC}/config.sh
1737 . $att{PERL_SRC}/ext/util/extliblist;
1738 echo EXTRALIBS=\$extralibs
1739 echo BSLOADLIBS=\$dynaloadlibs
1740 echo LDLOADLIBS=\$statloadlibs
1744 if ($line =~ /(.*)\s*=\s*(.*)\s*$/){
1746 print STDERR " $1 = $2" if $Verbose;
1751 print STDERR "Messages from extliblist:\n", join("\n",@w,'')
1753 @attrib{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)};
1757 sub new_extliblist {
1758 my($self, $potential_libs)=@_;
1759 return ("", "", "") unless $potential_libs;
1761 my($so) = $Config{'so'};
1762 my($libs) = $Config{'libs'};
1764 # compute $extralibs, $bsloadlibs and $ldloadlibs from
1766 # this is a rewrite of Andy Dougherty's extliblist in perl
1767 # its home is in <distribution>/ext/util
1769 my(@searchpath); # from "-L/path" entries in $potential_libs
1770 my(@libpath) = split " ", $Config{'libpth'};
1775 my($pwd) = fastcwd(); # from Cwd.pm
1777 foreach $thislib (split ' ', $potential_libs){
1779 # Handle possible linker path arguments.
1780 if ($thislib =~ s/^(-[LR])//){ # save path flag type
1782 unless (-d $thislib){
1783 warn "$ptype$thislib ignored, directory does not exist\n"
1787 if ($thislib !~ m|^/|) {
1788 warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
1789 $thislib = "$pwd/$thislib";
1791 push(@searchpath, $thislib);
1792 push(@extralibs, "$ptype$thislib");
1793 push(@ldloadlibs, "$ptype$thislib");
1797 # Handle possible library arguments.
1798 unless ($thislib =~ s/^-l//){
1799 warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
1804 foreach $thispth (@searchpath, @libpath){
1806 if (@fullname=<${thispth}/lib${thislib}.${so}.[0-9]*>){
1807 $fullname=$fullname[-1]; #ATTN: 10 looses against 9!
1808 } elsif (-f ($fullname="$thispth/lib$thislib.$so")){
1809 } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")
1810 && ($thislib .= "_s") ){ # we must explicitly ask for _s version
1811 } elsif (-f ($fullname="$thispth/lib$thislib.a")){
1812 } elsif (-f ($fullname="$thispth/Slib$thislib.a")){
1814 warn "$thislib not found in $thispth\n" if $Verbose;
1817 warn "'-l$thislib' found at $fullname\n" if $Verbose;
1820 # Now update library lists
1822 # what do we know about this library...
1823 my $is_dyna = ($fullname !~ /\.a$/);
1824 my $in_perl = ($libs =~ /\B-l${thislib}\b/s);
1826 # Do not add it into the list if it is already linked in
1827 # with the main perl executable.
1828 # We have to special-case the NeXT, because all the math is also in libsys_s
1829 unless ( $in_perl || ($Config{'osname'} eq 'next' && $thislib eq 'm') ){
1830 push(@extralibs, "-l$thislib");
1834 # We might be able to load this archive file dynamically
1835 if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){
1836 # We push -l$thislib instead of $fullname because
1837 # it avoids hardwiring a fixed path into the .bs file.
1838 # mkbootstrap will automatically add dl_findfile() to
1839 # the .bs file if it sees a name in the -l format.
1840 # USE THIS LATER: push(@bsloadlibs, "-l$thislib"); # " $fullname";
1841 # USE THIS while checking results against old_extliblist
1842 push(@bsloadlibs, "$fullname");
1845 # For SunOS4, do not add in this shared library if
1846 # it is already linked in the main perl executable
1847 push(@ldloadlibs, "-l$thislib")
1848 unless ($in_perl and $Config{'osname'} eq 'sunos');
1850 push(@ldloadlibs, "-l$thislib");
1853 last; # found one here so don't bother looking further
1855 warn "Warning (non-fatal): No library found for -l$thislib\n" unless $found_lib>0;
1857 ("@extralibs", "@bsloadlibs", "@ldloadlibs");
1861 # --- Write a DynaLoader bootstrap file if required
1871 Make a bootstrap file for use by this system's DynaLoader.
1872 It typically gets called from an extension Makefile.
1874 There is no .bs file supplied with the extension. Instead a _BS file
1875 which has code for the special cases, like posix for berkeley db on the
1878 This file will get parsed, and produce a maybe empty
1879 @DynaLoader::dl_resolve_using array for the current architecture.
1880 That will be extended by $BSLOADLIBS, which was computed by Andy's
1881 extliblist script. If this array still is empty, we do nothing, else
1882 we write a .bs file with an @DynaLoader::dl_resolve_using array, but
1883 without any C<if>s, because there is no longer a need to deal with
1886 The _BS file can put some code into the generated .bs file by placing
1887 it in $bscode. This is a handy 'escape' mechanism that may prove
1888 useful in complex situations.
1890 If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
1891 mkbootstrap will automatically add a dl_findfile() call to the
1896 Andreas Koenig <k@otto.ww.TU-Berlin.DE>, Tim Bunce
1897 <Tim.Bunce@ig.co.uk>, Andy Dougherty <doughera@lafcol.lafayette.edu>.
1898 VMS support by Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU>.
1902 my($self, @bsloadlibs)=@_;
1904 @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
1906 print STDERR " bsloadlibs=@bsloadlibs\n" if $Verbose;
1908 # We need DynaLoader here because we and/or the *_BS file may
1909 # call dl_findfile(). We don't say `use' here because when
1910 # first building perl extensions the DynaLoader will not have
1911 # been built when MakeMaker gets first used.
1915 init_main() unless defined $att{'BASEEXT'};
1917 rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
1919 if (-f "$att{BASEEXT}_BS"){
1920 $_ = "$att{BASEEXT}_BS";
1921 package DynaLoader; # execute code as if in DynaLoader
1922 local($osname, $dlsrc) = (); # avoid warnings
1923 ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
1930 if ($Config{'dlsrc'} =~ /^dl_dld/){
1932 push(@dl_resolve_using, dl_findfile('-lc'));
1935 my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
1938 open BS, ">$att{BASEEXT}.bs"
1939 or die "Unable to open $att{BASEEXT}.bs: $!";
1940 print STDOUT "Writing $att{BASEEXT}.bs\n";
1941 print STDOUT " containing: @all" if $Verbose;
1942 print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
1943 print BS "# Do not edit this file, changes will be lost.\n";
1944 print BS "# This file was automatically generated by the\n";
1945 print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
1946 print BS "\@DynaLoader::dl_resolve_using = ";
1947 # If @all contains names in the form -lxxx or -Lxxx then it's asking for
1948 # runtime library location so we automatically add a call to dl_findfile()
1949 if (" @all" =~ m/ -[lLR]/){
1950 print BS " dl_findfile(qw(\n @all\n ));\n";
1952 print BS " qw(@all);\n";
1954 # write extra code if *_BS says so
1955 print BS $DynaLoader::bscode if $DynaLoader::bscode;
1960 # special handling for systems which needs a list of all global
1961 # symbols exported by a modules to be dynamically linked.
1962 if ($Config{'dlsrc'} =~ /^dl_aix/){
1964 ($bootfunc = $att{NAME}) =~ s/\W/_/g;
1965 open EXP, ">$att{BASEEXT}.exp";
1966 print EXP "#!\nboot_$bootfunc\n";
1974 # only AIX requires a symbol list at this point
1975 # (so does VMS, but that's handled by the MM_VMS package)
1976 return '' unless $Config{'osname'} eq 'AIX';
1978 init_main(@ARGV) unless defined $att{'BASEEXT'};
1979 if (!$att{DL_FUNCS}) {
1980 (my($bootfunc) = $att{NAME}) =~ s/\W/_/g;
1981 $att{DL_FUNCS} = {$att{BASEEXT} => ["boot_$bootfunc"]};
1983 rename "$att{BASEEXT}.exp", "$att{BASEEXT}.exp_old";
1985 open(EXP,">$att{BASEEXT}.exp") or die $!;
1986 print EXP join("\n",@{$att{DL_VARS}}) if @{$att{DL_VARS}};
1987 foreach $pkg (keys %{$att{DL_FUNC}}) {
1988 (my($prefix) = $pkg) =~ s/\W/_/g;
1989 foreach $func (@{$att{DL_FUNC}->{$pkg}}) {
1990 $func = "XS_${prefix}_$func" unless $func =~ /^boot_/;
1991 print EXP "$func\n";
1997 # --- Output postprocessing section ---
1998 #nicetext is included to make VMS support easier
1999 sub nicetext { # Just return the input - no action needed
2000 my($self,$text) = @_;
2004 # the following keeps AutoSplit happy
2005 package ExtUtils::MakeMaker;