| 1 | # $Id$ | ||
| 2 | package ExtUtils::MakeMaker; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | |||
| 6 | BEGIN {require 5.006;} | ||
| 7 | |||
| 8 | require Exporter; | ||
| 9 | use ExtUtils::MakeMaker::Config; | ||
| 10 | use ExtUtils::MakeMaker::version; # ensure we always have our fake version.pm | ||
| 11 | use Carp; | ||
| 12 | use File::Path; | ||
| 13 | my $CAN_DECODE = eval { require ExtUtils::MakeMaker::Locale; }; # 2 birds, 1 stone | ||
| 14 | eval { ExtUtils::MakeMaker::Locale::reinit('UTF-8') } | ||
| 15 | if $CAN_DECODE and $ExtUtils::MakeMaker::Locale::ENCODING_LOCALE eq 'US-ASCII'; | ||
| 16 | |||
| 17 | our $Verbose = 0; # exported | ||
| 18 | our @Parent; # needs to be localized | ||
| 19 | our @Get_from_Config; # referenced by MM_Unix | ||
| 20 | our @MM_Sections; | ||
| 21 | our @Overridable; | ||
| 22 | my @Prepend_parent; | ||
| 23 | my %Recognized_Att_Keys; | ||
| 24 | our %macro_fsentity; # whether a macro is a filesystem name | ||
| 25 | our %macro_dep; # whether a macro is a dependency | ||
| 26 | |||
| 27 | our $VERSION = '7.13_01'; | ||
| 28 | $VERSION = eval $VERSION; ## no critic [BuiltinFunctions::ProhibitStringyEval] | ||
| 29 | |||
| 30 | # Emulate something resembling CVS $Revision$ | ||
| 31 | (our $Revision = $VERSION) =~ s{_}{}; | ||
| 32 | $Revision = int $Revision * 10000; | ||
| 33 | |||
| 34 | our $Filename = __FILE__; # referenced outside MakeMaker | ||
| 35 | |||
| 36 | our @ISA = qw(Exporter); | ||
| 37 | our @EXPORT = qw(&WriteMakefile $Verbose &prompt); | ||
| 38 | our @EXPORT_OK = qw($VERSION &neatvalue &mkbootstrap &mksymlists | ||
| 39 | &WriteEmptyMakefile &open_for_writing &write_file_via_tmp | ||
| 40 | &_sprintf562); | ||
| 41 | |||
| 42 | # These will go away once the last of the Win32 & VMS specific code is | ||
| 43 | # purged. | ||
| 44 | my $Is_VMS = $^O eq 'VMS'; | ||
| 45 | my $Is_Win32 = $^O eq 'MSWin32'; | ||
| 46 | our $UNDER_CORE = $ENV{PERL_CORE}; # needs to be our | ||
| 47 | |||
| 48 | full_setup(); | ||
| 49 | |||
| 50 | require ExtUtils::MM; # Things like CPAN assume loading ExtUtils::MakeMaker | ||
| 51 | # will give them MM. | ||
| 52 | |||
| 53 | require ExtUtils::MY; # XXX pre-5.8 versions of ExtUtils::Embed expect | ||
| 54 | # loading ExtUtils::MakeMaker will give them MY. | ||
| 55 | # This will go when Embed is its own CPAN module. | ||
| 56 | |||
| 57 | |||
| 58 | # 5.6.2 can't do sprintf "%1$s" - this can only do %s | ||
| 59 | sub _sprintf562 { | ||
| 60 | my ($format, @args) = @_; | ||
| 61 | for (my $i = 1; $i <= @args; $i++) { | ||
| 62 | $format =~ s#%$i\$s#$args[$i-1]#g; | ||
| 63 | } | ||
| 64 | $format; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub WriteMakefile { | ||
| 68 | croak "WriteMakefile: Need even number of args" if @_ % 2; | ||
| 69 | |||
| 70 | require ExtUtils::MY; | ||
| 71 | my %att = @_; | ||
| 72 | |||
| 73 | _convert_compat_attrs(\%att); | ||
| 74 | |||
| 75 | _verify_att(\%att); | ||
| 76 | |||
| 77 | my $mm = MM->new(\%att); | ||
| 78 | $mm->flush; | ||
| 79 | |||
| 80 | return $mm; | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | # Basic signatures of the attributes WriteMakefile takes. Each is the | ||
| 85 | # reference type. Empty value indicate it takes a non-reference | ||
| 86 | # scalar. | ||
| 87 | my %Att_Sigs; | ||
| 88 | my %Special_Sigs = ( | ||
| 89 | AUTHOR => 'ARRAY', | ||
| 90 | C => 'ARRAY', | ||
| 91 | CONFIG => 'ARRAY', | ||
| 92 | CONFIGURE => 'CODE', | ||
| 93 | DIR => 'ARRAY', | ||
| 94 | DL_FUNCS => 'HASH', | ||
| 95 | DL_VARS => 'ARRAY', | ||
| 96 | EXCLUDE_EXT => 'ARRAY', | ||
| 97 | EXE_FILES => 'ARRAY', | ||
| 98 | FUNCLIST => 'ARRAY', | ||
| 99 | H => 'ARRAY', | ||
| 100 | IMPORTS => 'HASH', | ||
| 101 | INCLUDE_EXT => 'ARRAY', | ||
| 102 | LIBS => ['ARRAY',''], | ||
| 103 | MAN1PODS => 'HASH', | ||
| 104 | MAN3PODS => 'HASH', | ||
| 105 | META_ADD => 'HASH', | ||
| 106 | META_MERGE => 'HASH', | ||
| 107 | OBJECT => ['ARRAY', ''], | ||
| 108 | PL_FILES => 'HASH', | ||
| 109 | PM => 'HASH', | ||
| 110 | PMLIBDIRS => 'ARRAY', | ||
| 111 | PMLIBPARENTDIRS => 'ARRAY', | ||
| 112 | PREREQ_PM => 'HASH', | ||
| 113 | BUILD_REQUIRES => 'HASH', | ||
| 114 | CONFIGURE_REQUIRES => 'HASH', | ||
| 115 | TEST_REQUIRES => 'HASH', | ||
| 116 | SKIP => 'ARRAY', | ||
| 117 | TYPEMAPS => 'ARRAY', | ||
| 118 | XS => 'HASH', | ||
| 119 | XSBUILD => 'HASH', | ||
| 120 | VERSION => ['version',''], | ||
| 121 | _KEEP_AFTER_FLUSH => '', | ||
| 122 | |||
| 123 | clean => 'HASH', | ||
| 124 | depend => 'HASH', | ||
| 125 | dist => 'HASH', | ||
| 126 | dynamic_lib=> 'HASH', | ||
| 127 | linkext => 'HASH', | ||
| 128 | macro => 'HASH', | ||
| 129 | postamble => 'HASH', | ||
| 130 | realclean => 'HASH', | ||
| 131 | test => 'HASH', | ||
| 132 | tool_autosplit => 'HASH', | ||
| 133 | ); | ||
| 134 | |||
| 135 | @Att_Sigs{keys %Recognized_Att_Keys} = ('') x keys %Recognized_Att_Keys; | ||
| 136 | @Att_Sigs{keys %Special_Sigs} = values %Special_Sigs; | ||
| 137 | |||
| 138 | sub _convert_compat_attrs { #result of running several times should be same | ||
| 139 | my($att) = @_; | ||
| 140 | if (exists $att->{AUTHOR}) { | ||
| 141 | if ($att->{AUTHOR}) { | ||
| 142 | if (!ref($att->{AUTHOR})) { | ||
| 143 | my $t = $att->{AUTHOR}; | ||
| 144 | $att->{AUTHOR} = [$t]; | ||
| 145 | } | ||
| 146 | } else { | ||
| 147 | $att->{AUTHOR} = []; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | sub _verify_att { | ||
| 153 | my($att) = @_; | ||
| 154 | |||
| 155 | foreach my $key (sort keys %$att) { | ||
| 156 | my $val = $att->{$key}; | ||
| 157 | my $sig = $Att_Sigs{$key}; | ||
| 158 | unless( defined $sig ) { | ||
| 159 | warn "WARNING: $key is not a known parameter.\n"; | ||
| 160 | next; | ||
| 161 | } | ||
| 162 | |||
| 163 | my @sigs = ref $sig ? @$sig : $sig; | ||
| 164 | my $given = ref $val; | ||
| 165 | unless( grep { _is_of_type($val, $_) } @sigs ) { | ||
| 166 | my $takes = join " or ", map { _format_att($_) } @sigs; | ||
| 167 | |||
| 168 | my $has = _format_att($given); | ||
| 169 | warn "WARNING: $key takes a $takes not a $has.\n". | ||
| 170 | " Please inform the author.\n"; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | # Check if a given thing is a reference or instance of $type | ||
| 177 | sub _is_of_type { | ||
| 178 | my($thing, $type) = @_; | ||
| 179 | |||
| 180 | return 1 if ref $thing eq $type; | ||
| 181 | |||
| 182 | local $SIG{__DIE__}; | ||
| 183 | return 1 if eval{ $thing->isa($type) }; | ||
| 184 | |||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | sub _format_att { | ||
| 190 | my $given = shift; | ||
| 191 | |||
| 192 | return $given eq '' ? "string/number" | ||
| 193 | : uc $given eq $given ? "$given reference" | ||
| 194 | : "$given object" | ||
| 195 | ; | ||
| 196 | } | ||
| 197 | |||
| 198 | |||
| 199 | sub prompt ($;$) { ## no critic | ||
| 200 | my($mess, $def) = @_; | ||
| 201 | confess("prompt function called without an argument") | ||
| 202 | unless defined $mess; | ||
| 203 | |||
| 204 | my $isa_tty = -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; | ||
| 205 | |||
| 206 | my $dispdef = defined $def ? "[$def] " : " "; | ||
| 207 | $def = defined $def ? $def : ""; | ||
| 208 | |||
| 209 | local $|=1; | ||
| 210 | local $\; | ||
| 211 | print "$mess $dispdef"; | ||
| 212 | |||
| 213 | my $ans; | ||
| 214 | if ($ENV{PERL_MM_USE_DEFAULT} || (!$isa_tty && eof STDIN)) { | ||
| 215 | print "$def\n"; | ||
| 216 | } | ||
| 217 | else { | ||
| 218 | $ans = <STDIN>; | ||
| 219 | if( defined $ans ) { | ||
| 220 | $ans =~ s{\015?\012$}{}; | ||
| 221 | } | ||
| 222 | else { # user hit ctrl-D | ||
| 223 | print "\n"; | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | return (!defined $ans || $ans eq '') ? $def : $ans; | ||
| 228 | } | ||
| 229 | |||
| 230 | sub eval_in_subdirs { | ||
| 231 | my($self) = @_; | ||
| 232 | use Cwd qw(cwd abs_path); | ||
| 233 | my $pwd = cwd() || die "Can't figure out your cwd!"; | ||
| 234 | |||
| 235 | local @INC = map eval {abs_path($_) if -e} || $_, @INC; | ||
| 236 | push @INC, '.'; # '.' has to always be at the end of @INC | ||
| 237 | |||
| 238 | foreach my $dir (@{$self->{DIR}}){ | ||
| 239 | my($abs) = $self->catdir($pwd,$dir); | ||
| 240 | eval { $self->eval_in_x($abs); }; | ||
| 241 | last if $@; | ||
| 242 | } | ||
| 243 | chdir $pwd; | ||
| 244 | die $@ if $@; | ||
| 245 | } | ||
| 246 | |||
| 247 | sub eval_in_x { | ||
| 248 | my($self,$dir) = @_; | ||
| 249 | chdir $dir or carp("Couldn't change to directory $dir: $!"); | ||
| 250 | |||
| 251 | { | ||
| 252 | package main; | ||
| 253 | do './Makefile.PL'; | ||
| 254 | }; | ||
| 255 | if ($@) { | ||
| 256 | # if ($@ =~ /prerequisites/) { | ||
| 257 | # die "MakeMaker WARNING: $@"; | ||
| 258 | # } else { | ||
| 259 | # warn "WARNING from evaluation of $dir/Makefile.PL: $@"; | ||
| 260 | # } | ||
| 261 | die "ERROR from evaluation of $dir/Makefile.PL: $@"; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | # package name for the classes into which the first object will be blessed | ||
| 267 | my $PACKNAME = 'PACK000'; | ||
| 268 | |||
| 269 | sub full_setup { | ||
| 270 | $Verbose ||= 0; | ||
| 271 | |||
| 272 | my @dep_macros = qw/ | ||
| 273 | PERL_INCDEP PERL_ARCHLIBDEP PERL_ARCHIVEDEP | ||
| 274 | /; | ||
| 275 | |||
| 276 | my @fs_macros = qw/ | ||
| 277 | FULLPERL XSUBPPDIR | ||
| 278 | |||
| 279 | INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB INST_MAN1DIR INST_MAN3DIR | ||
| 280 | INSTALLDIRS | ||
| 281 | DESTDIR PREFIX INSTALL_BASE | ||
| 282 | PERLPREFIX SITEPREFIX VENDORPREFIX | ||
| 283 | INSTALLPRIVLIB INSTALLSITELIB INSTALLVENDORLIB | ||
| 284 | INSTALLARCHLIB INSTALLSITEARCH INSTALLVENDORARCH | ||
| 285 | INSTALLBIN INSTALLSITEBIN INSTALLVENDORBIN | ||
| 286 | INSTALLMAN1DIR INSTALLMAN3DIR | ||
| 287 | INSTALLSITEMAN1DIR INSTALLSITEMAN3DIR | ||
| 288 | INSTALLVENDORMAN1DIR INSTALLVENDORMAN3DIR | ||
| 289 | INSTALLSCRIPT INSTALLSITESCRIPT INSTALLVENDORSCRIPT | ||
| 290 | PERL_LIB PERL_ARCHLIB | ||
| 291 | SITELIBEXP SITEARCHEXP | ||
| 292 | |||
| 293 | MAKE LIBPERL_A LIB PERL_SRC PERL_INC | ||
| 294 | PPM_INSTALL_EXEC PPM_UNINSTALL_EXEC | ||
| 295 | PPM_INSTALL_SCRIPT PPM_UNINSTALL_SCRIPT | ||
| 296 | /; | ||
| 297 | |||
| 298 | my @attrib_help = qw/ | ||
| 299 | |||
| 300 | AUTHOR ABSTRACT ABSTRACT_FROM BINARY_LOCATION | ||
| 301 | C CAPI CCFLAGS CONFIG CONFIGURE DEFINE DIR DISTNAME DISTVNAME | ||
| 302 | DL_FUNCS DL_VARS | ||
| 303 | EXCLUDE_EXT EXE_FILES FIRST_MAKEFILE | ||
| 304 | FULLPERLRUN FULLPERLRUNINST | ||
| 305 | FUNCLIST H IMPORTS | ||
| 306 | |||
| 307 | INC INCLUDE_EXT LDFROM LIBS LICENSE | ||
| 308 | LINKTYPE MAKEAPERL MAKEFILE MAKEFILE_OLD MAN1PODS MAN3PODS MAP_TARGET | ||
| 309 | META_ADD META_MERGE MIN_PERL_VERSION BUILD_REQUIRES CONFIGURE_REQUIRES | ||
| 310 | MYEXTLIB NAME NEEDS_LINKING NOECHO NO_META NO_MYMETA NO_PACKLIST NO_PERLLOCAL | ||
| 311 | NORECURS NO_VC OBJECT OPTIMIZE PERL_MALLOC_OK PERL PERLMAINCC PERLRUN | ||
| 312 | PERLRUNINST PERL_CORE | ||
| 313 | PERM_DIR PERM_RW PERM_RWX MAGICXS | ||
| 314 | PL_FILES PM PM_FILTER PMLIBDIRS PMLIBPARENTDIRS POLLUTE | ||
| 315 | PREREQ_FATAL PREREQ_PM PREREQ_PRINT PRINT_PREREQ | ||
| 316 | SIGN SKIP TEST_REQUIRES TYPEMAPS UNINST VERSION VERSION_FROM XS | ||
| 317 | XSBUILD XSMULTI XSOPT XSPROTOARG XS_VERSION | ||
| 318 | clean depend dist dynamic_lib linkext macro realclean tool_autosplit | ||
| 319 | |||
| 320 | MAN1EXT MAN3EXT | ||
| 321 | |||
| 322 | MACPERL_SRC MACPERL_LIB MACLIBS_68K MACLIBS_PPC MACLIBS_SC MACLIBS_MRC | ||
| 323 | MACLIBS_ALL_68K MACLIBS_ALL_PPC MACLIBS_SHARED | ||
| 324 | /; | ||
| 325 | push @attrib_help, @fs_macros; | ||
| 326 | @macro_fsentity{@fs_macros, @dep_macros} = (1) x (@fs_macros+@dep_macros); | ||
| 327 | @macro_dep{@dep_macros} = (1) x @dep_macros; | ||
| 328 | |||
| 329 | # IMPORTS is used under OS/2 and Win32 | ||
| 330 | |||
| 331 | # @Overridable is close to @MM_Sections but not identical. The | ||
| 332 | # order is important. Many subroutines declare macros. These | ||
| 333 | # depend on each other. Let's try to collect the macros up front, | ||
| 334 | # then pasthru, then the rules. | ||
| 335 | |||
| 336 | # MM_Sections are the sections we have to call explicitly | ||
| 337 | # in Overridable we have subroutines that are used indirectly | ||
| 338 | |||
| 339 | |||
| 340 | @MM_Sections = | ||
| 341 | qw( | ||
| 342 | |||
| 343 | post_initialize const_config constants platform_constants | ||
| 344 | tool_autosplit tool_xsubpp tools_other | ||
| 345 | |||
| 346 | makemakerdflt | ||
| 347 | |||
| 348 | dist macro depend cflags const_loadlibs const_cccmd | ||
| 349 | post_constants | ||
| 350 | |||
| 351 | pasthru | ||
| 352 | |||
| 353 | special_targets | ||
| 354 | c_o xs_c xs_o | ||
| 355 | top_targets blibdirs linkext dlsyms dynamic_bs dynamic | ||
| 356 | dynamic_lib static static_lib manifypods processPL | ||
| 357 | installbin subdirs | ||
| 358 | clean_subdirs clean realclean_subdirs realclean | ||
| 359 | metafile signature | ||
| 360 | dist_basics dist_core distdir dist_test dist_ci distmeta distsignature | ||
| 361 | install force perldepend makefile staticmake test ppd | ||
| 362 | |||
| 363 | ); # loses section ordering | ||
| 364 | |||
| 365 | @Overridable = @MM_Sections; | ||
| 366 | push @Overridable, qw[ | ||
| 367 | |||
| 368 | libscan makeaperl needs_linking | ||
| 369 | subdir_x test_via_harness test_via_script | ||
| 370 | |||
| 371 | init_VERSION init_dist init_INST init_INSTALL init_DEST init_dirscan | ||
| 372 | init_PM init_MANPODS init_xs init_PERL init_DIRFILESEP init_linker | ||
| 373 | ]; | ||
| 374 | |||
| 375 | push @MM_Sections, qw[ | ||
| 376 | |||
| 377 | pm_to_blib selfdocument | ||
| 378 | |||
| 379 | ]; | ||
| 380 | |||
| 381 | # Postamble needs to be the last that was always the case | ||
| 382 | push @MM_Sections, "postamble"; | ||
| 383 | push @Overridable, "postamble"; | ||
| 384 | |||
| 385 | # All sections are valid keys. | ||
| 386 | @Recognized_Att_Keys{@MM_Sections} = (1) x @MM_Sections; | ||
| 387 | |||
| 388 | # we will use all these variables in the Makefile | ||
| 389 | @Get_from_Config = | ||
| 390 | qw( | ||
| 391 | ar cc cccdlflags ccdlflags dlext dlsrc exe_ext full_ar ld | ||
| 392 | lddlflags ldflags libc lib_ext obj_ext osname osvers ranlib | ||
| 393 | sitelibexp sitearchexp so | ||
| 394 | ); | ||
| 395 | |||
| 396 | # 5.5.3 doesn't have any concept of vendor libs | ||
| 397 | push @Get_from_Config, qw( vendorarchexp vendorlibexp ) if $] >= 5.006; | ||
| 398 | |||
| 399 | foreach my $item (@attrib_help){ | ||
| 400 | $Recognized_Att_Keys{$item} = 1; | ||
| 401 | } | ||
| 402 | foreach my $item (@Get_from_Config) { | ||
| 403 | $Recognized_Att_Keys{uc $item} = $Config{$item}; | ||
| 404 | print "Attribute '\U$item\E' => '$Config{$item}'\n" | ||
| 405 | if ($Verbose >= 2); | ||
| 406 | } | ||
| 407 | |||
| 408 | # | ||
| 409 | # When we eval a Makefile.PL in a subdirectory, that one will ask | ||
| 410 | # us (the parent) for the values and will prepend "..", so that | ||
| 411 | # all files to be installed end up below OUR ./blib | ||
| 412 | # | ||
| 413 | @Prepend_parent = qw( | ||
| 414 | INST_BIN INST_LIB INST_ARCHLIB INST_SCRIPT | ||
| 415 | MAP_TARGET INST_MAN1DIR INST_MAN3DIR PERL_SRC | ||
| 416 | PERL FULLPERL | ||
| 417 | ); | ||
| 418 | } | ||
| 419 | |||
| 420 | sub _has_cpan_meta_requirements { | ||
| 421 | return eval { | ||
| 422 | require CPAN::Meta::Requirements; | ||
| 423 | CPAN::Meta::Requirements->VERSION(2.130); | ||
| 424 | require B; # CMR requires this, for core we have to too. | ||
| 425 | }; | ||
| 426 | } | ||
| 427 | |||
| 428 | sub new { | ||
| 429 | my($class,$self) = @_; | ||
| 430 | my($key); | ||
| 431 | |||
| 432 | _convert_compat_attrs($self) if defined $self && $self; | ||
| 433 | |||
| 434 | # Store the original args passed to WriteMakefile() | ||
| 435 | foreach my $k (keys %$self) { | ||
| 436 | $self->{ARGS}{$k} = $self->{$k}; | ||
| 437 | } | ||
| 438 | |||
| 439 | $self = {} unless defined $self; | ||
| 440 | |||
| 441 | # Temporarily bless it into MM so it can be used as an | ||
| 442 | # object. It will be blessed into a temp package later. | ||
| 443 | bless $self, "MM"; | ||
| 444 | |||
| 445 | # Cleanup all the module requirement bits | ||
| 446 | my %key2cmr; | ||
| 447 | for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { | ||
| 448 | $self->{$key} ||= {}; | ||
| 449 | if (_has_cpan_meta_requirements) { | ||
| 450 | my $cmr = CPAN::Meta::Requirements->from_string_hash( | ||
| 451 | $self->{$key}, | ||
| 452 | { | ||
| 453 | bad_version_hook => sub { | ||
| 454 | #no warnings 'numeric'; # module doesn't use warnings | ||
| 455 | my ($fallback) = $_[0] ? ($_[0] =~ /^([0-9.]+)/) : 0; | ||
| 456 | $fallback += 0; | ||
| 457 | carp "Unparsable version '$_[0]' for prerequisite $_[1] treated as $fallback"; | ||
| 458 | version->new($fallback); | ||
| 459 | }, | ||
| 460 | }, | ||
| 461 | ); | ||
| 462 | $self->{$key} = $cmr->as_string_hash; | ||
| 463 | $key2cmr{$key} = $cmr; | ||
| 464 | } else { | ||
| 465 | for my $module (sort keys %{ $self->{$key} }) { | ||
| 466 | my $version = $self->{$key}->{$module}; | ||
| 467 | my $fallback = 0; | ||
| 468 | if (!defined($version) or !length($version)) { | ||
| 469 | carp "Undefined requirement for $module treated as '0' (CPAN::Meta::Requirements not available)"; | ||
| 470 | } | ||
| 471 | elsif ($version =~ /^\d+(?:\.\d+(?:_\d+)*)?$/) { | ||
| 472 | next; | ||
| 473 | } | ||
| 474 | else { | ||
| 475 | my ($fallback) = $_[0] ? ($_[0] =~ /^([0-9.]+)/) : 0; | ||
| 476 | $fallback += 0; | ||
| 477 | carp "Unparsable version '$version' for prerequisite $module treated as $fallback (CPAN::Meta::Requirements not available)"; | ||
| 478 | } | ||
| 479 | $self->{$key}->{$module} = $fallback; | ||
| 480 | } | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 | if ("@ARGV" =~ /\bPREREQ_PRINT\b/) { | ||
| 485 | $self->_PREREQ_PRINT; | ||
| 486 | } | ||
| 487 | |||
| 488 | # PRINT_PREREQ is RedHatism. | ||
| 489 | if ("@ARGV" =~ /\bPRINT_PREREQ\b/) { | ||
| 490 | $self->_PRINT_PREREQ; | ||
| 491 | } | ||
| 492 | |||
| 493 | print "MakeMaker (v$VERSION)\n" if $Verbose; | ||
| 494 | if (-f "MANIFEST" && ! -f "Makefile" && ! $UNDER_CORE){ | ||
| 495 | check_manifest(); | ||
| 496 | } | ||
| 497 | |||
| 498 | check_hints($self); | ||
| 499 | |||
| 500 | if ( defined $self->{MIN_PERL_VERSION} | ||
| 501 | && $self->{MIN_PERL_VERSION} !~ /^v?[\d_\.]+$/ ) { | ||
| 502 | require version; | ||
| 503 | my $normal = eval { | ||
| 504 | local $SIG{__WARN__} = sub { | ||
| 505 | # simulate "use warnings FATAL => 'all'" for vintage perls | ||
| 506 | die @_; | ||
| 507 | }; | ||
| 508 | version->new( $self->{MIN_PERL_VERSION} ) | ||
| 509 | }; | ||
| 510 | $self->{MIN_PERL_VERSION} = $normal if defined $normal && !$@; | ||
| 511 | } | ||
| 512 | |||
| 513 | # Translate X.Y.Z to X.00Y00Z | ||
| 514 | if( defined $self->{MIN_PERL_VERSION} ) { | ||
| 515 | $self->{MIN_PERL_VERSION} =~ s{ ^v? (\d+) \. (\d+) \. (\d+) $ } | ||
| 516 | {sprintf "%d.%03d%03d", $1, $2, $3}ex; | ||
| 517 | } | ||
| 518 | |||
| 519 | my $perl_version_ok = eval { | ||
| 520 | local $SIG{__WARN__} = sub { | ||
| 521 | # simulate "use warnings FATAL => 'all'" for vintage perls | ||
| 522 | die @_; | ||
| 523 | }; | ||
| 524 | !$self->{MIN_PERL_VERSION} or $self->{MIN_PERL_VERSION} <= $] | ||
| 525 | }; | ||
| 526 | if (!$perl_version_ok) { | ||
| 527 | if (!defined $perl_version_ok) { | ||
| 528 | die <<'END'; | ||
| 529 | Warning: MIN_PERL_VERSION is not in a recognized format. | ||
| 530 | Recommended is a quoted numerical value like '5.005' or '5.008001'. | ||
| 531 | END | ||
| 532 | } | ||
| 533 | elsif ($self->{PREREQ_FATAL}) { | ||
| 534 | die sprintf <<"END", $self->{MIN_PERL_VERSION}, $]; | ||
| 535 | MakeMaker FATAL: perl version too low for this distribution. | ||
| 536 | Required is %s. We run %s. | ||
| 537 | END | ||
| 538 | } | ||
| 539 | else { | ||
| 540 | warn sprintf | ||
| 541 | "Warning: Perl version %s or higher required. We run %s.\n", | ||
| 542 | $self->{MIN_PERL_VERSION}, $]; | ||
| 543 | } | ||
| 544 | } | ||
| 545 | |||
| 546 | my %configure_att; # record &{$self->{CONFIGURE}} attributes | ||
| 547 | my(%initial_att) = %$self; # record initial attributes | ||
| 548 | |||
| 549 | my(%unsatisfied) = (); | ||
| 550 | my %prereq2version; | ||
| 551 | my $cmr; | ||
| 552 | if (_has_cpan_meta_requirements) { | ||
| 553 | $cmr = CPAN::Meta::Requirements->new; | ||
| 554 | for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { | ||
| 555 | $cmr->add_requirements($key2cmr{$key}) if $key2cmr{$key}; | ||
| 556 | } | ||
| 557 | foreach my $prereq ($cmr->required_modules) { | ||
| 558 | $prereq2version{$prereq} = $cmr->requirements_for_module($prereq); | ||
| 559 | } | ||
| 560 | } else { | ||
| 561 | for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) { | ||
| 562 | next unless my $module2version = $self->{$key}; | ||
| 563 | $prereq2version{$_} = $module2version->{$_} for keys %$module2version; | ||
| 564 | } | ||
| 565 | } | ||
| 566 | foreach my $prereq (sort keys %prereq2version) { | ||
| 567 | my $required_version = $prereq2version{$prereq}; | ||
| 568 | |||
| 569 | my $pr_version = 0; | ||
| 570 | my $installed_file; | ||
| 571 | |||
| 572 | if ( $prereq eq 'perl' ) { | ||
| 573 | if ( defined $required_version && $required_version =~ /^v?[\d_\.]+$/ | ||
| 574 | || $required_version !~ /^v?[\d_\.]+$/ ) { | ||
| 575 | require version; | ||
| 576 | my $normal = eval { version->new( $required_version ) }; | ||
| 577 | $required_version = $normal if defined $normal; | ||
| 578 | } | ||
| 579 | $installed_file = $prereq; | ||
| 580 | $pr_version = $]; | ||
| 581 | } | ||
| 582 | else { | ||
| 583 | $installed_file = MM->_installed_file_for_module($prereq); | ||
| 584 | $pr_version = MM->parse_version($installed_file) if $installed_file; | ||
| 585 | $pr_version = 0 if $pr_version eq 'undef'; | ||
| 586 | if ( !eval { version->new( $pr_version ); 1 } ) { | ||
| 587 | #no warnings 'numeric'; # module doesn't use warnings | ||
| 588 | my ($fallback) = $pr_version ? ($pr_version =~ /^([0-9.]+)/) : 0; | ||
| 589 | $fallback += 0; | ||
| 590 | carp "Unparsable version '$pr_version' for installed prerequisite $prereq treated as $fallback"; | ||
| 591 | $pr_version = $fallback; | ||
| 592 | } | ||
| 593 | } | ||
| 594 | |||
| 595 | # convert X.Y_Z alpha version #s to X.YZ for easier comparisons | ||
| 596 | $pr_version =~ s/(\d+)\.(\d+)_(\d+)/$1.$2$3/; | ||
| 597 | |||
| 598 | if (!$installed_file) { | ||
| 599 | warn sprintf "Warning: prerequisite %s %s not found.\n", | ||
| 600 | $prereq, $required_version | ||
| 601 | unless $self->{PREREQ_FATAL} | ||
| 602 | or $UNDER_CORE; | ||
| 603 | |||
| 604 | $unsatisfied{$prereq} = 'not installed'; | ||
| 605 | } | ||
| 606 | elsif ( | ||
| 607 | $cmr | ||
| 608 | ? !$cmr->accepts_module($prereq, $pr_version) | ||
| 609 | : $required_version > $pr_version | ||
| 610 | ) { | ||
| 611 | warn sprintf "Warning: prerequisite %s %s not found. We have %s.\n", | ||
| 612 | $prereq, $required_version, ($pr_version || 'unknown version') | ||
| 613 | unless $self->{PREREQ_FATAL} | ||
| 614 | or $UNDER_CORE; | ||
| 615 | |||
| 616 | $unsatisfied{$prereq} = $required_version || 'unknown version' ; | ||
| 617 | } | ||
| 618 | } | ||
| 619 | |||
| 620 | if (%unsatisfied && $self->{PREREQ_FATAL}){ | ||
| 621 | my $failedprereqs = join "\n", map {" $_ $unsatisfied{$_}"} | ||
| 622 | sort { $a cmp $b } keys %unsatisfied; | ||
| 623 | die <<"END"; | ||
| 624 | MakeMaker FATAL: prerequisites not found. | ||
| 625 | $failedprereqs | ||
| 626 | |||
| 627 | Please install these modules first and rerun 'perl Makefile.PL'. | ||
| 628 | END | ||
| 629 | } | ||
| 630 | |||
| 631 | if (defined $self->{CONFIGURE}) { | ||
| 632 | if (ref $self->{CONFIGURE} eq 'CODE') { | ||
| 633 | %configure_att = %{&{$self->{CONFIGURE}}}; | ||
| 634 | _convert_compat_attrs(\%configure_att); | ||
| 635 | $self = { %$self, %configure_att }; | ||
| 636 | } else { | ||
| 637 | croak "Attribute 'CONFIGURE' to WriteMakefile() not a code reference\n"; | ||
| 638 | } | ||
| 639 | } | ||
| 640 | |||
| 641 | # This is for old Makefiles written pre 5.00, will go away | ||
| 642 | if ( Carp::longmess("") =~ /runsubdirpl/s ){ | ||
| 643 | carp("WARNING: Please rerun 'perl Makefile.PL' to regenerate your Makefiles\n"); | ||
| 644 | } | ||
| 645 | |||
| 646 | my $newclass = ++$PACKNAME; | ||
| 647 | local @Parent = @Parent; # Protect against non-local exits | ||
| 648 | { | ||
| 649 | print "Blessing Object into class [$newclass]\n" if $Verbose>=2; | ||
| 650 | mv_all_methods("MY",$newclass); | ||
| 651 | bless $self, $newclass; | ||
| 652 | push @Parent, $self; | ||
| 653 | require ExtUtils::MY; | ||
| 654 | |||
| 655 | no strict 'refs'; ## no critic; | ||
| 656 | @{"$newclass\:\:ISA"} = 'MM'; | ||
| 657 | } | ||
| 658 | |||
| 659 | if (defined $Parent[-2]){ | ||
| 660 | $self->{PARENT} = $Parent[-2]; | ||
| 661 | for my $key (@Prepend_parent) { | ||
| 662 | next unless defined $self->{PARENT}{$key}; | ||
| 663 | |||
| 664 | # Don't stomp on WriteMakefile() args. | ||
| 665 | next if defined $self->{ARGS}{$key} and | ||
| 666 | $self->{ARGS}{$key} eq $self->{$key}; | ||
| 667 | |||
| 668 | $self->{$key} = $self->{PARENT}{$key}; | ||
| 669 | |||
| 670 | if ($Is_VMS && $key =~ /PERL$/) { | ||
| 671 | # PERL or FULLPERL will be a command verb or even a | ||
| 672 | # command with an argument instead of a full file | ||
| 673 | # specification under VMS. So, don't turn the command | ||
| 674 | # into a filespec, but do add a level to the path of | ||
| 675 | # the argument if not already absolute. | ||
| 676 | my @cmd = split /\s+/, $self->{$key}; | ||
| 677 | $cmd[1] = $self->catfile('[-]',$cmd[1]) | ||
| 678 | unless (@cmd < 2) || $self->file_name_is_absolute($cmd[1]); | ||
| 679 | $self->{$key} = join(' ', @cmd); | ||
| 680 | } else { | ||
| 681 | my $value = $self->{$key}; | ||
| 682 | # not going to test in FS so only stripping start | ||
| 683 | $value =~ s/^"// if $key =~ /PERL$/; | ||
| 684 | $value = $self->catdir("..", $value) | ||
| 685 | unless $self->file_name_is_absolute($value); | ||
| 686 | $value = qq{"$value} if $key =~ /PERL$/; | ||
| 687 | $self->{$key} = $value; | ||
| 688 | } | ||
| 689 | } | ||
| 690 | if ($self->{PARENT}) { | ||
| 691 | $self->{PARENT}->{CHILDREN}->{$newclass} = $self; | ||
| 692 | foreach my $opt (qw(POLLUTE PERL_CORE LINKTYPE LD OPTIMIZE)) { | ||
| 693 | if (exists $self->{PARENT}->{$opt} | ||
| 694 | and not exists $self->{$opt}) | ||
| 695 | { | ||
| 696 | # inherit, but only if already unspecified | ||
| 697 | $self->{$opt} = $self->{PARENT}->{$opt}; | ||
| 698 | } | ||
| 699 | } | ||
| 700 | } | ||
| 701 | my @fm = grep /^FIRST_MAKEFILE=/, @ARGV; | ||
| 702 | parse_args($self,@fm) if @fm; | ||
| 703 | } | ||
| 704 | else { | ||
| 705 | parse_args($self, _shellwords($ENV{PERL_MM_OPT} || ''),@ARGV); | ||
| 706 | } | ||
| 707 | |||
| 708 | # RT#91540 PREREQ_FATAL not recognized on command line | ||
| 709 | if (%unsatisfied && $self->{PREREQ_FATAL}){ | ||
| 710 | my $failedprereqs = join "\n", map {" $_ $unsatisfied{$_}"} | ||
| 711 | sort { $a cmp $b } keys %unsatisfied; | ||
| 712 | die <<"END"; | ||
| 713 | MakeMaker FATAL: prerequisites not found. | ||
| 714 | $failedprereqs | ||
| 715 | |||
| 716 | Please install these modules first and rerun 'perl Makefile.PL'. | ||
| 717 | END | ||
| 718 | } | ||
| 719 | |||
| 720 | $self->{NAME} ||= $self->guess_name; | ||
| 721 | |||
| 722 | warn "Warning: NAME must be a package name\n" | ||
| 723 | unless $self->{NAME} =~ m!^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$!; | ||
| 724 | |||
| 725 | ($self->{NAME_SYM} = $self->{NAME}) =~ s/\W+/_/g; | ||
| 726 | |||
| 727 | $self->init_MAKE; | ||
| 728 | $self->init_main; | ||
| 729 | $self->init_VERSION; | ||
| 730 | $self->init_dist; | ||
| 731 | $self->init_INST; | ||
| 732 | $self->init_INSTALL; | ||
| 733 | $self->init_DEST; | ||
| 734 | $self->init_dirscan; | ||
| 735 | $self->init_PM; | ||
| 736 | $self->init_MANPODS; | ||
| 737 | $self->init_xs; | ||
| 738 | $self->init_PERL; | ||
| 739 | $self->init_DIRFILESEP; | ||
| 740 | $self->init_linker; | ||
| 741 | $self->init_ABSTRACT; | ||
| 742 | |||
| 743 | $self->arch_check( | ||
| 744 | $INC{'Config.pm'}, | ||
| 745 | $self->catfile($Config{'archlibexp'}, "Config.pm") | ||
| 746 | ); | ||
| 747 | |||
| 748 | $self->init_tools(); | ||
| 749 | $self->init_others(); | ||
| 750 | $self->init_platform(); | ||
| 751 | $self->init_PERM(); | ||
| 752 | my @args = @ARGV; | ||
| 753 | @args = map { Encode::decode(locale => $_) } @args if $CAN_DECODE; | ||
| 754 | my($argv) = neatvalue(\@args); | ||
| 755 | $argv =~ s/^\[/(/; | ||
| 756 | $argv =~ s/\]$/)/; | ||
| 757 | |||
| 758 | push @{$self->{RESULT}}, <<END; | ||
| 759 | # This Makefile is for the $self->{NAME} extension to perl. | ||
| 760 | # | ||
| 761 | # It was generated automatically by MakeMaker version | ||
| 762 | # $VERSION (Revision: $Revision) from the contents of | ||
| 763 | # Makefile.PL. Don't edit this file, edit Makefile.PL instead. | ||
| 764 | # | ||
| 765 | # ANY CHANGES MADE HERE WILL BE LOST! | ||
| 766 | # | ||
| 767 | # MakeMaker ARGV: $argv | ||
| 768 | # | ||
| 769 | END | ||
| 770 | |||
| 771 | push @{$self->{RESULT}}, $self->_MakeMaker_Parameters_section(\%initial_att); | ||
| 772 | |||
| 773 | if (defined $self->{CONFIGURE}) { | ||
| 774 | push @{$self->{RESULT}}, <<END; | ||
| 775 | |||
| 776 | # MakeMaker 'CONFIGURE' Parameters: | ||
| 777 | END | ||
| 778 | if (scalar(keys %configure_att) > 0) { | ||
| 779 | foreach my $key (sort keys %configure_att){ | ||
| 780 | next if $key eq 'ARGS'; | ||
| 781 | my($v) = neatvalue($configure_att{$key}); | ||
| 782 | $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/; | ||
| 783 | $v =~ tr/\n/ /s; | ||
| 784 | push @{$self->{RESULT}}, "# $key => $v"; | ||
| 785 | } | ||
| 786 | } | ||
| 787 | else | ||
| 788 | { | ||
| 789 | push @{$self->{RESULT}}, "# no values returned"; | ||
| 790 | } | ||
| 791 | undef %configure_att; # free memory | ||
| 792 | } | ||
| 793 | |||
| 794 | # turn the SKIP array into a SKIPHASH hash | ||
| 795 | for my $skip (@{$self->{SKIP} || []}) { | ||
| 796 | $self->{SKIPHASH}{$skip} = 1; | ||
| 797 | } | ||
| 798 | delete $self->{SKIP}; # free memory | ||
| 799 | |||
| 800 | if ($self->{PARENT}) { | ||
| 801 | for (qw/install dist dist_basics dist_core distdir dist_test dist_ci/) { | ||
| 802 | $self->{SKIPHASH}{$_} = 1; | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | # We run all the subdirectories now. They don't have much to query | ||
| 807 | # from the parent, but the parent has to query them: if they need linking! | ||
| 808 | unless ($self->{NORECURS}) { | ||
| 809 | $self->eval_in_subdirs if @{$self->{DIR}}; | ||
| 810 | } | ||
| 811 | |||
| 812 | foreach my $section ( @MM_Sections ){ | ||
| 813 | # Support for new foo_target() methods. | ||
| 814 | my $method = $section; | ||
| 815 | $method .= '_target' unless $self->can($method); | ||
| 816 | |||
| 817 | print "Processing Makefile '$section' section\n" if ($Verbose >= 2); | ||
| 818 | my($skipit) = $self->skipcheck($section); | ||
| 819 | if ($skipit){ | ||
| 820 | push @{$self->{RESULT}}, "\n# --- MakeMaker $section section $skipit."; | ||
| 821 | } else { | ||
| 822 | my(%a) = %{$self->{$section} || {}}; | ||
| 823 | push @{$self->{RESULT}}, "\n# --- MakeMaker $section section:"; | ||
| 824 | push @{$self->{RESULT}}, "# " . join ", ", %a if $Verbose && %a; | ||
| 825 | push @{$self->{RESULT}}, $self->maketext_filter( | ||
| 826 | $self->$method( %a ) | ||
| 827 | ); | ||
| 828 | } | ||
| 829 | } | ||
| 830 | |||
| 831 | push @{$self->{RESULT}}, "\n# End."; | ||
| 832 | |||
| 833 | $self; | ||
| 834 | } | ||
| 835 | |||
| 836 | sub WriteEmptyMakefile { | ||
| 837 | croak "WriteEmptyMakefile: Need an even number of args" if @_ % 2; | ||
| 838 | |||
| 839 | my %att = @_; | ||
| 840 | $att{DIR} = [] unless $att{DIR}; # don't recurse by default | ||
| 841 | my $self = MM->new(\%att); | ||
| 842 | |||
| 843 | my $new = $self->{MAKEFILE}; | ||
| 844 | my $old = $self->{MAKEFILE_OLD}; | ||
| 845 | if (-f $old) { | ||
| 846 | _unlink($old) or warn "unlink $old: $!"; | ||
| 847 | } | ||
| 848 | if ( -f $new ) { | ||
| 849 | _rename($new, $old) or warn "rename $new => $old: $!" | ||
| 850 | } | ||
| 851 | open my $mfh, '>', $new or die "open $new for write: $!"; | ||
| 852 | print $mfh <<'EOP'; | ||
| 853 | all : | ||
| 854 | |||
| 855 | manifypods : | ||
| 856 | |||
| 857 | subdirs : | ||
| 858 | |||
| 859 | dynamic : | ||
| 860 | |||
| 861 | static : | ||
| 862 | |||
| 863 | clean : | ||
| 864 | |||
| 865 | install : | ||
| 866 | |||
| 867 | makemakerdflt : | ||
| 868 | |||
| 869 | test : | ||
| 870 | |||
| 871 | test_dynamic : | ||
| 872 | |||
| 873 | test_static : | ||
| 874 | |||
| 875 | EOP | ||
| 876 | close $mfh or die "close $new for write: $!"; | ||
| 877 | } | ||
| 878 | |||
| 879 | |||
| 880 | =begin private | ||
| 881 | |||
| 882 | =head3 _installed_file_for_module | ||
| 883 | |||
| 884 | my $file = MM->_installed_file_for_module($module); | ||
| 885 | |||
| 886 | Return the first installed .pm $file associated with the $module. The | ||
| 887 | one which will show up when you C<use $module>. | ||
| 888 | |||
| 889 | $module is something like "strict" or "Test::More". | ||
| 890 | |||
| 891 | =end private | ||
| 892 | |||
| 893 | =cut | ||
| 894 | |||
| 895 | sub _installed_file_for_module { | ||
| 896 | my $class = shift; | ||
| 897 | my $prereq = shift; | ||
| 898 | |||
| 899 | my $file = "$prereq.pm"; | ||
| 900 | $file =~ s{::}{/}g; | ||
| 901 | |||
| 902 | my $path; | ||
| 903 | for my $dir (@INC) { | ||
| 904 | my $tmp = File::Spec->catfile($dir, $file); | ||
| 905 | if ( -r $tmp ) { | ||
| 906 | $path = $tmp; | ||
| 907 | last; | ||
| 908 | } | ||
| 909 | } | ||
| 910 | |||
| 911 | return $path; | ||
| 912 | } | ||
| 913 | |||
| 914 | |||
| 915 | # Extracted from MakeMaker->new so we can test it | ||
| 916 | sub _MakeMaker_Parameters_section { | ||
| 917 | my $self = shift; | ||
| 918 | my $att = shift; | ||
| 919 | |||
| 920 | my @result = <<'END'; | ||
| 921 | # MakeMaker Parameters: | ||
| 922 | END | ||
| 923 | |||
| 924 | foreach my $key (sort keys %$att){ | ||
| 925 | next if $key eq 'ARGS'; | ||
| 926 | my $v; | ||
| 927 | if ($key eq 'PREREQ_PM') { | ||
| 928 | # CPAN.pm takes prereqs from this field in 'Makefile' | ||
| 929 | # and does not know about BUILD_REQUIRES | ||
| 930 | $v = neatvalue({ | ||
| 931 | %{ $att->{PREREQ_PM} || {} }, | ||
| 932 | %{ $att->{BUILD_REQUIRES} || {} }, | ||
| 933 | %{ $att->{TEST_REQUIRES} || {} }, | ||
| 934 | }); | ||
| 935 | } else { | ||
| 936 | $v = neatvalue($att->{$key}); | ||
| 937 | } | ||
| 938 | |||
| 939 | $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/; | ||
| 940 | $v =~ tr/\n/ /s; | ||
| 941 | push @result, "# $key => $v"; | ||
| 942 | } | ||
| 943 | |||
| 944 | return @result; | ||
| 945 | } | ||
| 946 | |||
| 947 | # _shellwords and _parseline borrowed from Text::ParseWords | ||
| 948 | sub _shellwords { | ||
| 949 | my (@lines) = @_; | ||
| 950 | my @allwords; | ||
| 951 | |||
| 952 | foreach my $line (@lines) { | ||
| 953 | $line =~ s/^\s+//; | ||
| 954 | my @words = _parse_line('\s+', 0, $line); | ||
| 955 | pop @words if (@words and !defined $words[-1]); | ||
| 956 | return() unless (@words || !length($line)); | ||
| 957 | push(@allwords, @words); | ||
| 958 | } | ||
| 959 | return(@allwords); | ||
| 960 | } | ||
| 961 | |||
| 962 | sub _parse_line { | ||
| 963 | my($delimiter, $keep, $line) = @_; | ||
| 964 | my($word, @pieces); | ||
| 965 | |||
| 966 | no warnings 'uninitialized'; # we will be testing undef strings | ||
| 967 | |||
| 968 | while (length($line)) { | ||
| 969 | # This pattern is optimised to be stack conservative on older perls. | ||
| 970 | # Do not refactor without being careful and testing it on very long strings. | ||
| 971 | # See Perl bug #42980 for an example of a stack busting input. | ||
| 972 | $line =~ s/^ | ||
| 973 | (?: | ||
| 974 | # double quoted string | ||
| 975 | (") # $quote | ||
| 976 | ((?>[^\\"]*(?:\\.[^\\"]*)*))" # $quoted | ||
| 977 | | # --OR-- | ||
| 978 | # singe quoted string | ||
| 979 | (') # $quote | ||
| 980 | ((?>[^\\']*(?:\\.[^\\']*)*))' # $quoted | ||
| 981 | | # --OR-- | ||
| 982 | # unquoted string | ||
| 983 | ( # $unquoted | ||
| 984 | (?:\\.|[^\\"'])*? | ||
| 985 | ) | ||
| 986 | # followed by | ||
| 987 | ( # $delim | ||
| 988 | \Z(?!\n) # EOL | ||
| 989 | | # --OR-- | ||
| 990 | (?-x:$delimiter) # delimiter | ||
| 991 | | # --OR-- | ||
| 992 | (?!^)(?=["']) # a quote | ||
| 993 | ) | ||
| 994 | )//xs or return; # extended layout | ||
| 995 | my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)), $5, $6); | ||
| 996 | |||
| 997 | |||
| 998 | return() unless( defined($quote) || length($unquoted) || length($delim)); | ||
| 999 | |||
| 1000 | if ($keep) { | ||
| 1001 | $quoted = "$quote$quoted$quote"; | ||
| 1002 | } | ||
| 1003 | else { | ||
| 1004 | $unquoted =~ s/\\(.)/$1/sg; | ||
| 1005 | if (defined $quote) { | ||
| 1006 | $quoted =~ s/\\(.)/$1/sg if ($quote eq '"'); | ||
| 1007 | #$quoted =~ s/\\([\\'])/$1/g if ( $PERL_SINGLE_QUOTE && $quote eq "'"); | ||
| 1008 | } | ||
| 1009 | } | ||
| 1010 | $word .= substr($line, 0, 0); # leave results tainted | ||
| 1011 | $word .= defined $quote ? $quoted : $unquoted; | ||
| 1012 | |||
| 1013 | if (length($delim)) { | ||
| 1014 | push(@pieces, $word); | ||
| 1015 | push(@pieces, $delim) if ($keep eq 'delimiters'); | ||
| 1016 | undef $word; | ||
| 1017 | } | ||
| 1018 | if (!length($line)) { | ||
| 1019 | push(@pieces, $word); | ||
| 1020 | } | ||
| 1021 | } | ||
| 1022 | return(@pieces); | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | sub check_manifest { | ||
| 1026 | print "Checking if your kit is complete...\n"; | ||
| 1027 | require ExtUtils::Manifest; | ||
| 1028 | # avoid warning | ||
| 1029 | $ExtUtils::Manifest::Quiet = $ExtUtils::Manifest::Quiet = 1; | ||
| 1030 | my(@missed) = ExtUtils::Manifest::manicheck(); | ||
| 1031 | if (@missed) { | ||
| 1032 | print "Warning: the following files are missing in your kit:\n"; | ||
| 1033 | print "\t", join "\n\t", @missed; | ||
| 1034 | print "\n"; | ||
| 1035 | print "Please inform the author.\n"; | ||
| 1036 | } else { | ||
| 1037 | print "Looks good\n"; | ||
| 1038 | } | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | sub parse_args{ | ||
| 1042 | my($self, @args) = @_; | ||
| 1043 | @args = map { Encode::decode(locale => $_) } @args if $CAN_DECODE; | ||
| 1044 | foreach (@args) { | ||
| 1045 | unless (m/(.*?)=(.*)/) { | ||
| 1046 | ++$Verbose if m/^verb/; | ||
| 1047 | next; | ||
| 1048 | } | ||
| 1049 | my($name, $value) = ($1, $2); | ||
| 1050 | if ($value =~ m/^~(\w+)?/) { # tilde with optional username | ||
| 1051 | $value =~ s [^~(\w*)] | ||
| 1052 | [$1 ? | ||
| 1053 | ((getpwnam($1))[7] || "~$1") : | ||
| 1054 | (getpwuid($>))[7] | ||
| 1055 | ]ex; | ||
| 1056 | } | ||
| 1057 | |||
| 1058 | # Remember the original args passed it. It will be useful later. | ||
| 1059 | $self->{ARGS}{uc $name} = $self->{uc $name} = $value; | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | # catch old-style 'potential_libs' and inform user how to 'upgrade' | ||
| 1063 | if (defined $self->{potential_libs}){ | ||
| 1064 | my($msg)="'potential_libs' => '$self->{potential_libs}' should be"; | ||
| 1065 | if ($self->{potential_libs}){ | ||
| 1066 | print "$msg changed to:\n\t'LIBS' => ['$self->{potential_libs}']\n"; | ||
| 1067 | } else { | ||
| 1068 | print "$msg deleted.\n"; | ||
| 1069 | } | ||
| 1070 | $self->{LIBS} = [$self->{potential_libs}]; | ||
| 1071 | delete $self->{potential_libs}; | ||
| 1072 | } | ||
| 1073 | # catch old-style 'ARMAYBE' and inform user how to 'upgrade' | ||
| 1074 | if (defined $self->{ARMAYBE}){ | ||
| 1075 | my($armaybe) = $self->{ARMAYBE}; | ||
| 1076 | print "ARMAYBE => '$armaybe' should be changed to:\n", | ||
| 1077 | "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n"; | ||
| 1078 | my(%dl) = %{$self->{dynamic_lib} || {}}; | ||
| 1079 | $self->{dynamic_lib} = { %dl, ARMAYBE => $armaybe}; | ||
| 1080 | delete $self->{ARMAYBE}; | ||
| 1081 | } | ||
| 1082 | if (defined $self->{LDTARGET}){ | ||
| 1083 | print "LDTARGET should be changed to LDFROM\n"; | ||
| 1084 | $self->{LDFROM} = $self->{LDTARGET}; | ||
| 1085 | delete $self->{LDTARGET}; | ||
| 1086 | } | ||
| 1087 | # Turn a DIR argument on the command line into an array | ||
| 1088 | if (defined $self->{DIR} && ref \$self->{DIR} eq 'SCALAR') { | ||
| 1089 | # So they can choose from the command line, which extensions they want | ||
| 1090 | # the grep enables them to have some colons too much in case they | ||
| 1091 | # have to build a list with the shell | ||
| 1092 | $self->{DIR} = [grep $_, split ":", $self->{DIR}]; | ||
| 1093 | } | ||
| 1094 | # Turn a INCLUDE_EXT argument on the command line into an array | ||
| 1095 | if (defined $self->{INCLUDE_EXT} && ref \$self->{INCLUDE_EXT} eq 'SCALAR') { | ||
| 1096 | $self->{INCLUDE_EXT} = [grep $_, split '\s+', $self->{INCLUDE_EXT}]; | ||
| 1097 | } | ||
| 1098 | # Turn a EXCLUDE_EXT argument on the command line into an array | ||
| 1099 | if (defined $self->{EXCLUDE_EXT} && ref \$self->{EXCLUDE_EXT} eq 'SCALAR') { | ||
| 1100 | $self->{EXCLUDE_EXT} = [grep $_, split '\s+', $self->{EXCLUDE_EXT}]; | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | foreach my $mmkey (sort keys %$self){ | ||
| 1104 | next if $mmkey eq 'ARGS'; | ||
| 1105 | print " $mmkey => ", neatvalue($self->{$mmkey}), "\n" if $Verbose; | ||
| 1106 | print "'$mmkey' is not a known MakeMaker parameter name.\n" | ||
| 1107 | unless exists $Recognized_Att_Keys{$mmkey}; | ||
| 1108 | } | ||
| 1109 | $| = 1 if $Verbose; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | sub check_hints { | ||
| 1113 | my($self) = @_; | ||
| 1114 | # We allow extension-specific hints files. | ||
| 1115 | |||
| 1116 | require File::Spec; | ||
| 1117 | my $curdir = File::Spec->curdir; | ||
| 1118 | |||
| 1119 | my $hint_dir = File::Spec->catdir($curdir, "hints"); | ||
| 1120 | return unless -d $hint_dir; | ||
| 1121 | |||
| 1122 | # First we look for the best hintsfile we have | ||
| 1123 | my($hint)="${^O}_$Config{osvers}"; | ||
| 1124 | $hint =~ s/\./_/g; | ||
| 1125 | $hint =~ s/_$//; | ||
| 1126 | return unless $hint; | ||
| 1127 | |||
| 1128 | # Also try without trailing minor version numbers. | ||
| 1129 | while (1) { | ||
| 1130 | last if -f File::Spec->catfile($hint_dir, "$hint.pl"); # found | ||
| 1131 | } continue { | ||
| 1132 | last unless $hint =~ s/_[^_]*$//; # nothing to cut off | ||
| 1133 | } | ||
| 1134 | my $hint_file = File::Spec->catfile($hint_dir, "$hint.pl"); | ||
| 1135 | |||
| 1136 | return unless -f $hint_file; # really there | ||
| 1137 | |||
| 1138 | _run_hintfile($self, $hint_file); | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | sub _run_hintfile { | ||
| 1142 | our $self; | ||
| 1143 | local($self) = shift; # make $self available to the hint file. | ||
| 1144 | my($hint_file) = shift; | ||
| 1145 | |||
| 1146 | local($@, $!); | ||
| 1147 | print "Processing hints file $hint_file\n" if $Verbose; | ||
| 1148 | |||
| 1149 | # Just in case the ./ isn't on the hint file, which File::Spec can | ||
| 1150 | # often strip off, we bung the curdir into @INC | ||
| 1151 | local @INC = (File::Spec->curdir, @INC); | ||
| 1152 | my $ret = do $hint_file; | ||
| 1153 | if( !defined $ret ) { | ||
| 1154 | my $error = $@ || $!; | ||
| 1155 | warn $error; | ||
| 1156 | } | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | sub mv_all_methods { | ||
| 1160 | my($from,$to) = @_; | ||
| 1161 | local $SIG{__WARN__} = sub { | ||
| 1162 | # can't use 'no warnings redefined', 5.6 only | ||
| 1163 | warn @_ unless $_[0] =~ /^Subroutine .* redefined/ | ||
| 1164 | }; | ||
| 1165 | foreach my $method (@Overridable) { | ||
| 1166 | next unless defined &{"${from}::$method"}; | ||
| 1167 | no strict 'refs'; ## no critic | ||
| 1168 | *{"${to}::$method"} = \&{"${from}::$method"}; | ||
| 1169 | |||
| 1170 | # If we delete a method, then it will be undefined and cannot | ||
| 1171 | # be called. But as long as we have Makefile.PLs that rely on | ||
| 1172 | # %MY:: being intact, we have to fill the hole with an | ||
| 1173 | # inheriting method: | ||
| 1174 | |||
| 1175 | { | ||
| 1176 | package MY; | ||
| 1177 | my $super = "SUPER::".$method; | ||
| 1178 | *{$method} = sub { | ||
| 1179 | shift->$super(@_); | ||
| 1180 | }; | ||
| 1181 | } | ||
| 1182 | } | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | sub skipcheck { | ||
| 1186 | my($self) = shift; | ||
| 1187 | my($section) = @_; | ||
| 1188 | return 'skipped' if $section eq 'metafile' && $UNDER_CORE; | ||
| 1189 | if ($section eq 'dynamic') { | ||
| 1190 | print "Warning (non-fatal): Target 'dynamic' depends on targets ", | ||
| 1191 | "in skipped section 'dynamic_bs'\n" | ||
| 1192 | if $self->{SKIPHASH}{dynamic_bs} && $Verbose; | ||
| 1193 | print "Warning (non-fatal): Target 'dynamic' depends on targets ", | ||
| 1194 | "in skipped section 'dynamic_lib'\n" | ||
| 1195 | if $self->{SKIPHASH}{dynamic_lib} && $Verbose; | ||
| 1196 | } | ||
| 1197 | if ($section eq 'dynamic_lib') { | ||
| 1198 | print "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on ", | ||
| 1199 | "targets in skipped section 'dynamic_bs'\n" | ||
| 1200 | if $self->{SKIPHASH}{dynamic_bs} && $Verbose; | ||
| 1201 | } | ||
| 1202 | if ($section eq 'static') { | ||
| 1203 | print "Warning (non-fatal): Target 'static' depends on targets ", | ||
| 1204 | "in skipped section 'static_lib'\n" | ||
| 1205 | if $self->{SKIPHASH}{static_lib} && $Verbose; | ||
| 1206 | } | ||
| 1207 | return 'skipped' if $self->{SKIPHASH}{$section}; | ||
| 1208 | return ''; | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | # returns filehandle, dies on fail. :raw so no :crlf | ||
| 1212 | sub open_for_writing { | ||
| 1213 | my ($file) = @_; | ||
| 1214 | open my $fh ,">", $file or die "Unable to open $file: $!"; | ||
| 1215 | my @layers = ':raw'; | ||
| 1216 | push @layers, join ' ', ':encoding(locale)' if $CAN_DECODE; | ||
| 1217 | binmode $fh, join ' ', @layers; | ||
| 1218 | $fh; | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | sub flush { | ||
| 1222 | my $self = shift; | ||
| 1223 | |||
| 1224 | my $finalname = $self->{MAKEFILE}; | ||
| 1225 | printf "Generating a %s %s\n", $self->make_type, $finalname if $Verbose || !$self->{PARENT}; | ||
| 1226 | print "Writing $finalname for $self->{NAME}\n" if $Verbose || !$self->{PARENT}; | ||
| 1227 | |||
| 1228 | unlink($finalname, "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : ()); | ||
| 1229 | |||
| 1230 | write_file_via_tmp($finalname, $self->{RESULT}); | ||
| 1231 | |||
| 1232 | # Write MYMETA.yml to communicate metadata up to the CPAN clients | ||
| 1233 | print "Writing MYMETA.yml and MYMETA.json\n" | ||
| 1234 | if !$self->{NO_MYMETA} and $self->write_mymeta( $self->mymeta ); | ||
| 1235 | |||
| 1236 | # save memory | ||
| 1237 | if ($self->{PARENT} && !$self->{_KEEP_AFTER_FLUSH}) { | ||
| 1238 | my %keep = map { ($_ => 1) } qw(NEEDS_LINKING HAS_LINK_CODE); | ||
| 1239 | delete $self->{$_} for grep !$keep{$_}, keys %$self; | ||
| 1240 | } | ||
| 1241 | |||
| 1242 | system("$Config::Config{eunicefix} $finalname") | ||
| 1243 | if $Config::Config{eunicefix} ne ":"; | ||
| 1244 | |||
| 1245 | return; | ||
| 1246 | } | ||
| 1247 | |||
| 1248 | sub write_file_via_tmp { | ||
| 1249 | my ($finalname, $contents) = @_; | ||
| 1250 | my $fh = open_for_writing("MakeMaker.tmp"); | ||
| 1251 | die "write_file_via_tmp: 2nd arg must be ref" unless ref $contents; | ||
| 1252 | for my $chunk (@$contents) { | ||
| 1253 | my $to_write = $chunk; | ||
| 1254 | utf8::encode $to_write if !$CAN_DECODE && $] > 5.008; | ||
| 1255 | print $fh "$to_write\n" or die "Can't write to MakeMaker.tmp: $!"; | ||
| 1256 | } | ||
| 1257 | close $fh or die "Can't write to MakeMaker.tmp: $!"; | ||
| 1258 | _rename("MakeMaker.tmp", $finalname) or | ||
| 1259 | warn "rename MakeMaker.tmp => $finalname: $!"; | ||
| 1260 | chmod 0644, $finalname if !$Is_VMS; | ||
| 1261 | return; | ||
| 1262 | } | ||
| 1263 | |||
| 1264 | # This is a rename for OS's where the target must be unlinked first. | ||
| 1265 | sub _rename { | ||
| 1266 | my($src, $dest) = @_; | ||
| 1267 | _unlink($dest); | ||
| 1268 | return rename $src, $dest; | ||
| 1269 | } | ||
| 1270 | |||
| 1271 | # This is an unlink for OS's where the target must be writable first. | ||
| 1272 | sub _unlink { | ||
| 1273 | my @files = @_; | ||
| 1274 | chmod 0666, @files; | ||
| 1275 | return unlink @files; | ||
| 1276 | } | ||
| 1277 | |||
| 1278 | |||
| 1279 | # The following mkbootstrap() is only for installations that are calling | ||
| 1280 | # the pre-4.1 mkbootstrap() from their old Makefiles. This MakeMaker | ||
| 1281 | # writes Makefiles, that use ExtUtils::Mkbootstrap directly. | ||
| 1282 | sub mkbootstrap { | ||
| 1283 | die <<END; | ||
| 1284 | !!! Your Makefile has been built such a long time ago, !!! | ||
| 1285 | !!! that is unlikely to work with current MakeMaker. !!! | ||
| 1286 | !!! Please rebuild your Makefile !!! | ||
| 1287 | END | ||
| 1288 | } | ||
| 1289 | |||
| 1290 | # Ditto for mksymlists() as of MakeMaker 5.17 | ||
| 1291 | sub mksymlists { | ||
| 1292 | die <<END; | ||
| 1293 | !!! Your Makefile has been built such a long time ago, !!! | ||
| 1294 | !!! that is unlikely to work with current MakeMaker. !!! | ||
| 1295 | !!! Please rebuild your Makefile !!! | ||
| 1296 | END | ||
| 1297 | } | ||
| 1298 | |||
| 1299 | sub neatvalue { | ||
| 1300 | my($v) = @_; | ||
| 1301 | return "undef" unless defined $v; | ||
| 1302 | my($t) = ref $v; | ||
| 1303 | return "q[$v]" unless $t; | ||
| 1304 | if ($t eq 'ARRAY') { | ||
| 1305 | my(@m, @neat); | ||
| 1306 | push @m, "["; | ||
| 1307 | foreach my $elem (@$v) { | ||
| 1308 | push @neat, "q[$elem]"; | ||
| 1309 | } | ||
| 1310 | push @m, join ", ", @neat; | ||
| 1311 | push @m, "]"; | ||
| 1312 | return join "", @m; | ||
| 1313 | } | ||
| 1314 | return $v unless $t eq 'HASH'; | ||
| 1315 | my(@m, $key, $val); | ||
| 1316 | for my $key (sort keys %$v) { | ||
| 1317 | last unless defined $key; # cautious programming in case (undef,undef) is true | ||
| 1318 | push @m,"$key=>".neatvalue($v->{$key}); | ||
| 1319 | } | ||
| 1320 | return "{ ".join(', ',@m)." }"; | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | sub _find_magic_vstring { | ||
| 1324 | my $value = shift; | ||
| 1325 | return $value if $UNDER_CORE; | ||
| 1326 | my $tvalue = ''; | ||
| 1327 | require B; | ||
| 1328 | my $sv = B::svref_2object(\$value); | ||
| 1329 | my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef; | ||
| 1330 | while ( $magic ) { | ||
| 1331 | if ( $magic->TYPE eq 'V' ) { | ||
| 1332 | $tvalue = $magic->PTR; | ||
| 1333 | $tvalue =~ s/^v?(.+)$/v$1/; | ||
| 1334 | last; | ||
| 1335 | } | ||
| 1336 | else { | ||
| 1337 | $magic = $magic->MOREMAGIC; | ||
| 1338 | } | ||
| 1339 | } | ||
| 1340 | return $tvalue; | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | sub selfdocument { | ||
| 1344 | my($self) = @_; | ||
| 1345 | my(@m); | ||
| 1346 | if ($Verbose){ | ||
| 1347 | push @m, "\n# Full list of MakeMaker attribute values:"; | ||
| 1348 | foreach my $key (sort keys %$self){ | ||
| 1349 | next if $key eq 'RESULT' || $key =~ /^[A-Z][a-z]/; | ||
| 1350 | my($v) = neatvalue($self->{$key}); | ||
| 1351 | $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/; | ||
| 1352 | $v =~ tr/\n/ /s; | ||
| 1353 | push @m, "# $key => $v"; | ||
| 1354 | } | ||
| 1355 | } | ||
| 1356 | # added here as selfdocument is not overridable | ||
| 1357 | push @m, <<'EOF'; | ||
| 1358 | |||
| 1359 | # here so even if top_targets is overridden, these will still be defined | ||
| 1360 | # gmake will silently still work if any are .PHONY-ed but nmake won't | ||
| 1361 | static :: | ||
| 1362 | $(NOECHO) $(NOOP) | ||
| 1363 | |||
| 1364 | dynamic :: | ||
| 1365 | $(NOECHO) $(NOOP) | ||
| 1366 | EOF | ||
| 1367 | push @m, join "\n", map "$_ ::\n\t\$(NOECHO) \$(NOOP)\n", | ||
| 1368 | # config is so manifypods won't puke if no subdirs | ||
| 1369 | qw(static dynamic config); | ||
| 1370 | join "\n", @m; | ||
| 1371 | } | ||
| 1372 | |||
| 1373 | 1; | ||
| 1374 | |||
| 1375 | __END__ |