1 package ExtUtils::MakeMaker;
3 # Authors: Andy Dougherty <doughera@lafcol.lafayette.edu>
4 # Andreas Koenig <k@franz.ww.TU-Berlin.DE>
5 # Tim Bunce <Tim.Bunce@ig.co.uk>
7 # Last Revision: 12 Oct 1994
9 # This utility is designed to write a Makefile for an extension
10 # module from a Makefile.PL. It is based on the excellent Makefile.SH
11 # model provided by Andy Dougherty and the perl5-porters.
13 # It splits the task of generating the Makefile into several
14 # subroutines that can be individually overridden.
15 # Each subroutine returns the text it wishes to have written to
21 @EXPORT = qw(writeMakefile mkbootstrap $Verbose);
22 @EXPORT_OK = qw(%att @recognized_att_keys);
26 # Setup dummy package:
27 # MY exists for overriding methods to be defined within
28 unshift(@MY::ISA, qw(MM));
31 $Subdirs = 0; # set to 1 to have this .PL run all below
35 # For most extensions it will do to call
37 # use ExtUtils::MakeMaker
38 # &writeMakefile("potential_libs" => "-L/usr/alpha -lfoo -lbar");
40 # from Makefile.PL in the extension directory
41 # It is also handy to include some of the following attributes:
43 @recognized_att_keys=qw(
44 TOP INC DISTNAME VERSION DEFINE OBJECT LDTARGET ARMAYBE
45 BACKUP_LIBS AUTOSPLITMAXLEN LINKTYPE
46 potential_libs otherldflags perl fullperl
48 clean_files realclean_files
52 # TOP is the directory above lib/ and ext/ (normally ../..)
53 # (MakeMaker will normally work this out for itself)
54 # INC is something like "-I/usr/local/Minerva/include"
55 # DISTNAME is a name of your choice for distributing the package
56 # VERSION is your version number
57 # DEFINE is something like "-DHAVE_UNISTD_H"
58 # OBJECT defaults to '$(BASEEXT).o', but can be a long string containing
59 # all object files, e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
60 # LDTARGET defaults to $(OBJECT) and is used in the ld command
61 # (some machines need additional switches for bigger projects)
62 # ARMAYBE defaults to ":", but can be used to run ar before ld
63 # BACKUP_LIBS is an anonymous array of libraries to be searched for
64 # until we get at least some output from ext/util/extliblist
65 # 'potential_libs' => "-lgdbm",
66 # 'BACKUP_LIBS' => [ "-ldbm -lfoo", "-ldbm.nfs" ]
67 # AUTOSPLITMAXLEN defaults to 8 and is used when autosplit is done
68 # (can be set higher on a case-by-case basis)
69 # defaults to `dynamic', can be set to `static'
72 # `make distclean' builds $(DISTNAME)-$(VERSION).tar.Z after a clean
74 # Be aware, that you can also pass attributes into the %att hash table
75 # by calling Makefile.PL with an argument of the form TOP=/some/where.
77 # If the Makefile generated by default does not fit your purpose,
78 # you may specify private subroutines in the Makefile.PL as there are:
80 # MY->initialize => sub MY::initialize{ ... }
81 # MY->post_initialize => sub MY::post_initialize{ ... }
82 # MY->constants => etc
84 # etc. (see function writeMakefile, for the current breakpoints)
86 # Each subroutines returns the text it wishes to have written to
87 # the Makefile. To override a section of the Makefile you can
88 # either say: sub MY::co { "new literal text" }
89 # or you can edit the default by saying something like:
90 # sub MY::co { $_=MM->co; s/old text/new text/; $_ }
92 # If you still need a different solution, try to develop another
93 # subroutine, that fits your needs and submit the diffs to
94 # perl5-porters or comp.lang.perl as appropriate.
101 $att{$1}=$2 if m/(.*)=(.*)/;
103 print STDOUT "MakeMaker" if $Verbose;
104 print STDOUT map(" $_ = '$att{$_}'\n", sort keys %att) if ($Verbose && %att);
108 print STDOUT "Writing ext/$att{FULLEXT}/Makefile (with variable substitutions)";
110 open MAKE, ">Makefile" or die "Unable to open Makefile: $!";
112 MY->mkbootstrap(split(" ", $att{'dynaloadlibs'}));
113 print MAKE MY->post_initialize;
115 print MAKE MY->constants;
116 print MAKE MY->post_constants;
118 print MAKE MY->subdir if $Subdirs;
119 print MAKE MY->dynamic;
120 print MAKE MY->force;
121 print MAKE MY->static;
124 print MAKE MY->installpm;
125 print MAKE MY->clean;
126 print MAKE MY->realclean;
128 print MAKE MY->install;
129 print MAKE MY->perldepend;
130 print MAKE MY->distclean;
131 print MAKE MY->postamble;
146 sub avoid_typo_warnings{
151 $DynaLoader::dl_resolve_using
152 $ExtUtils::MakeMaker::Config
158 # --- Supply the MakeMaker default methods ---
165 Exporter::import('ExtUtils::MakeMaker', qw(%att @recognized_att_keys));
167 # These attributes cannot be overridden
168 @other_att_keys=qw(extralibs dynaloadlibs statloadlibs bootdep);
172 my($self, $ver, $names, $dirs, $trace) = @_;
174 print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n"
176 foreach $dir (@$dirs){
177 foreach $name (@$names){
178 print "checking $dir/$name\n" if ($trace >= 2);
179 next unless -x "$dir/$name";
180 print "executing $dir/$name\n" if ($trace);
181 my($out) = `$dir/$name -e 'require $ver; print "5OK\n" ' 2>&1`;
182 return "$dir/$name" if $out =~ /5OK/;
185 warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
186 0; # false and not empty
191 # Find out directory name. This is also the extension name.
194 unless ( $top = $att{TOP} ){
195 foreach(qw(../.. ../../.. ../../../..)){
196 ($top=$_, last) if -f "$_/config.sh";
198 die "Can't find config.sh" unless -f "$top/config.sh";
200 chdir $top or die "Couldn't chdir $top: $!";
204 # EXTMODNAME = The perl module name for this extension.
205 # FULLEXT = Full pathname to extension directory.
206 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
207 # ROOTEXT = Directory part of FULLEXT. May be empty.
208 my($p) = $pwd; $p =~ s:^\Q$abstop/ext/\E::;
209 ($att{EXTMODNAME}=$p) =~ s#/#::#g ; #eg. BSD::Foo::Socket
210 ($att{FULLEXT} =$p); #eg. BSD/Foo/Socket
211 ($att{BASEEXT} =$p) =~ s:.*/:: ; #eg. Socket
212 ($att{ROOTEXT} =$p) =~ s:/?\Q$att{BASEEXT}\E$:: ; #eg. BSD/Foo
214 # Find Perl 5. The only contract here is that both 'perl' and 'fullperl'
215 # will be working versions of perl 5.
216 $att{'perl'} = MY->find_perl(5.0, [ qw(perl5 perl miniperl) ],
217 [ $abstop, split(":", $ENV{PATH}) ], 0 )
218 unless ($att{'perl'} && -x $att{'perl'});
220 # Define 'fullperl' to be a non-miniperl (used in test: target)
221 ($att{'fullperl'} = $att{'perl'}) =~ s/miniperl$/perl/
222 unless ($att{'fullperl'} && -x $att{'fullperl'});
224 for $key (@recognized_att_keys, @other_att_keys){
225 # avoid warnings for uninitialized vars
226 $att{$key} = "" unless defined $att{$key};
229 # compute extralibs, dynaloadlibs and statloadlibs from
230 # $att{'potential_libs'}
232 unless ( &run_extliblist($att{'potential_libs'}) ){
233 foreach ( @{$att{'BACKUP_LIBS'} || []} ){
234 # Try again. Maybe they have specified some other libraries
235 last if &run_extliblist($_);
242 my($potential_libs)=@_;
243 # Now run ext/util/extliblist to discover what *libs definitions
244 # are required for the needs of $potential_libs
245 $ENV{'potential_libs'} = $potential_libs;
246 $_=`. $abstop/ext/util/extliblist;
247 echo extralibs=\$extralibs
248 echo dynaloadlibs=\$dynaloadlibs
249 echo statloadlibs=\$statloadlibs
250 echo bootdep=\$bootdep
253 foreach $line (split "\n", $_){
255 if ($line =~ /(.*)\s*=\s*(.*)$/){
257 print STDERR " $1 = $2" if $Verbose;
262 print STDERR "Messages from extliblist:\n", join("\n",@w,'')
264 join '', @att{qw(extralibs dynaloadlibs statloadlibs)};
276 $att{BOOTDEP} = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
277 $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT};
278 $att{LDTARGET} = '$(OBJECT)' unless $att{LDTARGET};
279 $att{ARMAYBE} = ":" unless $att{ARMAYBE};
280 $att{AUTOSPLITMAXLEN} = 8 unless $att{AUTOSPLITMAXLEN};
281 $att{LINKTYPE} = ($Config{'usedl'}) ? 'dynamic' : 'static'
282 unless $att{LINKTYPE};
287 # This Makefile is for the $att{FULLEXT} extension to perl.
288 # It was written by Makefile.PL, so don't edit it, edit
289 # Makefile.PL instead. ANY CHANGES MADE HERE WILL BE LOST!
292 DISTNAME = $att{DISTNAME}
293 VERSION = $att{VERSION}
298 FULLPERL = $att{'fullperl'}
300 DEFINE = $att{DEFINE}
301 OBJECT = $att{OBJECT}
302 LDTARGET = $att{LDTARGET}
307 LIBC = $Config{'libc'}
308 LDFLAGS = $Config{'ldflags'}
309 CLDFLAGS = $Config{'ldflags'}
310 LINKTYPE = $att{LINKTYPE}
311 ARMAYBE = $att{ARMAYBE}
312 RANLIB = $Config{'ranlib'}
314 SMALL = $Config{'small'}
315 LARGE = $Config{'large'} $Config{'split'}
316 # The following are used to build and install shared libraries for
318 LDDLFLAGS = $Config{'lddlflags'}
319 CCDLFLAGS = $Config{'ccdlflags'}
320 CCCDLFLAGS = $Config{'cccdlflags'}
322 DLEXT = $Config{'dlext'}
323 DLSRC = $Config{'dlsrc'}
327 # $att{FULLEXT} might need to be linked with some extra libraries.
328 # EXTRALIBS = full list of libraries needed for static linking.
329 # Only those libraries that actually exist are included.
330 # DYNALOADLIBS = list of those libraries that are needed but can be
331 # linked in dynamically on this platform. On SunOS, for
332 # example, this would be .so* libraries, but not archive
333 # libraries. The bootstrap file is installed only if
334 # this list is not empty.
335 # STATLOADLIBS = list of those libraries which must be statically
336 # linked into the shared library. On SunOS 4.1.3,
337 # for example, I have only an archive version of
338 # -lm, and it must be linked in statically.
339 EXTRALIBS = $att{'extralibs'}
340 DYNALOADLIBS = $att{'dynaloadlibs'}
341 STATLOADLIBS = $att{'statloadlibs'}
346 # EXTMODNAME = The perl module name for this extension.
347 # FULLEXT = Full pathname to extension directory.
348 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
349 # ROOTEXT = Directory part of FULLEXT. May be empty.
350 EXTMODNAME = $att{EXTMODNAME}
351 FULLEXT = $att{FULLEXT}
352 BASEEXT = $att{BASEEXT}
353 ROOTEXT = $att{ROOTEXT}
354 # and for backward compatibility and for AIX support (due to change!)
357 # $att{FULLEXT} might have its own typemap
358 EXTTYPEMAP = ".(-f "typemap" ? "typemap" : "")."
359 # $att{FULLEXT} might have its own bootstrap support
360 BOOTSTRAP = $att{BASEEXT}.bs
361 BOOTDEP = $att{BOOTDEP}
365 # Where to put things:
366 AUTO = $(TOP)/lib/auto
367 AUTOEXT = $(TOP)/lib/auto/$(FULLEXT)
368 INST_BOOT = $(AUTOEXT)/$(BASEEXT).bs
369 INST_DYNAMIC = $(AUTOEXT)/$(BASEEXT).$(DLEXT)
370 INST_STATIC = $(BASEEXT).a
371 INST_PM = $(TOP)/lib/$(FULLEXT).pm
373 # These two are only used by install: targets
374 INSTALLPRIVLIB = $Config{'installprivlib'}
375 INSTALLARCHLIB = $Config{'installarchlib'}
378 push @m, "\nshellflags = $Config{'shellflags'}" if $Config{'shellflags'};
383 CCCMD = `sh $(shellflags) $(ABSTOP)/cflags $@`
384 XSUBPP = $(TOP)/ext/xsubpp
385 # the following is a portable way to say mkdir -p
386 MKPATH = $(PERL) -we '$$"="/"; foreach(split(/\//,$$ARGV[0])){ push(@p, $$_); next if -d "@p"; print "mkdir @p\n"; mkdir("@p",0777)||die "mkdir @p: $$!" } exit 0;'
387 AUTOSPLITLIB = cd $(TOP); \
388 $(PERL) -Ilib -e 'use AutoSplit; $$AutoSplit::Maxlen=}.$att{AUTOSPLITMAXLEN}.q{; autosplit_lib_modules(@ARGV) ;'
396 @$(MKPATH) $(AUTOEXT)
413 foreach $MakefilePL (<*/Makefile.PL>){
414 ($subdir=$MakefilePL) =~ s:/Makefile\.PL$:: ;
418 if test ! -f Makefile; then \\
419 test -f Makefile.PL && \$(PERL) -I\$(ABSTOP)/lib Makefile.PL TOP=\$(ABSTOP) ; \\
423 cd $subdir ; \$(MAKE) config
424 cd $subdir ; \$(MAKE) all
435 $(CCCMD) $(CCCDLFLAGS) $(DEFINE) -I$(TOP) $(INC) $*.c
442 # Phony target to force checking subdirectories.
452 # Target for Dynamic Loading:
453 dynamic:: $(INST_DYNAMIC) $(INST_PM) $(INST_BOOT)
455 $(INST_DYNAMIC): $(OBJECT)
456 @$(MKPATH) $(AUTOEXT)
457 $(ARMAYBE) cr $(EXTMODNAME).a $(OBJECT)
458 ld $(LDDLFLAGS) -o $@ $(LDTARGET) '.$att{'otherldflags'}.' $(STATLOADLIBS)
460 $(BOOTSTRAP): $(BOOTDEP)
461 $(PERL) -I$(TOP)/lib -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(DYNALOADLIBS)");\'
464 $(INST_BOOT): $(BOOTSTRAP)
465 @test ! -s $(BOOTSTRAP) || cp $(BOOTSTRAP) $@
472 # Target for Static Loading:
473 static:: $(INST_STATIC) $(INST_PM)
475 $(INST_STATIC): $(OBJECT)
478 echo $(EXTRALIBS) >> $(TOP)/ext.libs
485 $(BASEEXT).c: $(BASEEXT).xs $(XSUBPP) $(TOP)/ext/typemap $(EXTTYPEMAP) $(TOP)/cflags
486 $(PERL) $(XSUBPP) $(BASEEXT).xs >tmp
494 $(INST_PM): $(BASEEXT).pm
495 @$(MKPATH) $(TOP)/lib/$(ROOTEXT)
498 @$(AUTOSPLITLIB) $(EXTMODNAME)
506 rm -f *.o *.a mon.out core $(BASEEXT).c so_locations
507 rm -f makefile Makefile $(BOOTSTRAP) $(BASEEXT).bso '.$att{'clean_files'}.'
515 rm -f $(INST_DYNAMIC) $(INST_STATIC) $(INST_BOOT)
516 rm -rf $(INST_PM) $(AUTOEXT) '.$att{'realclean_files'}.'
526 $(FULLPERL) -I$(TOP)/lib -e \'use Test::Harness; runtests @ARGV;\' t/*.t
533 # used if installperl will not be installing it for you
541 my($tarflags) = $att{'distclean_tarflags'} || 'cvf';
544 rm -f Makefile *~ t/*~
545 cd ..; tar '.$tarflags.' "$(DISTNAME)-$(VERSION).tar" $(BASEEXT)
546 cd ..; compress "$(DISTNAME)-$(VERSION).tar"
554 $(OBJECT) : $(TOP)/EXTERN.h
555 $(OBJECT) : $(TOP)/INTERN.h
556 $(OBJECT) : $(TOP)/XSUB.h
557 $(OBJECT) : $(TOP)/av.h
558 $(OBJECT) : $(TOP)/cop.h
559 $(OBJECT) : $(TOP)/cv.h
560 $(OBJECT) : $(TOP)/dosish.h
561 $(OBJECT) : $(TOP)/embed.h
562 $(OBJECT) : $(TOP)/form.h
563 $(OBJECT) : $(TOP)/gv.h
564 $(OBJECT) : $(TOP)/handy.h
565 $(OBJECT) : $(TOP)/hv.h
566 $(OBJECT) : $(TOP)/keywords.h
567 $(OBJECT) : $(TOP)/mg.h
568 $(OBJECT) : $(TOP)/op.h
569 $(OBJECT) : $(TOP)/opcode.h
570 $(OBJECT) : $(TOP)/patchlevel.h
571 $(OBJECT) : $(TOP)/perl.h
572 $(OBJECT) : $(TOP)/perly.h
573 $(OBJECT) : $(TOP)/pp.h
574 $(OBJECT) : $(TOP)/proto.h
575 $(OBJECT) : $(TOP)/regcomp.h
576 $(OBJECT) : $(TOP)/regexp.h
577 $(OBJECT) : $(TOP)/scope.h
578 $(OBJECT) : $(TOP)/sv.h
579 $(OBJECT) : $(TOP)/unixish.h
580 $(OBJECT) : $(TOP)/util.h
581 $(TOP)/config.h: $(TOP)/config.sh; cd $(TOP); /bin/sh config_h.SH
582 $(TOP)/embed.h: $(TOP)/config.sh; cd $(TOP); /bin/sh embed_h.SH
583 $(TOP)/cflags: $(TOP)/config.sh; cd $(TOP); /bin/sh cflags.SH
585 Makefile: Makefile.PL
586 $(PERL) -I$(TOP)/lib Makefile.PL
597 chmod 0644, "Makefile";
598 system("$Config{'eunicefix'} Makefile") unless $Config{'eunicefix'} eq ":";
607 # Andreas Koenig <k@otto.ww.TU-Berlin.DE>
608 # Tim Bunce <Tim.Bunce@ig.co.uk>
609 # Andy Dougherty <doughera@lafcol.lafayette.edu>
611 # This perl script attempts to make a bootstrap file for use by this
612 # system's DynaLoader. It typically gets called from an extension
615 # There is no .bs file supplied with the extension. Instead a _BS
616 # file which has code for the special cases, like posix for berkeley db
619 # This file will get parsed, and produce a maybe empty
620 # @DynaLoader::dl_resolve_using array for the current architecture.
621 # That will be extended by $dynaloadlibs, which was computed by Andy's
622 # extliblist script. If this array still is empty, we do nothing, else
623 # we write a .bs file with an @DynaLoader::dl_resolve_using array, but
624 # without any `if's, because there is no longer a need to deal with
627 # The _BS file can put some code into the generated .bs file by placing
628 # it in $bscode. This is a handy 'escape' mechanism that may prove
629 # useful in complex situations.
631 # If @DynaLoader::dl_resolve_using contains -L* or -l* entries then
632 # mkbootstrap will automatically add a dl_findfile() call to the
633 # generated .bs file.
635 my($self, @dynaloadlibs)=@_;
636 print STDERR " dynaloadlibs=@dynaloadlibs" if $Verbose;
637 require DynaLoader; # we need DynaLoader, if the *_BS gets interpreted
638 import DynaLoader; # we don't say `use', so if DynaLoader is not
639 # yet built MakeMaker works nonetheless except here
641 &initialize unless defined $att{'perl'};
643 rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
645 if (-f "$att{BASEEXT}_BS"){
646 $_ = "$att{BASEEXT}_BS";
647 package DynaLoader; # execute code as if in DynaLoader
648 local($osname, $dlsrc) = (); # avoid warnings
649 ($osname, $dlsrc) = @Config{qw(osname dlsrc)};
655 if ($Config{'dlsrc'} =~ /^dl_dld/){
657 push(@dl_resolve_using, dl_findfile('-lc'));
660 my(@all) = (@dynaloadlibs, @DynaLoader::dl_resolve_using);
663 open BS, ">$att{BASEEXT}.bs"
664 or die "Unable to open $att{BASEEXT}.bs: $!";
665 print STDOUT "Writing $att{BASEEXT}.bs\n";
666 print STDOUT " containing: @all" if $Verbose;
667 print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
668 print BS "# Do not edit this file, changes will be lost.\n";
669 print BS "# This file was automatically generated by the\n";
670 print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
671 print BS "\@DynaLoader::dl_resolve_using = ";
672 if (" @all" =~ m/ -[lL]/){
673 print BS " dl_findfile(qw(\n @all\n ));\n";
675 print BS " qw(@all);\n";
677 # write extra code if *_BS says so
678 print BS $DynaLoader::bscode if $DynaLoader::bscode;
683 if ($Config{'dlsrc'} =~ /^dl_aix/){
684 open AIX, ">$att{BASEEXT}.exp";
685 print AIX "#!\nboot_$att{BASEEXT}\n";
690 # the following makes AutoSplit happy (bug in perl5b3e)
691 package ExtUtils::MakeMaker;