| Filename | /usr/share/perl/5.36/ExtUtils/MM_Any.pm |
| Statements | Executed 29 statements in 6.53ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 10µs | 13µs | ExtUtils::MM_Any::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 9µs | ExtUtils::MM_Any::BEGIN@11 |
| 1 | 1 | 1 | 8µs | 8µs | ExtUtils::MM_Any::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 27µs | ExtUtils::MM_Any::BEGIN@1674 |
| 1 | 1 | 1 | 6µs | 70µs | ExtUtils::MM_Any::BEGIN@14 |
| 1 | 1 | 1 | 6µs | 16µs | ExtUtils::MM_Any::BEGIN@16 |
| 1 | 1 | 1 | 6µs | 29µs | ExtUtils::MM_Any::BEGIN@8 |
| 1 | 1 | 1 | 5µs | 22µs | ExtUtils::MM_Any::BEGIN@10 |
| 1 | 1 | 1 | 4µs | 23µs | ExtUtils::MM_Any::BEGIN@4 |
| 1 | 1 | 1 | 400ns | 400ns | ExtUtils::MM_Any::__ANON__ (xsub) |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::POD2MAN_macro |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_PREREQ_PRINT |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_PRINT_PREREQ |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::__ANON__[:1479] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::__ANON__[:2854] |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_add_requirements_to_meta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_add_requirements_to_meta_v1_4 |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_clear_maketype_cache |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_dump_hash |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_expand_macros |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_fix_libs |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_fix_metadata_before_conversion |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_has_cpan_meta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_hash_merge |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_metaspec_version |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_mymeta_from_meta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_normalize_version |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_perl_header_files |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_perl_header_files_fragment |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_sort_pairs |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::_xs_list_basenames |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::all_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::arch_check |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::blessed |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::blibdirs_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::can_dep_space |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::can_load_xs |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::can_redirect_error |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::can_run |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::catfile |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::clean |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::clean_subdirs_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::dir_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::dist_test |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::distdir |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::distmeta_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::distsignature_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::dynamic |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::echo |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::escape_all_dollarsigns |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::escape_dollarsigns |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::extra_clean_files |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::find_tests |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::find_tests_recursive |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::find_tests_recursive_in |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_ABSTRACT |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_INST |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_INSTALL |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_INSTALL_from_INSTALL_BASE |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_INSTALL_from_PREFIX |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_MAKE |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_VERSION |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_others |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_platform |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::init_tools |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::installvars |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::is_make_type |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::libscan |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::make |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::make_type |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::makemakerdflt_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::maketext_filter |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::manifypods |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::manifypods_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::max |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::metafile_data |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::metafile_file |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::metafile_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::min |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::mymeta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::os_flavor_is |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::platform_constants |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::post_constants |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::post_initialize |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::postamble |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::quote_dep |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::realclean |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::realclean_subdirs_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::signature_target |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::special_targets |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::split_command |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::stashmeta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::test_via_harness |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::test_via_script |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::tool_autosplit |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::tools_other |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::wraplist |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::write_mymeta |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::xs_dlsyms_arg |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::xs_dlsyms_ext |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::xs_dlsyms_extra |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::xs_dlsyms_iterator |
| 0 | 0 | 0 | 0s | 0s | ExtUtils::MM_Any::xs_make_dlsyms |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package ExtUtils::MM_Any; | ||||
| 2 | |||||
| 3 | 2 | 22µs | 2 | 15µs | # spent 13µs (10+2) within ExtUtils::MM_Any::BEGIN@3 which was called:
# once (10µs+2µs) by IPC::Cmd::can_run at line 3 # spent 13µs making 1 call to ExtUtils::MM_Any::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | 2 | 29µs | 2 | 42µs | # spent 23µs (4+19) within ExtUtils::MM_Any::BEGIN@4 which was called:
# once (4µs+19µs) by IPC::Cmd::can_run at line 4 # spent 23µs making 1 call to ExtUtils::MM_Any::BEGIN@4
# spent 19µs making 1 call to warnings::import |
| 5 | 1 | 400ns | our $VERSION = '7.64'; | ||
| 6 | 1 | 1µs | $VERSION =~ tr/_//d; | ||
| 7 | |||||
| 8 | 2 | 16µs | 2 | 53µs | # spent 29µs (6+24) within ExtUtils::MM_Any::BEGIN@8 which was called:
# once (6µs+24µs) by IPC::Cmd::can_run at line 8 # spent 29µs making 1 call to ExtUtils::MM_Any::BEGIN@8
# spent 24µs making 1 call to Exporter::import |
| 9 | 2 | 18µs | 2 | 9µs | # spent 8µs (8+400ns) within ExtUtils::MM_Any::BEGIN@9 which was called:
# once (8µs+400ns) by IPC::Cmd::can_run at line 9 # spent 8µs making 1 call to ExtUtils::MM_Any::BEGIN@9
# spent 400ns making 1 call to ExtUtils::MM_Any::__ANON__ |
| 10 | 2 | 21µs | 2 | 40µs | # spent 22µs (5+17) within ExtUtils::MM_Any::BEGIN@10 which was called:
# once (5µs+17µs) by IPC::Cmd::can_run at line 10 # spent 22µs making 1 call to ExtUtils::MM_Any::BEGIN@10
# spent 17µs making 1 call to Exporter::import |
| 11 | 1 | 24µs | 1 | 9µs | # spent 9µs within ExtUtils::MM_Any::BEGIN@11 which was called:
# once (9µs+0s) by IPC::Cmd::can_run at line 11 # spent 9µs making 1 call to ExtUtils::MM_Any::BEGIN@11 |
| 12 | |||||
| 13 | # We need $Verbose | ||||
| 14 | 2 | 17µs | 2 | 133µs | # spent 70µs (6+64) within ExtUtils::MM_Any::BEGIN@14 which was called:
# once (6µs+64µs) by IPC::Cmd::can_run at line 14 # spent 70µs making 1 call to ExtUtils::MM_Any::BEGIN@14
# spent 64µs making 1 call to Exporter::import |
| 15 | |||||
| 16 | 2 | 3.40ms | 2 | 26µs | # spent 16µs (6+10) within ExtUtils::MM_Any::BEGIN@16 which was called:
# once (6µs+10µs) by IPC::Cmd::can_run at line 16 # spent 16µs making 1 call to ExtUtils::MM_Any::BEGIN@16
# spent 10µs making 1 call to ExtUtils::MakeMaker::Config::import |
| 17 | |||||
| 18 | |||||
| 19 | # So we don't have to keep calling the methods over and over again, | ||||
| 20 | # we have these globals to cache the values. Faster and shrtr. | ||||
| 21 | 1 | 7µs | 1 | 2µs | my $Curdir = __PACKAGE__->curdir; # spent 2µs making 1 call to File::Spec::Unix::curdir |
| 22 | #my $Updir = __PACKAGE__->updir; | ||||
| 23 | |||||
| 24 | 1 | 200ns | my $METASPEC_URL = 'https://metacpan.org/pod/CPAN::Meta::Spec'; | ||
| 25 | 1 | 100ns | my $METASPEC_V = 2; | ||
| 26 | |||||
| 27 | =head1 NAME | ||||
| 28 | |||||
| 29 | ExtUtils::MM_Any - Platform-agnostic MM methods | ||||
| 30 | |||||
| 31 | =head1 SYNOPSIS | ||||
| 32 | |||||
| 33 | FOR INTERNAL USE ONLY! | ||||
| 34 | |||||
| 35 | package ExtUtils::MM_SomeOS; | ||||
| 36 | |||||
| 37 | # Temporarily, you have to subclass both. Put MM_Any first. | ||||
| 38 | require ExtUtils::MM_Any; | ||||
| 39 | require ExtUtils::MM_Unix; | ||||
| 40 | @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix); | ||||
| 41 | |||||
| 42 | =head1 DESCRIPTION | ||||
| 43 | |||||
| 44 | B<FOR INTERNAL USE ONLY!> | ||||
| 45 | |||||
| 46 | ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of | ||||
| 47 | modules. It contains methods which are either inherently | ||||
| 48 | cross-platform or are written in a cross-platform manner. | ||||
| 49 | |||||
| 50 | Subclass off of ExtUtils::MM_Any I<and> L<ExtUtils::MM_Unix>. This is a | ||||
| 51 | temporary solution. | ||||
| 52 | |||||
| 53 | B<THIS MAY BE TEMPORARY!> | ||||
| 54 | |||||
| 55 | |||||
| 56 | =head1 METHODS | ||||
| 57 | |||||
| 58 | Any methods marked I<Abstract> must be implemented by subclasses. | ||||
| 59 | |||||
| 60 | |||||
| 61 | =head2 Cross-platform helper methods | ||||
| 62 | |||||
| 63 | These are methods which help writing cross-platform code. | ||||
| 64 | |||||
| - - | |||||
| 67 | =head3 os_flavor I<Abstract> | ||||
| 68 | |||||
| 69 | my @os_flavor = $mm->os_flavor; | ||||
| 70 | |||||
| 71 | @os_flavor is the style of operating system this is, usually | ||||
| 72 | corresponding to the MM_*.pm file we're using. | ||||
| 73 | |||||
| 74 | The first element of @os_flavor is the major family (ie. Unix, | ||||
| 75 | Windows, VMS, OS/2, etc...) and the rest are sub families. | ||||
| 76 | |||||
| 77 | Some examples: | ||||
| 78 | |||||
| 79 | Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x') | ||||
| 80 | Windows ('Win32') | ||||
| 81 | Win98 ('Win32', 'Win9x') | ||||
| 82 | Linux ('Unix', 'Linux') | ||||
| 83 | MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X') | ||||
| 84 | OS/2 ('OS/2') | ||||
| 85 | |||||
| 86 | This is used to write code for styles of operating system. | ||||
| 87 | See os_flavor_is() for use. | ||||
| 88 | |||||
| 89 | |||||
| 90 | =head3 os_flavor_is | ||||
| 91 | |||||
| 92 | my $is_this_flavor = $mm->os_flavor_is($this_flavor); | ||||
| 93 | my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors); | ||||
| 94 | |||||
| 95 | Checks to see if the current operating system is one of the given flavors. | ||||
| 96 | |||||
| 97 | This is useful for code like: | ||||
| 98 | |||||
| 99 | if( $mm->os_flavor_is('Unix') ) { | ||||
| 100 | $out = `foo 2>&1`; | ||||
| 101 | } | ||||
| 102 | else { | ||||
| 103 | $out = `foo`; | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | =cut | ||||
| 107 | |||||
| 108 | sub os_flavor_is { | ||||
| 109 | my $self = shift; | ||||
| 110 | my %flavors = map { ($_ => 1) } $self->os_flavor; | ||||
| 111 | return (grep { $flavors{$_} } @_) ? 1 : 0; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | |||||
| 115 | =head3 can_load_xs | ||||
| 116 | |||||
| 117 | my $can_load_xs = $self->can_load_xs; | ||||
| 118 | |||||
| 119 | Returns true if we have the ability to load XS. | ||||
| 120 | |||||
| 121 | This is important because miniperl, used to build XS modules in the | ||||
| 122 | core, can not load XS. | ||||
| 123 | |||||
| 124 | =cut | ||||
| 125 | |||||
| 126 | sub can_load_xs { | ||||
| 127 | return defined &DynaLoader::boot_DynaLoader ? 1 : 0; | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | |||||
| 131 | =head3 can_run | ||||
| 132 | |||||
| 133 | use ExtUtils::MM; | ||||
| 134 | my $runnable = MM->can_run($Config{make}); | ||||
| 135 | |||||
| 136 | If called in a scalar context it will return the full path to the binary | ||||
| 137 | you asked for if it was found, or C<undef> if it was not. | ||||
| 138 | |||||
| 139 | If called in a list context, it will return a list of the full paths to instances | ||||
| 140 | of the binary where found in C<PATH>, or an empty list if it was not found. | ||||
| 141 | |||||
| 142 | Copied from L<IPC::Cmd|IPC::Cmd/"$path = can_run( PROGRAM );">, but modified into | ||||
| 143 | a method (and removed C<$INSTANCES> capability). | ||||
| 144 | |||||
| 145 | =cut | ||||
| 146 | |||||
| 147 | sub can_run { | ||||
| 148 | my ($self, $command) = @_; | ||||
| 149 | |||||
| 150 | # a lot of VMS executables have a symbol defined | ||||
| 151 | # check those first | ||||
| 152 | if ( $^O eq 'VMS' ) { | ||||
| 153 | require VMS::DCLsym; | ||||
| 154 | my $syms = VMS::DCLsym->new; | ||||
| 155 | return $command if scalar $syms->getsym( uc $command ); | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | my @possibles; | ||||
| 159 | |||||
| 160 | if( File::Spec->file_name_is_absolute($command) ) { | ||||
| 161 | return $self->maybe_command($command); | ||||
| 162 | |||||
| 163 | } else { | ||||
| 164 | for my $dir ( | ||||
| 165 | File::Spec->path, | ||||
| 166 | File::Spec->curdir | ||||
| 167 | ) { | ||||
| 168 | next if ! $dir || ! -d $dir; | ||||
| 169 | my $abs = File::Spec->catfile($self->os_flavor_is('Win32') ? Win32::GetShortPathName( $dir ) : $dir, $command); | ||||
| 170 | push @possibles, $abs if $abs = $self->maybe_command($abs); | ||||
| 171 | } | ||||
| 172 | } | ||||
| 173 | return @possibles if wantarray; | ||||
| 174 | return shift @possibles; | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | |||||
| 178 | =head3 can_redirect_error | ||||
| 179 | |||||
| 180 | $useredirect = MM->can_redirect_error; | ||||
| 181 | |||||
| 182 | True if on an OS where qx operator (or backticks) can redirect C<STDERR> | ||||
| 183 | onto C<STDOUT>. | ||||
| 184 | |||||
| 185 | =cut | ||||
| 186 | |||||
| 187 | sub can_redirect_error { | ||||
| 188 | my $self = shift; | ||||
| 189 | $self->os_flavor_is('Unix') | ||||
| 190 | or ($self->os_flavor_is('Win32') and !$self->os_flavor_is('Win9x')) | ||||
| 191 | or $self->os_flavor_is('OS/2') | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | |||||
| 195 | =head3 is_make_type | ||||
| 196 | |||||
| 197 | my $is_dmake = $self->is_make_type('dmake'); | ||||
| 198 | |||||
| 199 | Returns true if C<< $self->make >> is the given type; possibilities are: | ||||
| 200 | |||||
| 201 | gmake GNU make | ||||
| 202 | dmake | ||||
| 203 | nmake | ||||
| 204 | bsdmake BSD pmake-derived | ||||
| 205 | |||||
| 206 | =cut | ||||
| 207 | |||||
| 208 | 1 | 200ns | my %maketype2true; | ||
| 209 | # undocumented - so t/cd.t can still do its thing | ||||
| 210 | sub _clear_maketype_cache { %maketype2true = () } | ||||
| 211 | |||||
| 212 | sub is_make_type { | ||||
| 213 | my($self, $type) = @_; | ||||
| 214 | return $maketype2true{$type} if defined $maketype2true{$type}; | ||||
| 215 | (undef, undef, my $make_basename) = $self->splitpath($self->make); | ||||
| 216 | return $maketype2true{$type} = 1 | ||||
| 217 | if $make_basename =~ /\b$type\b/i; # executable's filename | ||||
| 218 | return $maketype2true{$type} = 0 | ||||
| 219 | if $make_basename =~ /\b[gdn]make\b/i; # Never fall through for dmake/nmake/gmake | ||||
| 220 | # now have to run with "-v" and guess | ||||
| 221 | my $redirect = $self->can_redirect_error ? '2>&1' : ''; | ||||
| 222 | my $make = $self->make || $self->{MAKE}; | ||||
| 223 | my $minus_v = `"$make" -v $redirect`; | ||||
| 224 | return $maketype2true{$type} = 1 | ||||
| 225 | if $type eq 'gmake' and $minus_v =~ /GNU make/i; | ||||
| 226 | return $maketype2true{$type} = 1 | ||||
| 227 | if $type eq 'bsdmake' | ||||
| 228 | and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im; | ||||
| 229 | $maketype2true{$type} = 0; # it wasn't whatever you asked | ||||
| 230 | } | ||||
| 231 | |||||
| 232 | |||||
| 233 | =head3 can_dep_space | ||||
| 234 | |||||
| 235 | my $can_dep_space = $self->can_dep_space; | ||||
| 236 | |||||
| 237 | Returns true if C<make> can handle (probably by quoting) | ||||
| 238 | dependencies that contain a space. Currently known true for GNU make, | ||||
| 239 | false for BSD pmake derivative. | ||||
| 240 | |||||
| 241 | =cut | ||||
| 242 | |||||
| 243 | my $cached_dep_space; | ||||
| 244 | sub can_dep_space { | ||||
| 245 | my $self = shift; | ||||
| 246 | return $cached_dep_space if defined $cached_dep_space; | ||||
| 247 | return $cached_dep_space = 1 if $self->is_make_type('gmake'); | ||||
| 248 | return $cached_dep_space = 0 if $self->is_make_type('dmake'); # only on W32 | ||||
| 249 | return $cached_dep_space = 0 if $self->is_make_type('bsdmake'); | ||||
| 250 | return $cached_dep_space = 0; # assume no | ||||
| 251 | } | ||||
| 252 | |||||
| 253 | |||||
| 254 | =head3 quote_dep | ||||
| 255 | |||||
| 256 | $text = $mm->quote_dep($text); | ||||
| 257 | |||||
| 258 | Method that protects Makefile single-value constants (mainly filenames), | ||||
| 259 | so that make will still treat them as single values even if they | ||||
| 260 | inconveniently have spaces in. If the make program being used cannot | ||||
| 261 | achieve such protection and the given text would need it, throws an | ||||
| 262 | exception. | ||||
| 263 | |||||
| 264 | =cut | ||||
| 265 | |||||
| 266 | sub quote_dep { | ||||
| 267 | my ($self, $arg) = @_; | ||||
| 268 | die <<EOF if $arg =~ / / and not $self->can_dep_space; | ||||
| 269 | Tried to use make dependency with space for make that can't: | ||||
| 270 | '$arg' | ||||
| 271 | EOF | ||||
| 272 | $arg =~ s/( )/\\$1/g; # how GNU make does it | ||||
| 273 | return $arg; | ||||
| 274 | } | ||||
| 275 | |||||
| 276 | |||||
| 277 | =head3 split_command | ||||
| 278 | |||||
| 279 | my @cmds = $MM->split_command($cmd, @args); | ||||
| 280 | |||||
| 281 | Most OS have a maximum command length they can execute at once. Large | ||||
| 282 | modules can easily generate commands well past that limit. Its | ||||
| 283 | necessary to split long commands up into a series of shorter commands. | ||||
| 284 | |||||
| 285 | C<split_command> will return a series of @cmds each processing part of | ||||
| 286 | the args. Collectively they will process all the arguments. Each | ||||
| 287 | individual line in @cmds will not be longer than the | ||||
| 288 | $self->max_exec_len being careful to take into account macro expansion. | ||||
| 289 | |||||
| 290 | $cmd should include any switches and repeated initial arguments. | ||||
| 291 | |||||
| 292 | If no @args are given, no @cmds will be returned. | ||||
| 293 | |||||
| 294 | Pairs of arguments will always be preserved in a single command, this | ||||
| 295 | is a heuristic for things like pm_to_blib and pod2man which work on | ||||
| 296 | pairs of arguments. This makes things like this safe: | ||||
| 297 | |||||
| 298 | $self->split_command($cmd, %pod2man); | ||||
| 299 | |||||
| 300 | |||||
| 301 | =cut | ||||
| 302 | |||||
| 303 | sub split_command { | ||||
| 304 | my($self, $cmd, @args) = @_; | ||||
| 305 | |||||
| 306 | my @cmds = (); | ||||
| 307 | return(@cmds) unless @args; | ||||
| 308 | |||||
| 309 | # If the command was given as a here-doc, there's probably a trailing | ||||
| 310 | # newline. | ||||
| 311 | chomp $cmd; | ||||
| 312 | |||||
| 313 | # set aside 30% for macro expansion. | ||||
| 314 | my $len_left = int($self->max_exec_len * 0.70); | ||||
| 315 | $len_left -= length $self->_expand_macros($cmd); | ||||
| 316 | |||||
| 317 | do { | ||||
| 318 | my $arg_str = ''; | ||||
| 319 | my @next_args; | ||||
| 320 | while( @next_args = splice(@args, 0, 2) ) { | ||||
| 321 | # Two at a time to preserve pairs. | ||||
| 322 | my $next_arg_str = "\t ". join ' ', @next_args, "\n"; | ||||
| 323 | |||||
| 324 | if( !length $arg_str ) { | ||||
| 325 | $arg_str .= $next_arg_str | ||||
| 326 | } | ||||
| 327 | elsif( length($arg_str) + length($next_arg_str) > $len_left ) { | ||||
| 328 | unshift @args, @next_args; | ||||
| 329 | last; | ||||
| 330 | } | ||||
| 331 | else { | ||||
| 332 | $arg_str .= $next_arg_str; | ||||
| 333 | } | ||||
| 334 | } | ||||
| 335 | chop $arg_str; | ||||
| 336 | |||||
| 337 | push @cmds, $self->escape_newlines("$cmd \n$arg_str"); | ||||
| 338 | } while @args; | ||||
| 339 | |||||
| 340 | return @cmds; | ||||
| 341 | } | ||||
| 342 | |||||
| 343 | |||||
| 344 | sub _expand_macros { | ||||
| 345 | my($self, $cmd) = @_; | ||||
| 346 | |||||
| 347 | $cmd =~ s{\$\((\w+)\)}{ | ||||
| 348 | defined $self->{$1} ? $self->{$1} : "\$($1)" | ||||
| 349 | }e; | ||||
| 350 | return $cmd; | ||||
| 351 | } | ||||
| 352 | |||||
| 353 | |||||
| 354 | =head3 make_type | ||||
| 355 | |||||
| 356 | Returns a suitable string describing the type of makefile being written. | ||||
| 357 | |||||
| 358 | =cut | ||||
| 359 | |||||
| 360 | # override if this isn't suitable! | ||||
| 361 | sub make_type { return 'Unix-style'; } | ||||
| 362 | |||||
| 363 | |||||
| 364 | =head3 stashmeta | ||||
| 365 | |||||
| 366 | my @recipelines = $MM->stashmeta($text, $file); | ||||
| 367 | |||||
| 368 | Generates a set of C<@recipelines> which will result in the literal | ||||
| 369 | C<$text> ending up in literal C<$file> when the recipe is executed. Call | ||||
| 370 | it once, with all the text you want in C<$file>. Make macros will not | ||||
| 371 | be expanded, so the locations will be fixed at configure-time, not | ||||
| 372 | at build-time. | ||||
| 373 | |||||
| 374 | =cut | ||||
| 375 | |||||
| 376 | sub stashmeta { | ||||
| 377 | my($self, $text, $file) = @_; | ||||
| 378 | $self->echo($text, $file, { allow_variables => 0, append => 0 }); | ||||
| 379 | } | ||||
| 380 | |||||
| 381 | |||||
| 382 | =head3 echo | ||||
| 383 | |||||
| 384 | my @commands = $MM->echo($text); | ||||
| 385 | my @commands = $MM->echo($text, $file); | ||||
| 386 | my @commands = $MM->echo($text, $file, \%opts); | ||||
| 387 | |||||
| 388 | Generates a set of @commands which print the $text to a $file. | ||||
| 389 | |||||
| 390 | If $file is not given, output goes to STDOUT. | ||||
| 391 | |||||
| 392 | If $opts{append} is true the $file will be appended to rather than | ||||
| 393 | overwritten. Default is to overwrite. | ||||
| 394 | |||||
| 395 | If $opts{allow_variables} is true, make variables of the form | ||||
| 396 | C<$(...)> will not be escaped. Other C<$> will. Default is to escape | ||||
| 397 | all C<$>. | ||||
| 398 | |||||
| 399 | Example of use: | ||||
| 400 | |||||
| 401 | my $make = join '', map "\t$_\n", $MM->echo($text, $file); | ||||
| 402 | |||||
| 403 | =cut | ||||
| 404 | |||||
| 405 | sub echo { | ||||
| 406 | my($self, $text, $file, $opts) = @_; | ||||
| 407 | |||||
| 408 | # Compatibility with old options | ||||
| 409 | if( !ref $opts ) { | ||||
| 410 | my $append = $opts; | ||||
| 411 | $opts = { append => $append || 0 }; | ||||
| 412 | } | ||||
| 413 | $opts->{allow_variables} = 0 unless defined $opts->{allow_variables}; | ||||
| 414 | |||||
| 415 | my $ql_opts = { allow_variables => $opts->{allow_variables} }; | ||||
| 416 | my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_, $ql_opts) } | ||||
| 417 | split /\n/, $text; | ||||
| 418 | if( $file ) { | ||||
| 419 | my $redirect = $opts->{append} ? '>>' : '>'; | ||||
| 420 | $cmds[0] .= " $redirect $file"; | ||||
| 421 | $_ .= " >> $file" foreach @cmds[1..$#cmds]; | ||||
| 422 | } | ||||
| 423 | |||||
| 424 | return @cmds; | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | |||||
| 428 | =head3 wraplist | ||||
| 429 | |||||
| 430 | my $args = $mm->wraplist(@list); | ||||
| 431 | |||||
| 432 | Takes an array of items and turns them into a well-formatted list of | ||||
| 433 | arguments. In most cases this is simply something like: | ||||
| 434 | |||||
| 435 | FOO \ | ||||
| 436 | BAR \ | ||||
| 437 | BAZ | ||||
| 438 | |||||
| 439 | =cut | ||||
| 440 | |||||
| 441 | sub wraplist { | ||||
| 442 | my $self = shift; | ||||
| 443 | return join " \\\n\t", @_; | ||||
| 444 | } | ||||
| 445 | |||||
| 446 | |||||
| 447 | =head3 maketext_filter | ||||
| 448 | |||||
| 449 | my $filter_make_text = $mm->maketext_filter($make_text); | ||||
| 450 | |||||
| 451 | The text of the Makefile is run through this method before writing to | ||||
| 452 | disk. It allows systems a chance to make portability fixes to the | ||||
| 453 | Makefile. | ||||
| 454 | |||||
| 455 | By default it does nothing. | ||||
| 456 | |||||
| 457 | This method is protected and not intended to be called outside of | ||||
| 458 | MakeMaker. | ||||
| 459 | |||||
| 460 | =cut | ||||
| 461 | |||||
| 462 | sub maketext_filter { return $_[1] } | ||||
| 463 | |||||
| 464 | |||||
| 465 | =head3 cd I<Abstract> | ||||
| 466 | |||||
| 467 | my $subdir_cmd = $MM->cd($subdir, @cmds); | ||||
| 468 | |||||
| 469 | This will generate a make fragment which runs the @cmds in the given | ||||
| 470 | $dir. The rough equivalent to this, except cross platform. | ||||
| 471 | |||||
| 472 | cd $subdir && $cmd | ||||
| 473 | |||||
| 474 | Currently $dir can only go down one level. "foo" is fine. "foo/bar" is | ||||
| 475 | not. "../foo" is right out. | ||||
| 476 | |||||
| 477 | The resulting $subdir_cmd has no leading tab nor trailing newline. This | ||||
| 478 | makes it easier to embed in a make string. For example. | ||||
| 479 | |||||
| 480 | my $make = sprintf <<'CODE', $subdir_cmd; | ||||
| 481 | foo : | ||||
| 482 | $(ECHO) what | ||||
| 483 | %s | ||||
| 484 | $(ECHO) mouche | ||||
| 485 | CODE | ||||
| 486 | |||||
| 487 | |||||
| 488 | =head3 oneliner I<Abstract> | ||||
| 489 | |||||
| 490 | my $oneliner = $MM->oneliner($perl_code); | ||||
| 491 | my $oneliner = $MM->oneliner($perl_code, \@switches); | ||||
| 492 | |||||
| 493 | This will generate a perl one-liner safe for the particular platform | ||||
| 494 | you're on based on the given $perl_code and @switches (a -e is | ||||
| 495 | assumed) suitable for using in a make target. It will use the proper | ||||
| 496 | shell quoting and escapes. | ||||
| 497 | |||||
| 498 | $(PERLRUN) will be used as perl. | ||||
| 499 | |||||
| 500 | Any newlines in $perl_code will be escaped. Leading and trailing | ||||
| 501 | newlines will be stripped. Makes this idiom much easier: | ||||
| 502 | |||||
| 503 | my $code = $MM->oneliner(<<'CODE', [...switches...]); | ||||
| 504 | some code here | ||||
| 505 | another line here | ||||
| 506 | CODE | ||||
| 507 | |||||
| 508 | Usage might be something like: | ||||
| 509 | |||||
| 510 | # an echo emulation | ||||
| 511 | $oneliner = $MM->oneliner('print "Foo\n"'); | ||||
| 512 | $make = '$oneliner > somefile'; | ||||
| 513 | |||||
| 514 | Dollar signs in the $perl_code will be protected from make using the | ||||
| 515 | C<quote_literal> method, unless they are recognised as being a make | ||||
| 516 | variable, C<$(varname)>, in which case they will be left for make | ||||
| 517 | to expand. Remember to quote make macros else it might be used as a | ||||
| 518 | bareword. For example: | ||||
| 519 | |||||
| 520 | # Assign the value of the $(VERSION_FROM) make macro to $vf. | ||||
| 521 | $oneliner = $MM->oneliner('$vf = "$(VERSION_FROM)"'); | ||||
| 522 | |||||
| 523 | Its currently very simple and may be expanded sometime in the figure | ||||
| 524 | to include more flexible code and switches. | ||||
| 525 | |||||
| 526 | |||||
| 527 | =head3 quote_literal I<Abstract> | ||||
| 528 | |||||
| 529 | my $safe_text = $MM->quote_literal($text); | ||||
| 530 | my $safe_text = $MM->quote_literal($text, \%options); | ||||
| 531 | |||||
| 532 | This will quote $text so it is interpreted literally in the shell. | ||||
| 533 | |||||
| 534 | For example, on Unix this would escape any single-quotes in $text and | ||||
| 535 | put single-quotes around the whole thing. | ||||
| 536 | |||||
| 537 | If $options{allow_variables} is true it will leave C<'$(FOO)'> make | ||||
| 538 | variables untouched. If false they will be escaped like any other | ||||
| 539 | C<$>. Defaults to true. | ||||
| 540 | |||||
| 541 | =head3 escape_dollarsigns | ||||
| 542 | |||||
| 543 | my $escaped_text = $MM->escape_dollarsigns($text); | ||||
| 544 | |||||
| 545 | Escapes stray C<$> so they are not interpreted as make variables. | ||||
| 546 | |||||
| 547 | It lets by C<$(...)>. | ||||
| 548 | |||||
| 549 | =cut | ||||
| 550 | |||||
| 551 | sub escape_dollarsigns { | ||||
| 552 | my($self, $text) = @_; | ||||
| 553 | |||||
| 554 | # Escape dollar signs which are not starting a variable | ||||
| 555 | $text =~ s{\$ (?!\() }{\$\$}gx; | ||||
| 556 | |||||
| 557 | return $text; | ||||
| 558 | } | ||||
| 559 | |||||
| 560 | |||||
| 561 | =head3 escape_all_dollarsigns | ||||
| 562 | |||||
| 563 | my $escaped_text = $MM->escape_all_dollarsigns($text); | ||||
| 564 | |||||
| 565 | Escapes all C<$> so they are not interpreted as make variables. | ||||
| 566 | |||||
| 567 | =cut | ||||
| 568 | |||||
| 569 | sub escape_all_dollarsigns { | ||||
| 570 | my($self, $text) = @_; | ||||
| 571 | |||||
| 572 | # Escape dollar signs | ||||
| 573 | $text =~ s{\$}{\$\$}gx; | ||||
| 574 | |||||
| 575 | return $text; | ||||
| 576 | } | ||||
| 577 | |||||
| 578 | |||||
| 579 | =head3 escape_newlines I<Abstract> | ||||
| 580 | |||||
| 581 | my $escaped_text = $MM->escape_newlines($text); | ||||
| 582 | |||||
| 583 | Shell escapes newlines in $text. | ||||
| 584 | |||||
| 585 | |||||
| 586 | =head3 max_exec_len I<Abstract> | ||||
| 587 | |||||
| 588 | my $max_exec_len = $MM->max_exec_len; | ||||
| 589 | |||||
| 590 | Calculates the maximum command size the OS can exec. Effectively, | ||||
| 591 | this is the max size of a shell command line. | ||||
| 592 | |||||
| 593 | =for _private | ||||
| 594 | $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes. | ||||
| 595 | |||||
| 596 | |||||
| 597 | =head3 make | ||||
| 598 | |||||
| 599 | my $make = $MM->make; | ||||
| 600 | |||||
| 601 | Returns the make variant we're generating the Makefile for. This attempts | ||||
| 602 | to do some normalization on the information from %Config or the user. | ||||
| 603 | |||||
| 604 | =cut | ||||
| 605 | |||||
| 606 | sub make { | ||||
| 607 | my $self = shift; | ||||
| 608 | |||||
| 609 | my $make = lc $self->{MAKE}; | ||||
| 610 | |||||
| 611 | # Truncate anything like foomake6 to just foomake. | ||||
| 612 | $make =~ s/^(\w+make).*/$1/; | ||||
| 613 | |||||
| 614 | # Turn gnumake into gmake. | ||||
| 615 | $make =~ s/^gnu/g/; | ||||
| 616 | |||||
| 617 | return $make; | ||||
| 618 | } | ||||
| 619 | |||||
| 620 | |||||
| 621 | =head2 Targets | ||||
| 622 | |||||
| 623 | These are methods which produce make targets. | ||||
| 624 | |||||
| 625 | |||||
| 626 | =head3 all_target | ||||
| 627 | |||||
| 628 | Generate the default target 'all'. | ||||
| 629 | |||||
| 630 | =cut | ||||
| 631 | |||||
| 632 | sub all_target { | ||||
| 633 | my $self = shift; | ||||
| 634 | |||||
| 635 | return <<'MAKE_EXT'; | ||||
| 636 | all :: pure_all | ||||
| 637 | $(NOECHO) $(NOOP) | ||||
| 638 | MAKE_EXT | ||||
| 639 | |||||
| 640 | } | ||||
| 641 | |||||
| 642 | |||||
| 643 | =head3 blibdirs_target | ||||
| 644 | |||||
| 645 | my $make_frag = $mm->blibdirs_target; | ||||
| 646 | |||||
| 647 | Creates the blibdirs target which creates all the directories we use | ||||
| 648 | in blib/. | ||||
| 649 | |||||
| 650 | The blibdirs.ts target is deprecated. Depend on blibdirs instead. | ||||
| 651 | |||||
| 652 | |||||
| 653 | =cut | ||||
| 654 | |||||
| 655 | sub _xs_list_basenames { | ||||
| 656 | my ($self) = @_; | ||||
| 657 | map { (my $b = $_) =~ s/\.xs$//; $b } sort keys %{ $self->{XS} }; | ||||
| 658 | } | ||||
| 659 | |||||
| 660 | sub blibdirs_target { | ||||
| 661 | my $self = shift; | ||||
| 662 | |||||
| 663 | my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib | ||||
| 664 | autodir archautodir | ||||
| 665 | bin script | ||||
| 666 | man1dir man3dir | ||||
| 667 | ); | ||||
| 668 | if ($self->{XSMULTI}) { | ||||
| 669 | for my $ext ($self->_xs_list_basenames) { | ||||
| 670 | my ($v, $d, $f) = File::Spec->splitpath($ext); | ||||
| 671 | my @d = File::Spec->splitdir($d); | ||||
| 672 | shift @d if $d[0] eq 'lib'; | ||||
| 673 | push @dirs, $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f); | ||||
| 674 | } | ||||
| 675 | } | ||||
| 676 | |||||
| 677 | my @exists = map { $_.'$(DFSEP).exists' } @dirs; | ||||
| 678 | |||||
| 679 | my $make = sprintf <<'MAKE', join(' ', @exists); | ||||
| 680 | blibdirs : %s | ||||
| 681 | $(NOECHO) $(NOOP) | ||||
| 682 | |||||
| 683 | # Backwards compat with 6.18 through 6.25 | ||||
| 684 | blibdirs.ts : blibdirs | ||||
| 685 | $(NOECHO) $(NOOP) | ||||
| 686 | |||||
| 687 | MAKE | ||||
| 688 | |||||
| 689 | $make .= $self->dir_target(@dirs); | ||||
| 690 | |||||
| 691 | return $make; | ||||
| 692 | } | ||||
| 693 | |||||
| 694 | |||||
| 695 | =head3 clean (o) | ||||
| 696 | |||||
| 697 | Defines the clean target. | ||||
| 698 | |||||
| 699 | =cut | ||||
| 700 | |||||
| 701 | sub clean { | ||||
| 702 | # --- Cleanup and Distribution Sections --- | ||||
| 703 | |||||
| 704 | my($self, %attribs) = @_; | ||||
| 705 | my @m; | ||||
| 706 | push(@m, ' | ||||
| 707 | # Delete temporary files but do not touch installed files. We don\'t delete | ||||
| 708 | # the Makefile here so a later make realclean still has a makefile to use. | ||||
| 709 | |||||
| 710 | clean :: clean_subdirs | ||||
| 711 | '); | ||||
| 712 | |||||
| 713 | my @files = sort values %{$self->{XS}}; # .c files from *.xs files | ||||
| 714 | push @files, map { | ||||
| 715 | my $file = $_; | ||||
| 716 | map { $file.$_ } $self->{OBJ_EXT}, qw(.def _def.old .bs .bso .exp .base); | ||||
| 717 | } $self->_xs_list_basenames; | ||||
| 718 | my @dirs = qw(blib); | ||||
| 719 | |||||
| 720 | # Normally these are all under blib but they might have been | ||||
| 721 | # redefined. | ||||
| 722 | # XXX normally this would be a good idea, but the Perl core sets | ||||
| 723 | # INST_LIB = ../../lib rather than actually installing the files. | ||||
| 724 | # So a "make clean" in an ext/ directory would blow away lib. | ||||
| 725 | # Until the core is adjusted let's leave this out. | ||||
| 726 | # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB) | ||||
| 727 | # $(INST_BIN) $(INST_SCRIPT) | ||||
| 728 | # $(INST_MAN1DIR) $(INST_MAN3DIR) | ||||
| 729 | # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR) | ||||
| 730 | # $(INST_STATIC) $(INST_DYNAMIC) | ||||
| 731 | # ); | ||||
| 732 | |||||
| 733 | |||||
| 734 | if( $attribs{FILES} ) { | ||||
| 735 | # Use @dirs because we don't know what's in here. | ||||
| 736 | push @dirs, ref $attribs{FILES} ? | ||||
| 737 | @{$attribs{FILES}} : | ||||
| 738 | split /\s+/, $attribs{FILES} ; | ||||
| 739 | } | ||||
| 740 | |||||
| 741 | push(@files, qw[$(MAKE_APERL_FILE) | ||||
| 742 | MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations | ||||
| 743 | blibdirs.ts pm_to_blib pm_to_blib.ts | ||||
| 744 | *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT) | ||||
| 745 | $(BOOTSTRAP) $(BASEEXT).bso | ||||
| 746 | $(BASEEXT).def lib$(BASEEXT).def | ||||
| 747 | $(BASEEXT).exp $(BASEEXT).x | ||||
| 748 | ]); | ||||
| 749 | |||||
| 750 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all')); | ||||
| 751 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld')); | ||||
| 752 | |||||
| 753 | # core files | ||||
| 754 | if ($^O eq 'vos') { | ||||
| 755 | push(@files, qw[perl*.kp]); | ||||
| 756 | } | ||||
| 757 | else { | ||||
| 758 | push(@files, qw[core core.*perl.*.? *perl.core]); | ||||
| 759 | } | ||||
| 760 | |||||
| 761 | push(@files, map { "core." . "[0-9]"x$_ } (1..5)); | ||||
| 762 | |||||
| 763 | # OS specific things to clean up. Use @dirs since we don't know | ||||
| 764 | # what might be in here. | ||||
| 765 | push @dirs, $self->extra_clean_files; | ||||
| 766 | |||||
| 767 | # Occasionally files are repeated several times from different sources | ||||
| 768 | { my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; } | ||||
| 769 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; } | ||||
| 770 | |||||
| 771 | push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files); | ||||
| 772 | push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs); | ||||
| 773 | |||||
| 774 | # Leave Makefile.old around for realclean | ||||
| 775 | push @m, <<'MAKE'; | ||||
| 776 | $(NOECHO) $(RM_F) $(MAKEFILE_OLD) | ||||
| 777 | - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL) | ||||
| 778 | MAKE | ||||
| 779 | |||||
| 780 | push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP}; | ||||
| 781 | |||||
| 782 | join("", @m); | ||||
| 783 | } | ||||
| 784 | |||||
| 785 | |||||
| 786 | =head3 clean_subdirs_target | ||||
| 787 | |||||
| 788 | my $make_frag = $MM->clean_subdirs_target; | ||||
| 789 | |||||
| 790 | Returns the clean_subdirs target. This is used by the clean target to | ||||
| 791 | call clean on any subdirectories which contain Makefiles. | ||||
| 792 | |||||
| 793 | =cut | ||||
| 794 | |||||
| 795 | sub clean_subdirs_target { | ||||
| 796 | my($self) = shift; | ||||
| 797 | |||||
| 798 | # No subdirectories, no cleaning. | ||||
| 799 | return <<'NOOP_FRAG' unless @{$self->{DIR}}; | ||||
| 800 | clean_subdirs : | ||||
| 801 | $(NOECHO) $(NOOP) | ||||
| 802 | NOOP_FRAG | ||||
| 803 | |||||
| 804 | |||||
| 805 | my $clean = "clean_subdirs :\n"; | ||||
| 806 | |||||
| 807 | for my $dir (@{$self->{DIR}}) { | ||||
| 808 | my $subclean = $self->oneliner(sprintf <<'CODE', $dir); | ||||
| 809 | exit 0 unless chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)'; | ||||
| 810 | CODE | ||||
| 811 | |||||
| 812 | $clean .= "\t$subclean\n"; | ||||
| 813 | } | ||||
| 814 | |||||
| 815 | return $clean; | ||||
| 816 | } | ||||
| 817 | |||||
| 818 | |||||
| 819 | =head3 dir_target | ||||
| 820 | |||||
| 821 | my $make_frag = $mm->dir_target(@directories); | ||||
| 822 | |||||
| 823 | Generates targets to create the specified directories and set its | ||||
| 824 | permission to PERM_DIR. | ||||
| 825 | |||||
| 826 | Because depending on a directory to just ensure it exists doesn't work | ||||
| 827 | too well (the modified time changes too often) dir_target() creates a | ||||
| 828 | .exists file in the created directory. It is this you should depend on. | ||||
| 829 | For portability purposes you should use the $(DIRFILESEP) macro rather | ||||
| 830 | than a '/' to separate the directory from the file. | ||||
| 831 | |||||
| 832 | yourdirectory$(DIRFILESEP).exists | ||||
| 833 | |||||
| 834 | =cut | ||||
| 835 | |||||
| 836 | sub dir_target { | ||||
| 837 | my($self, @dirs) = @_; | ||||
| 838 | |||||
| 839 | my $make = ''; | ||||
| 840 | foreach my $dir (@dirs) { | ||||
| 841 | $make .= sprintf <<'MAKE', ($dir) x 4; | ||||
| 842 | %s$(DFSEP).exists :: Makefile.PL | ||||
| 843 | $(NOECHO) $(MKPATH) %s | ||||
| 844 | $(NOECHO) $(CHMOD) $(PERM_DIR) %s | ||||
| 845 | $(NOECHO) $(TOUCH) %s$(DFSEP).exists | ||||
| 846 | |||||
| 847 | MAKE | ||||
| 848 | |||||
| 849 | } | ||||
| 850 | |||||
| 851 | return $make; | ||||
| 852 | } | ||||
| 853 | |||||
| 854 | |||||
| 855 | =head3 distdir | ||||
| 856 | |||||
| 857 | Defines the scratch directory target that will hold the distribution | ||||
| 858 | before tar-ing (or shar-ing). | ||||
| 859 | |||||
| 860 | =cut | ||||
| 861 | |||||
| 862 | # For backwards compatibility. | ||||
| 863 | 1 | 1µs | *dist_dir = *distdir; | ||
| 864 | |||||
| 865 | sub distdir { | ||||
| 866 | my($self) = shift; | ||||
| 867 | |||||
| 868 | my $meta_target = $self->{NO_META} ? '' : 'distmeta'; | ||||
| 869 | my $sign_target = !$self->{SIGN} ? '' : 'distsignature'; | ||||
| 870 | |||||
| 871 | return sprintf <<'MAKE_FRAG', $meta_target, $sign_target; | ||||
| 872 | create_distdir : | ||||
| 873 | $(RM_RF) $(DISTVNAME) | ||||
| 874 | $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \ | ||||
| 875 | -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');" | ||||
| 876 | |||||
| 877 | distdir : create_distdir %s %s | ||||
| 878 | $(NOECHO) $(NOOP) | ||||
| 879 | |||||
| 880 | MAKE_FRAG | ||||
| 881 | |||||
| 882 | } | ||||
| 883 | |||||
| 884 | |||||
| 885 | =head3 dist_test | ||||
| 886 | |||||
| 887 | Defines a target that produces the distribution in the | ||||
| 888 | scratch directory, and runs 'perl Makefile.PL; make ;make test' in that | ||||
| 889 | subdirectory. | ||||
| 890 | |||||
| 891 | =cut | ||||
| 892 | |||||
| 893 | sub dist_test { | ||||
| 894 | my($self) = shift; | ||||
| 895 | |||||
| 896 | my $mpl_args = join " ", map qq["$_"], @ARGV; | ||||
| 897 | |||||
| 898 | my $test = $self->cd('$(DISTVNAME)', | ||||
| 899 | '$(ABSPERLRUN) Makefile.PL '.$mpl_args, | ||||
| 900 | '$(MAKE) $(PASTHRU)', | ||||
| 901 | '$(MAKE) test $(PASTHRU)' | ||||
| 902 | ); | ||||
| 903 | |||||
| 904 | return sprintf <<'MAKE_FRAG', $test; | ||||
| 905 | disttest : distdir | ||||
| 906 | %s | ||||
| 907 | |||||
| 908 | MAKE_FRAG | ||||
| 909 | |||||
| 910 | |||||
| 911 | } | ||||
| 912 | |||||
| 913 | |||||
| 914 | =head3 xs_dlsyms_arg | ||||
| 915 | |||||
| 916 | Returns command-line arg(s) to linker for file listing dlsyms to export. | ||||
| 917 | Defaults to returning empty string, can be overridden by e.g. AIX. | ||||
| 918 | |||||
| 919 | =cut | ||||
| 920 | |||||
| 921 | sub xs_dlsyms_arg { | ||||
| 922 | return ''; | ||||
| 923 | } | ||||
| 924 | |||||
| 925 | =head3 xs_dlsyms_ext | ||||
| 926 | |||||
| 927 | Returns file-extension for C<xs_make_dlsyms> method's output file, | ||||
| 928 | including any "." character. | ||||
| 929 | |||||
| 930 | =cut | ||||
| 931 | |||||
| 932 | sub xs_dlsyms_ext { | ||||
| 933 | die "Pure virtual method"; | ||||
| 934 | } | ||||
| 935 | |||||
| 936 | =head3 xs_dlsyms_extra | ||||
| 937 | |||||
| 938 | Returns any extra text to be prepended to the C<$extra> argument of | ||||
| 939 | C<xs_make_dlsyms>. | ||||
| 940 | |||||
| 941 | =cut | ||||
| 942 | |||||
| 943 | sub xs_dlsyms_extra { | ||||
| 944 | ''; | ||||
| 945 | } | ||||
| 946 | |||||
| 947 | =head3 xs_dlsyms_iterator | ||||
| 948 | |||||
| 949 | Iterates over necessary shared objects, calling C<xs_make_dlsyms> method | ||||
| 950 | for each with appropriate arguments. | ||||
| 951 | |||||
| 952 | =cut | ||||
| 953 | |||||
| 954 | sub xs_dlsyms_iterator { | ||||
| 955 | my ($self, $attribs) = @_; | ||||
| 956 | if ($self->{XSMULTI}) { | ||||
| 957 | my @m; | ||||
| 958 | for my $ext ($self->_xs_list_basenames) { | ||||
| 959 | my @parts = File::Spec->splitdir($ext); | ||||
| 960 | shift @parts if $parts[0] eq 'lib'; | ||||
| 961 | my $name = join '::', @parts; | ||||
| 962 | push @m, $self->xs_make_dlsyms( | ||||
| 963 | $attribs, | ||||
| 964 | $ext . $self->xs_dlsyms_ext, | ||||
| 965 | "$ext.xs", | ||||
| 966 | $name, | ||||
| 967 | $parts[-1], | ||||
| 968 | {}, [], {}, [], | ||||
| 969 | $self->xs_dlsyms_extra . q!, 'FILE' => ! . neatvalue($ext), | ||||
| 970 | ); | ||||
| 971 | } | ||||
| 972 | return join "\n", @m; | ||||
| 973 | } else { | ||||
| 974 | return $self->xs_make_dlsyms( | ||||
| 975 | $attribs, | ||||
| 976 | $self->{BASEEXT} . $self->xs_dlsyms_ext, | ||||
| 977 | 'Makefile.PL', | ||||
| 978 | $self->{NAME}, | ||||
| 979 | $self->{DLBASE}, | ||||
| 980 | $attribs->{DL_FUNCS} || $self->{DL_FUNCS} || {}, | ||||
| 981 | $attribs->{FUNCLIST} || $self->{FUNCLIST} || [], | ||||
| 982 | $attribs->{IMPORTS} || $self->{IMPORTS} || {}, | ||||
| 983 | $attribs->{DL_VARS} || $self->{DL_VARS} || [], | ||||
| 984 | $self->xs_dlsyms_extra, | ||||
| 985 | ); | ||||
| 986 | } | ||||
| 987 | } | ||||
| 988 | |||||
| 989 | =head3 xs_make_dlsyms | ||||
| 990 | |||||
| 991 | $self->xs_make_dlsyms( | ||||
| 992 | \%attribs, # hashref from %attribs in caller | ||||
| 993 | "$self->{BASEEXT}.def", # output file for Makefile target | ||||
| 994 | 'Makefile.PL', # dependency | ||||
| 995 | $self->{NAME}, # shared object's "name" | ||||
| 996 | $self->{DLBASE}, # last ::-separated part of name | ||||
| 997 | $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {}, # various params | ||||
| 998 | $attribs{FUNCLIST} || $self->{FUNCLIST} || [], | ||||
| 999 | $attribs{IMPORTS} || $self->{IMPORTS} || {}, | ||||
| 1000 | $attribs{DL_VARS} || $self->{DL_VARS} || [], | ||||
| 1001 | # optional extra param that will be added as param to Mksymlists | ||||
| 1002 | ); | ||||
| 1003 | |||||
| 1004 | Utility method that returns Makefile snippet to call C<Mksymlists>. | ||||
| 1005 | |||||
| 1006 | =cut | ||||
| 1007 | |||||
| 1008 | sub xs_make_dlsyms { | ||||
| 1009 | my ($self, $attribs, $target, $dep, $name, $dlbase, $funcs, $funclist, $imports, $vars, $extra) = @_; | ||||
| 1010 | my @m = ( | ||||
| 1011 | "\n$target: $dep\n", | ||||
| 1012 | q! $(PERLRUN) -MExtUtils::Mksymlists \\ | ||||
| 1013 | -e "Mksymlists('NAME'=>\"!, $name, | ||||
| 1014 | q!\", 'DLBASE' => '!,$dlbase, | ||||
| 1015 | # The above two lines quoted differently to work around | ||||
| 1016 | # a bug in the 4DOS/4NT command line interpreter. The visible | ||||
| 1017 | # result of the bug was files named q('extension_name',) *with the | ||||
| 1018 | # single quotes and the comma* in the extension build directories. | ||||
| 1019 | q!', 'DL_FUNCS' => !,neatvalue($funcs), | ||||
| 1020 | q!, 'FUNCLIST' => !,neatvalue($funclist), | ||||
| 1021 | q!, 'IMPORTS' => !,neatvalue($imports), | ||||
| 1022 | q!, 'DL_VARS' => !, neatvalue($vars) | ||||
| 1023 | ); | ||||
| 1024 | push @m, $extra if defined $extra; | ||||
| 1025 | push @m, qq!);"\n!; | ||||
| 1026 | join '', @m; | ||||
| 1027 | } | ||||
| 1028 | |||||
| 1029 | =head3 dynamic (o) | ||||
| 1030 | |||||
| 1031 | Defines the dynamic target. | ||||
| 1032 | |||||
| 1033 | =cut | ||||
| 1034 | |||||
| 1035 | sub dynamic { | ||||
| 1036 | # --- Dynamic Loading Sections --- | ||||
| 1037 | |||||
| 1038 | my($self) = shift; | ||||
| 1039 | ' | ||||
| 1040 | dynamic :: $(FIRST_MAKEFILE) config $(INST_BOOT) $(INST_DYNAMIC) | ||||
| 1041 | $(NOECHO) $(NOOP) | ||||
| 1042 | '; | ||||
| 1043 | } | ||||
| 1044 | |||||
| 1045 | |||||
| 1046 | =head3 makemakerdflt_target | ||||
| 1047 | |||||
| 1048 | my $make_frag = $mm->makemakerdflt_target | ||||
| 1049 | |||||
| 1050 | Returns a make fragment with the makemakerdeflt_target specified. | ||||
| 1051 | This target is the first target in the Makefile, is the default target | ||||
| 1052 | and simply points off to 'all' just in case any make variant gets | ||||
| 1053 | confused or something gets snuck in before the real 'all' target. | ||||
| 1054 | |||||
| 1055 | =cut | ||||
| 1056 | |||||
| 1057 | sub makemakerdflt_target { | ||||
| 1058 | return <<'MAKE_FRAG'; | ||||
| 1059 | makemakerdflt : all | ||||
| 1060 | $(NOECHO) $(NOOP) | ||||
| 1061 | MAKE_FRAG | ||||
| 1062 | |||||
| 1063 | } | ||||
| 1064 | |||||
| 1065 | |||||
| 1066 | =head3 manifypods_target | ||||
| 1067 | |||||
| 1068 | my $manifypods_target = $self->manifypods_target; | ||||
| 1069 | |||||
| 1070 | Generates the manifypods target. This target generates man pages from | ||||
| 1071 | all POD files in MAN1PODS and MAN3PODS. | ||||
| 1072 | |||||
| 1073 | =cut | ||||
| 1074 | |||||
| 1075 | sub manifypods_target { | ||||
| 1076 | my($self) = shift; | ||||
| 1077 | |||||
| 1078 | my $man1pods = ''; | ||||
| 1079 | my $man3pods = ''; | ||||
| 1080 | my $dependencies = ''; | ||||
| 1081 | |||||
| 1082 | # populate manXpods & dependencies: | ||||
| 1083 | foreach my $name (sort keys %{$self->{MAN1PODS}}, sort keys %{$self->{MAN3PODS}}) { | ||||
| 1084 | $dependencies .= " \\\n\t$name"; | ||||
| 1085 | } | ||||
| 1086 | |||||
| 1087 | my $manify = <<END; | ||||
| 1088 | manifypods : pure_all config $dependencies | ||||
| 1089 | END | ||||
| 1090 | |||||
| 1091 | my @man_cmds; | ||||
| 1092 | foreach my $num (qw(1 3)) { | ||||
| 1093 | my $pods = $self->{"MAN${num}PODS"}; | ||||
| 1094 | my $p2m = sprintf <<'CMD', "\$(MAN${num}EXT)", "$]" > 5.008 ? " -u" : ""; | ||||
| 1095 | $(NOECHO) $(POD2MAN) --section=%s --perm_rw=$(PERM_RW)%s | ||||
| 1096 | CMD | ||||
| 1097 | push @man_cmds, $self->split_command($p2m, map {($_,$pods->{$_})} sort keys %$pods); | ||||
| 1098 | } | ||||
| 1099 | |||||
| 1100 | $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds; | ||||
| 1101 | $manify .= join '', map { "$_\n" } @man_cmds; | ||||
| 1102 | |||||
| 1103 | return $manify; | ||||
| 1104 | } | ||||
| 1105 | |||||
| 1106 | { | ||||
| 1107 | 1 | 200ns | my $has_cpan_meta; | ||
| 1108 | sub _has_cpan_meta { | ||||
| 1109 | return $has_cpan_meta if defined $has_cpan_meta; | ||||
| 1110 | return $has_cpan_meta = !!eval { | ||||
| 1111 | require CPAN::Meta; | ||||
| 1112 | CPAN::Meta->VERSION(2.112150); | ||||
| 1113 | 1; | ||||
| 1114 | }; | ||||
| 1115 | } | ||||
| 1116 | } | ||||
| 1117 | |||||
| 1118 | =head3 metafile_target | ||||
| 1119 | |||||
| 1120 | my $target = $mm->metafile_target; | ||||
| 1121 | |||||
| 1122 | Generate the metafile target. | ||||
| 1123 | |||||
| 1124 | Writes the file META.yml (YAML encoded meta-data) and META.json | ||||
| 1125 | (JSON encoded meta-data) about the module in the distdir. | ||||
| 1126 | The format follows Module::Build's as closely as possible. | ||||
| 1127 | |||||
| 1128 | =cut | ||||
| 1129 | |||||
| 1130 | 1 | 300ns | sub metafile_target { | ||
| 1131 | my $self = shift; | ||||
| 1132 | return <<'MAKE_FRAG' if $self->{NO_META} or ! _has_cpan_meta(); | ||||
| 1133 | metafile : | ||||
| 1134 | $(NOECHO) $(NOOP) | ||||
| 1135 | MAKE_FRAG | ||||
| 1136 | |||||
| 1137 | my $metadata = $self->metafile_data( | ||||
| 1138 | $self->{META_ADD} || {}, | ||||
| 1139 | $self->{META_MERGE} || {}, | ||||
| 1140 | ); | ||||
| 1141 | |||||
| 1142 | my $meta = $self->_fix_metadata_before_conversion( $metadata ); | ||||
| 1143 | |||||
| 1144 | my @write_metayml = $self->stashmeta( | ||||
| 1145 | $meta->as_string({version => "1.4"}), 'META_new.yml' | ||||
| 1146 | ); | ||||
| 1147 | my @write_metajson = $self->stashmeta( | ||||
| 1148 | $meta->as_string({version => "2.0"}), 'META_new.json' | ||||
| 1149 | ); | ||||
| 1150 | |||||
| 1151 | my $metayml = join("\n\t", @write_metayml); | ||||
| 1152 | my $metajson = join("\n\t", @write_metajson); | ||||
| 1153 | return sprintf <<'MAKE_FRAG', $metayml, $metajson; | ||||
| 1154 | metafile : create_distdir | ||||
| 1155 | $(NOECHO) $(ECHO) Generating META.yml | ||||
| 1156 | %s | ||||
| 1157 | -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml | ||||
| 1158 | $(NOECHO) $(ECHO) Generating META.json | ||||
| 1159 | %s | ||||
| 1160 | -$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json | ||||
| 1161 | MAKE_FRAG | ||||
| 1162 | |||||
| 1163 | } | ||||
| 1164 | |||||
| 1165 | =begin private | ||||
| 1166 | |||||
| 1167 | =head3 _fix_metadata_before_conversion | ||||
| 1168 | |||||
| 1169 | $mm->_fix_metadata_before_conversion( \%metadata ); | ||||
| 1170 | |||||
| 1171 | Fixes errors in the metadata before it's handed off to L<CPAN::Meta> for | ||||
| 1172 | conversion. This hopefully results in something that can be used further | ||||
| 1173 | on, no guarantee is made though. | ||||
| 1174 | |||||
| 1175 | =end private | ||||
| 1176 | |||||
| 1177 | =cut | ||||
| 1178 | |||||
| 1179 | sub _fix_metadata_before_conversion { | ||||
| 1180 | my ( $self, $metadata ) = @_; | ||||
| 1181 | |||||
| 1182 | # we should never be called unless this already passed but | ||||
| 1183 | # prefer to be defensive in case somebody else calls this | ||||
| 1184 | |||||
| 1185 | return unless _has_cpan_meta; | ||||
| 1186 | |||||
| 1187 | my $bad_version = $metadata->{version} && | ||||
| 1188 | !CPAN::Meta::Validator->new->version( 'version', $metadata->{version} ); | ||||
| 1189 | # just delete all invalid versions | ||||
| 1190 | if( $bad_version ) { | ||||
| 1191 | warn "Can't parse version '$metadata->{version}'\n"; | ||||
| 1192 | $metadata->{version} = ''; | ||||
| 1193 | } | ||||
| 1194 | |||||
| 1195 | my $validator2 = CPAN::Meta::Validator->new( $metadata ); | ||||
| 1196 | my @errors; | ||||
| 1197 | push @errors, $validator2->errors if !$validator2->is_valid; | ||||
| 1198 | my $validator14 = CPAN::Meta::Validator->new( | ||||
| 1199 | { | ||||
| 1200 | %$metadata, | ||||
| 1201 | 'meta-spec' => { version => 1.4 }, | ||||
| 1202 | } | ||||
| 1203 | ); | ||||
| 1204 | push @errors, $validator14->errors if !$validator14->is_valid; | ||||
| 1205 | # fix non-camelcase custom resource keys (only other trick we know) | ||||
| 1206 | for my $error ( @errors ) { | ||||
| 1207 | my ( $key ) = ( $error =~ /Custom resource '(.*)' must be in CamelCase./ ); | ||||
| 1208 | next if !$key; | ||||
| 1209 | |||||
| 1210 | # first try to remove all non-alphabetic chars | ||||
| 1211 | ( my $new_key = $key ) =~ s/[^_a-zA-Z]//g; | ||||
| 1212 | |||||
| 1213 | # if that doesn't work, uppercase first one | ||||
| 1214 | $new_key = ucfirst $new_key if !$validator14->custom_1( $new_key ); | ||||
| 1215 | |||||
| 1216 | # copy to new key if that worked | ||||
| 1217 | $metadata->{resources}{$new_key} = $metadata->{resources}{$key} | ||||
| 1218 | if $validator14->custom_1( $new_key ); | ||||
| 1219 | |||||
| 1220 | # and delete old one in any case | ||||
| 1221 | delete $metadata->{resources}{$key}; | ||||
| 1222 | } | ||||
| 1223 | |||||
| 1224 | # paper over validation issues, but still complain, necessary because | ||||
| 1225 | # there's no guarantee that the above will fix ALL errors | ||||
| 1226 | my $meta = eval { CPAN::Meta->create( $metadata, { lazy_validation => 1 } ) }; | ||||
| 1227 | warn $@ if $@ and | ||||
| 1228 | $@ !~ /encountered CODE.*, but JSON can only represent references to arrays or hashes/; | ||||
| 1229 | |||||
| 1230 | # use the original metadata straight if the conversion failed | ||||
| 1231 | # or if it can't be stringified. | ||||
| 1232 | if( !$meta || | ||||
| 1233 | !eval { $meta->as_string( { version => $METASPEC_V } ) } || | ||||
| 1234 | !eval { $meta->as_string } | ||||
| 1235 | ) { | ||||
| 1236 | $meta = bless $metadata, 'CPAN::Meta'; | ||||
| 1237 | } | ||||
| 1238 | |||||
| 1239 | my $now_license = $meta->as_struct({ version => 2 })->{license}; | ||||
| 1240 | if ($self->{LICENSE} and $self->{LICENSE} ne 'unknown' and | ||||
| 1241 | @{$now_license} == 1 and $now_license->[0] eq 'unknown' | ||||
| 1242 | ) { | ||||
| 1243 | warn "Invalid LICENSE value '$self->{LICENSE}' ignored\n"; | ||||
| 1244 | } | ||||
| 1245 | |||||
| 1246 | $meta; | ||||
| 1247 | } | ||||
| 1248 | |||||
| 1249 | |||||
| 1250 | =begin private | ||||
| 1251 | |||||
| 1252 | =head3 _sort_pairs | ||||
| 1253 | |||||
| 1254 | my @pairs = _sort_pairs($sort_sub, \%hash); | ||||
| 1255 | |||||
| 1256 | Sorts the pairs of a hash based on keys ordered according | ||||
| 1257 | to C<$sort_sub>. | ||||
| 1258 | |||||
| 1259 | =end private | ||||
| 1260 | |||||
| 1261 | =cut | ||||
| 1262 | |||||
| 1263 | sub _sort_pairs { | ||||
| 1264 | my $sort = shift; | ||||
| 1265 | my $pairs = shift; | ||||
| 1266 | return map { $_ => $pairs->{$_} } | ||||
| 1267 | sort $sort | ||||
| 1268 | keys %$pairs; | ||||
| 1269 | } | ||||
| 1270 | |||||
| 1271 | |||||
| 1272 | # Taken from Module::Build::Base | ||||
| 1273 | sub _hash_merge { | ||||
| 1274 | my ($self, $h, $k, $v) = @_; | ||||
| 1275 | if (ref $h->{$k} eq 'ARRAY') { | ||||
| 1276 | push @{$h->{$k}}, ref $v ? @$v : $v; | ||||
| 1277 | } elsif (ref $h->{$k} eq 'HASH') { | ||||
| 1278 | $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v; | ||||
| 1279 | } else { | ||||
| 1280 | $h->{$k} = $v; | ||||
| 1281 | } | ||||
| 1282 | } | ||||
| 1283 | |||||
| 1284 | |||||
| 1285 | =head3 metafile_data | ||||
| 1286 | |||||
| 1287 | my $metadata_hashref = $mm->metafile_data(\%meta_add, \%meta_merge); | ||||
| 1288 | |||||
| 1289 | Returns the data which MakeMaker turns into the META.yml file | ||||
| 1290 | and the META.json file. It is always in version 2.0 of the format. | ||||
| 1291 | |||||
| 1292 | Values of %meta_add will overwrite any existing metadata in those | ||||
| 1293 | keys. %meta_merge will be merged with them. | ||||
| 1294 | |||||
| 1295 | =cut | ||||
| 1296 | |||||
| 1297 | sub metafile_data { | ||||
| 1298 | my $self = shift; | ||||
| 1299 | my($meta_add, $meta_merge) = @_; | ||||
| 1300 | |||||
| 1301 | $meta_add ||= {}; | ||||
| 1302 | $meta_merge ||= {}; | ||||
| 1303 | |||||
| 1304 | my $version = _normalize_version($self->{VERSION}); | ||||
| 1305 | my $release_status = ($version =~ /_/) ? 'unstable' : 'stable'; | ||||
| 1306 | my %meta = ( | ||||
| 1307 | # required | ||||
| 1308 | abstract => $self->{ABSTRACT} || 'unknown', | ||||
| 1309 | author => defined($self->{AUTHOR}) ? $self->{AUTHOR} : ['unknown'], | ||||
| 1310 | dynamic_config => 1, | ||||
| 1311 | generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION", | ||||
| 1312 | license => [ $self->{LICENSE} || 'unknown' ], | ||||
| 1313 | 'meta-spec' => { | ||||
| 1314 | url => $METASPEC_URL, | ||||
| 1315 | version => $METASPEC_V, | ||||
| 1316 | }, | ||||
| 1317 | name => $self->{DISTNAME}, | ||||
| 1318 | release_status => $release_status, | ||||
| 1319 | version => $version, | ||||
| 1320 | |||||
| 1321 | # optional | ||||
| 1322 | no_index => { directory => [qw(t inc)] }, | ||||
| 1323 | ); | ||||
| 1324 | $self->_add_requirements_to_meta(\%meta); | ||||
| 1325 | |||||
| 1326 | if (!eval { require JSON::PP; require CPAN::Meta::Converter; CPAN::Meta::Converter->VERSION(2.141170) }) { | ||||
| 1327 | return \%meta; | ||||
| 1328 | } | ||||
| 1329 | |||||
| 1330 | # needs to be based on the original version | ||||
| 1331 | my $v1_add = _metaspec_version($meta_add) !~ /^2/; | ||||
| 1332 | |||||
| 1333 | my ($add_v, $merge_v) = map _metaspec_version($_), $meta_add, $meta_merge; | ||||
| 1334 | for my $frag ($meta_add, $meta_merge) { | ||||
| 1335 | my $def_v = $frag == $meta_add ? $merge_v : $add_v; | ||||
| 1336 | $frag = CPAN::Meta::Converter->new($frag, default_version => $def_v)->upgrade_fragment; | ||||
| 1337 | } | ||||
| 1338 | |||||
| 1339 | # if we upgraded a 1.x _ADD fragment, we gave it a prereqs key that | ||||
| 1340 | # will override all prereqs, which is more than the user asked for; | ||||
| 1341 | # instead, we'll go inside the prereqs and override all those | ||||
| 1342 | while( my($key, $val) = each %$meta_add ) { | ||||
| 1343 | if ($v1_add and $key eq 'prereqs') { | ||||
| 1344 | $meta{$key}{$_} = $val->{$_} for keys %$val; | ||||
| 1345 | } elsif ($key ne 'meta-spec') { | ||||
| 1346 | $meta{$key} = $val; | ||||
| 1347 | } | ||||
| 1348 | } | ||||
| 1349 | |||||
| 1350 | while( my($key, $val) = each %$meta_merge ) { | ||||
| 1351 | next if $key eq 'meta-spec'; | ||||
| 1352 | $self->_hash_merge(\%meta, $key, $val); | ||||
| 1353 | } | ||||
| 1354 | |||||
| 1355 | return \%meta; | ||||
| 1356 | } | ||||
| 1357 | |||||
| 1358 | |||||
| 1359 | =begin private | ||||
| 1360 | |||||
| 1361 | =cut | ||||
| 1362 | |||||
| 1363 | sub _add_requirements_to_meta { | ||||
| 1364 | my ( $self, $meta ) = @_; | ||||
| 1365 | # Check the original args so we can tell between the user setting it | ||||
| 1366 | # to an empty hash and it just being initialized. | ||||
| 1367 | $meta->{prereqs}{configure}{requires} = $self->{ARGS}{CONFIGURE_REQUIRES} | ||||
| 1368 | ? $self->{CONFIGURE_REQUIRES} | ||||
| 1369 | : { 'ExtUtils::MakeMaker' => 0, }; | ||||
| 1370 | $meta->{prereqs}{build}{requires} = $self->{ARGS}{BUILD_REQUIRES} | ||||
| 1371 | ? $self->{BUILD_REQUIRES} | ||||
| 1372 | : { 'ExtUtils::MakeMaker' => 0, }; | ||||
| 1373 | $meta->{prereqs}{test}{requires} = $self->{TEST_REQUIRES} | ||||
| 1374 | if $self->{ARGS}{TEST_REQUIRES}; | ||||
| 1375 | $meta->{prereqs}{runtime}{requires} = $self->{PREREQ_PM} | ||||
| 1376 | if $self->{ARGS}{PREREQ_PM}; | ||||
| 1377 | $meta->{prereqs}{runtime}{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION}) | ||||
| 1378 | if $self->{MIN_PERL_VERSION}; | ||||
| 1379 | } | ||||
| 1380 | |||||
| 1381 | # spec version of given fragment - if not given, assume 1.4 | ||||
| 1382 | sub _metaspec_version { | ||||
| 1383 | my ( $meta ) = @_; | ||||
| 1384 | return $meta->{'meta-spec'}->{version} | ||||
| 1385 | if defined $meta->{'meta-spec'} | ||||
| 1386 | and defined $meta->{'meta-spec'}->{version}; | ||||
| 1387 | return '1.4'; | ||||
| 1388 | } | ||||
| 1389 | |||||
| 1390 | sub _add_requirements_to_meta_v1_4 { | ||||
| 1391 | my ( $self, $meta ) = @_; | ||||
| 1392 | # Check the original args so we can tell between the user setting it | ||||
| 1393 | # to an empty hash and it just being initialized. | ||||
| 1394 | if( $self->{ARGS}{CONFIGURE_REQUIRES} ) { | ||||
| 1395 | $meta->{configure_requires} = $self->{CONFIGURE_REQUIRES}; | ||||
| 1396 | } else { | ||||
| 1397 | $meta->{configure_requires} = { | ||||
| 1398 | 'ExtUtils::MakeMaker' => 0, | ||||
| 1399 | }; | ||||
| 1400 | } | ||||
| 1401 | if( $self->{ARGS}{BUILD_REQUIRES} ) { | ||||
| 1402 | $meta->{build_requires} = $self->{BUILD_REQUIRES}; | ||||
| 1403 | } else { | ||||
| 1404 | $meta->{build_requires} = { | ||||
| 1405 | 'ExtUtils::MakeMaker' => 0, | ||||
| 1406 | }; | ||||
| 1407 | } | ||||
| 1408 | if( $self->{ARGS}{TEST_REQUIRES} ) { | ||||
| 1409 | $meta->{build_requires} = { | ||||
| 1410 | %{ $meta->{build_requires} }, | ||||
| 1411 | %{ $self->{TEST_REQUIRES} }, | ||||
| 1412 | }; | ||||
| 1413 | } | ||||
| 1414 | $meta->{requires} = $self->{PREREQ_PM} | ||||
| 1415 | if defined $self->{PREREQ_PM}; | ||||
| 1416 | $meta->{requires}{perl} = _normalize_version($self->{MIN_PERL_VERSION}) | ||||
| 1417 | if $self->{MIN_PERL_VERSION}; | ||||
| 1418 | } | ||||
| 1419 | |||||
| 1420 | # Adapted from Module::Build::Base | ||||
| 1421 | sub _normalize_version { | ||||
| 1422 | my ($version) = @_; | ||||
| 1423 | $version = 0 unless defined $version; | ||||
| 1424 | |||||
| 1425 | if ( ref $version eq 'version' ) { # version objects | ||||
| 1426 | $version = $version->stringify; | ||||
| 1427 | } | ||||
| 1428 | elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots | ||||
| 1429 | # normalize string tuples without "v": "1.2.3" -> "v1.2.3" | ||||
| 1430 | $version = "v$version"; | ||||
| 1431 | } | ||||
| 1432 | else { | ||||
| 1433 | # leave alone | ||||
| 1434 | } | ||||
| 1435 | return $version; | ||||
| 1436 | } | ||||
| 1437 | |||||
| 1438 | =head3 _dump_hash | ||||
| 1439 | |||||
| 1440 | $yaml = _dump_hash(\%options, %hash); | ||||
| 1441 | |||||
| 1442 | Implements a fake YAML dumper for a hash given | ||||
| 1443 | as a list of pairs. No quoting/escaping is done. Keys | ||||
| 1444 | are supposed to be strings. Values are undef, strings, | ||||
| 1445 | hash refs or array refs of strings. | ||||
| 1446 | |||||
| 1447 | Supported options are: | ||||
| 1448 | |||||
| 1449 | delta => STR - indentation delta | ||||
| 1450 | use_header => BOOL - whether to include a YAML header | ||||
| 1451 | indent => STR - a string of spaces | ||||
| 1452 | default: '' | ||||
| 1453 | |||||
| 1454 | max_key_length => INT - maximum key length used to align | ||||
| 1455 | keys and values of the same hash | ||||
| 1456 | default: 20 | ||||
| 1457 | key_sort => CODE - a sort sub | ||||
| 1458 | It may be undef, which means no sorting by keys | ||||
| 1459 | default: sub { lc $a cmp lc $b } | ||||
| 1460 | |||||
| 1461 | customs => HASH - special options for certain keys | ||||
| 1462 | (whose values are hashes themselves) | ||||
| 1463 | may contain: max_key_length, key_sort, customs | ||||
| 1464 | |||||
| 1465 | =end private | ||||
| 1466 | |||||
| 1467 | =cut | ||||
| 1468 | |||||
| 1469 | sub _dump_hash { | ||||
| 1470 | croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH'; | ||||
| 1471 | my $options = shift; | ||||
| 1472 | my %hash = @_; | ||||
| 1473 | |||||
| 1474 | # Use a list to preserve order. | ||||
| 1475 | my @pairs; | ||||
| 1476 | |||||
| 1477 | my $k_sort | ||||
| 1478 | = exists $options->{key_sort} ? $options->{key_sort} | ||||
| 1479 | : sub { lc $a cmp lc $b }; | ||||
| 1480 | if ($k_sort) { | ||||
| 1481 | croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE'; | ||||
| 1482 | @pairs = _sort_pairs($k_sort, \%hash); | ||||
| 1483 | } else { # list of pairs, no sorting | ||||
| 1484 | @pairs = @_; | ||||
| 1485 | } | ||||
| 1486 | |||||
| 1487 | my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : ''; | ||||
| 1488 | my $indent = $options->{indent} || ''; | ||||
| 1489 | my $k_length = min( | ||||
| 1490 | ($options->{max_key_length} || 20), | ||||
| 1491 | max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash) | ||||
| 1492 | ); | ||||
| 1493 | my $customs = $options->{customs} || {}; | ||||
| 1494 | |||||
| 1495 | # printf format for key | ||||
| 1496 | my $k_format = "%-${k_length}s"; | ||||
| 1497 | |||||
| 1498 | while( @pairs ) { | ||||
| 1499 | my($key, $val) = splice @pairs, 0, 2; | ||||
| 1500 | $val = '~' unless defined $val; | ||||
| 1501 | if(ref $val eq 'HASH') { | ||||
| 1502 | if ( keys %$val ) { | ||||
| 1503 | my %k_options = ( # options for recursive call | ||||
| 1504 | delta => $options->{delta}, | ||||
| 1505 | use_header => 0, | ||||
| 1506 | indent => $indent . $options->{delta}, | ||||
| 1507 | ); | ||||
| 1508 | if (exists $customs->{$key}) { | ||||
| 1509 | my %k_custom = %{$customs->{$key}}; | ||||
| 1510 | foreach my $k (qw(key_sort max_key_length customs)) { | ||||
| 1511 | $k_options{$k} = $k_custom{$k} if exists $k_custom{$k}; | ||||
| 1512 | } | ||||
| 1513 | } | ||||
| 1514 | $yaml .= $indent . "$key:\n" | ||||
| 1515 | . _dump_hash(\%k_options, %$val); | ||||
| 1516 | } | ||||
| 1517 | else { | ||||
| 1518 | $yaml .= $indent . "$key: {}\n"; | ||||
| 1519 | } | ||||
| 1520 | } | ||||
| 1521 | elsif (ref $val eq 'ARRAY') { | ||||
| 1522 | if( @$val ) { | ||||
| 1523 | $yaml .= $indent . "$key:\n"; | ||||
| 1524 | |||||
| 1525 | for (@$val) { | ||||
| 1526 | croak "only nested arrays of non-refs are supported" if ref $_; | ||||
| 1527 | $yaml .= $indent . $options->{delta} . "- $_\n"; | ||||
| 1528 | } | ||||
| 1529 | } | ||||
| 1530 | else { | ||||
| 1531 | $yaml .= $indent . "$key: []\n"; | ||||
| 1532 | } | ||||
| 1533 | } | ||||
| 1534 | elsif( ref $val and !blessed($val) ) { | ||||
| 1535 | croak "only nested hashes, arrays and objects are supported"; | ||||
| 1536 | } | ||||
| 1537 | else { # if it's an object, just stringify it | ||||
| 1538 | $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val; | ||||
| 1539 | } | ||||
| 1540 | }; | ||||
| 1541 | |||||
| 1542 | return $yaml; | ||||
| 1543 | |||||
| 1544 | } | ||||
| 1545 | |||||
| 1546 | sub blessed { | ||||
| 1547 | return eval { $_[0]->isa("UNIVERSAL"); }; | ||||
| 1548 | } | ||||
| 1549 | |||||
| 1550 | sub max { | ||||
| 1551 | return (sort { $b <=> $a } @_)[0]; | ||||
| 1552 | } | ||||
| 1553 | |||||
| 1554 | sub min { | ||||
| 1555 | return (sort { $a <=> $b } @_)[0]; | ||||
| 1556 | } | ||||
| 1557 | |||||
| 1558 | =head3 metafile_file | ||||
| 1559 | |||||
| 1560 | my $meta_yml = $mm->metafile_file(@metadata_pairs); | ||||
| 1561 | |||||
| 1562 | Turns the @metadata_pairs into YAML. | ||||
| 1563 | |||||
| 1564 | This method does not implement a complete YAML dumper, being limited | ||||
| 1565 | to dump a hash with values which are strings, undef's or nested hashes | ||||
| 1566 | and arrays of strings. No quoting/escaping is done. | ||||
| 1567 | |||||
| 1568 | =cut | ||||
| 1569 | |||||
| 1570 | sub metafile_file { | ||||
| 1571 | my $self = shift; | ||||
| 1572 | |||||
| 1573 | my %dump_options = ( | ||||
| 1574 | use_header => 1, | ||||
| 1575 | delta => ' ' x 4, | ||||
| 1576 | key_sort => undef, | ||||
| 1577 | ); | ||||
| 1578 | return _dump_hash(\%dump_options, @_); | ||||
| 1579 | |||||
| 1580 | } | ||||
| 1581 | |||||
| 1582 | |||||
| 1583 | =head3 distmeta_target | ||||
| 1584 | |||||
| 1585 | my $make_frag = $mm->distmeta_target; | ||||
| 1586 | |||||
| 1587 | Generates the distmeta target to add META.yml and META.json to the MANIFEST | ||||
| 1588 | in the distdir. | ||||
| 1589 | |||||
| 1590 | =cut | ||||
| 1591 | |||||
| 1592 | sub distmeta_target { | ||||
| 1593 | my $self = shift; | ||||
| 1594 | |||||
| 1595 | my @add_meta = ( | ||||
| 1596 | $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']), | ||||
| 1597 | exit unless -e q{META.yml}; | ||||
| 1598 | eval { maniadd({q{META.yml} => q{Module YAML meta-data (added by MakeMaker)}}) } | ||||
| 1599 | or die "Could not add META.yml to MANIFEST: ${'@'}" | ||||
| 1600 | CODE | ||||
| 1601 | $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']) | ||||
| 1602 | exit unless -f q{META.json}; | ||||
| 1603 | eval { maniadd({q{META.json} => q{Module JSON meta-data (added by MakeMaker)}}) } | ||||
| 1604 | or die "Could not add META.json to MANIFEST: ${'@'}" | ||||
| 1605 | CODE | ||||
| 1606 | ); | ||||
| 1607 | |||||
| 1608 | my @add_meta_to_distdir = map { $self->cd('$(DISTVNAME)', $_) } @add_meta; | ||||
| 1609 | |||||
| 1610 | return sprintf <<'MAKE', @add_meta_to_distdir; | ||||
| 1611 | distmeta : create_distdir metafile | ||||
| 1612 | $(NOECHO) %s | ||||
| 1613 | $(NOECHO) %s | ||||
| 1614 | |||||
| 1615 | MAKE | ||||
| 1616 | |||||
| 1617 | } | ||||
| 1618 | |||||
| 1619 | |||||
| 1620 | =head3 mymeta | ||||
| 1621 | |||||
| 1622 | my $mymeta = $mm->mymeta; | ||||
| 1623 | |||||
| 1624 | Generate MYMETA information as a hash either from an existing CPAN Meta file | ||||
| 1625 | (META.json or META.yml) or from internal data. | ||||
| 1626 | |||||
| 1627 | =cut | ||||
| 1628 | |||||
| 1629 | sub mymeta { | ||||
| 1630 | my $self = shift; | ||||
| 1631 | my $file = shift || ''; # for testing | ||||
| 1632 | |||||
| 1633 | my $mymeta = $self->_mymeta_from_meta($file); | ||||
| 1634 | my $v2 = 1; | ||||
| 1635 | |||||
| 1636 | unless ( $mymeta ) { | ||||
| 1637 | $mymeta = $self->metafile_data( | ||||
| 1638 | $self->{META_ADD} || {}, | ||||
| 1639 | $self->{META_MERGE} || {}, | ||||
| 1640 | ); | ||||
| 1641 | $v2 = 0; | ||||
| 1642 | } | ||||
| 1643 | |||||
| 1644 | # Overwrite the non-configure dependency hashes | ||||
| 1645 | $self->_add_requirements_to_meta($mymeta); | ||||
| 1646 | |||||
| 1647 | $mymeta->{dynamic_config} = 0; | ||||
| 1648 | |||||
| 1649 | return $mymeta; | ||||
| 1650 | } | ||||
| 1651 | |||||
| 1652 | |||||
| 1653 | sub _mymeta_from_meta { | ||||
| 1654 | my $self = shift; | ||||
| 1655 | my $metafile = shift || ''; # for testing | ||||
| 1656 | |||||
| 1657 | return unless _has_cpan_meta(); | ||||
| 1658 | |||||
| 1659 | my $meta; | ||||
| 1660 | for my $file ( $metafile, "META.json", "META.yml" ) { | ||||
| 1661 | next unless -e $file; | ||||
| 1662 | eval { | ||||
| 1663 | $meta = CPAN::Meta->load_file($file)->as_struct( { version => 2 } ); | ||||
| 1664 | }; | ||||
| 1665 | last if $meta; | ||||
| 1666 | } | ||||
| 1667 | return unless $meta; | ||||
| 1668 | |||||
| 1669 | # META.yml before 6.25_01 cannot be trusted. META.yml lived in the source directory. | ||||
| 1670 | # There was a good chance the author accidentally uploaded a stale META.yml if they | ||||
| 1671 | # rolled their own tarball rather than using "make dist". | ||||
| 1672 | if ($meta->{generated_by} && | ||||
| 1673 | $meta->{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) { | ||||
| 1674 | 2 | 2.95ms | 2 | 47µs | # spent 27µs (8+20) within ExtUtils::MM_Any::BEGIN@1674 which was called:
# once (8µs+20µs) by IPC::Cmd::can_run at line 1674 # spent 27µs making 1 call to ExtUtils::MM_Any::BEGIN@1674
# spent 20µs making 1 call to warnings::unimport |
| 1675 | if ($eummv < 6.2501) { | ||||
| 1676 | return; | ||||
| 1677 | } | ||||
| 1678 | } | ||||
| 1679 | |||||
| 1680 | return $meta; | ||||
| 1681 | } | ||||
| 1682 | |||||
| 1683 | =head3 write_mymeta | ||||
| 1684 | |||||
| 1685 | $self->write_mymeta( $mymeta ); | ||||
| 1686 | |||||
| 1687 | Write MYMETA information to MYMETA.json and MYMETA.yml. | ||||
| 1688 | |||||
| 1689 | =cut | ||||
| 1690 | |||||
| 1691 | sub write_mymeta { | ||||
| 1692 | my $self = shift; | ||||
| 1693 | my $mymeta = shift; | ||||
| 1694 | |||||
| 1695 | return unless _has_cpan_meta(); | ||||
| 1696 | |||||
| 1697 | my $meta_obj = $self->_fix_metadata_before_conversion( $mymeta ); | ||||
| 1698 | |||||
| 1699 | $meta_obj->save( 'MYMETA.json', { version => "2.0" } ); | ||||
| 1700 | $meta_obj->save( 'MYMETA.yml', { version => "1.4" } ); | ||||
| 1701 | return 1; | ||||
| 1702 | } | ||||
| 1703 | |||||
| 1704 | =head3 realclean (o) | ||||
| 1705 | |||||
| 1706 | Defines the realclean target. | ||||
| 1707 | |||||
| 1708 | =cut | ||||
| 1709 | |||||
| 1710 | sub realclean { | ||||
| 1711 | my($self, %attribs) = @_; | ||||
| 1712 | |||||
| 1713 | my @dirs = qw($(DISTVNAME)); | ||||
| 1714 | my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD)); | ||||
| 1715 | |||||
| 1716 | # Special exception for the perl core where INST_* is not in blib. | ||||
| 1717 | # This cleans up the files built from the ext/ directory (all XS). | ||||
| 1718 | if( $self->{PERL_CORE} ) { | ||||
| 1719 | push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR)); | ||||
| 1720 | push @files, values %{$self->{PM}}; | ||||
| 1721 | } | ||||
| 1722 | |||||
| 1723 | if( $self->has_link_code ){ | ||||
| 1724 | push @files, qw($(OBJECT)); | ||||
| 1725 | } | ||||
| 1726 | |||||
| 1727 | if( $attribs{FILES} ) { | ||||
| 1728 | if( ref $attribs{FILES} ) { | ||||
| 1729 | push @dirs, @{ $attribs{FILES} }; | ||||
| 1730 | } | ||||
| 1731 | else { | ||||
| 1732 | push @dirs, split /\s+/, $attribs{FILES}; | ||||
| 1733 | } | ||||
| 1734 | } | ||||
| 1735 | |||||
| 1736 | # Occasionally files are repeated several times from different sources | ||||
| 1737 | { my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; } | ||||
| 1738 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; } | ||||
| 1739 | |||||
| 1740 | my $rm_cmd = join "\n\t", map { "$_" } | ||||
| 1741 | $self->split_command('- $(RM_F)', @files); | ||||
| 1742 | my $rmf_cmd = join "\n\t", map { "$_" } | ||||
| 1743 | $self->split_command('- $(RM_RF)', @dirs); | ||||
| 1744 | |||||
| 1745 | my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd; | ||||
| 1746 | # Delete temporary files (via clean) and also delete dist files | ||||
| 1747 | realclean purge :: realclean_subdirs | ||||
| 1748 | %s | ||||
| 1749 | %s | ||||
| 1750 | MAKE | ||||
| 1751 | |||||
| 1752 | $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP}; | ||||
| 1753 | |||||
| 1754 | return $m; | ||||
| 1755 | } | ||||
| 1756 | |||||
| 1757 | |||||
| 1758 | =head3 realclean_subdirs_target | ||||
| 1759 | |||||
| 1760 | my $make_frag = $MM->realclean_subdirs_target; | ||||
| 1761 | |||||
| 1762 | Returns the realclean_subdirs target. This is used by the realclean | ||||
| 1763 | target to call realclean on any subdirectories which contain Makefiles. | ||||
| 1764 | |||||
| 1765 | =cut | ||||
| 1766 | |||||
| 1767 | sub realclean_subdirs_target { | ||||
| 1768 | my $self = shift; | ||||
| 1769 | my @m = <<'EOF'; | ||||
| 1770 | # so clean is forced to complete before realclean_subdirs runs | ||||
| 1771 | realclean_subdirs : clean | ||||
| 1772 | EOF | ||||
| 1773 | return join '', @m, "\t\$(NOECHO) \$(NOOP)\n" unless @{$self->{DIR}}; | ||||
| 1774 | foreach my $dir (@{$self->{DIR}}) { | ||||
| 1775 | foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) { | ||||
| 1776 | my $subrclean .= $self->oneliner(_sprintf562 <<'CODE', $dir, $makefile); | ||||
| 1777 | chdir '%1$s'; system '$(MAKE) $(USEMAKEFILE) %2$s realclean' if -f '%2$s'; | ||||
| 1778 | CODE | ||||
| 1779 | push @m, "\t- $subrclean\n"; | ||||
| 1780 | } | ||||
| 1781 | } | ||||
| 1782 | return join '', @m; | ||||
| 1783 | } | ||||
| 1784 | |||||
| 1785 | |||||
| 1786 | =head3 signature_target | ||||
| 1787 | |||||
| 1788 | my $target = $mm->signature_target; | ||||
| 1789 | |||||
| 1790 | Generate the signature target. | ||||
| 1791 | |||||
| 1792 | Writes the file SIGNATURE with "cpansign -s". | ||||
| 1793 | |||||
| 1794 | =cut | ||||
| 1795 | |||||
| 1796 | sub signature_target { | ||||
| 1797 | my $self = shift; | ||||
| 1798 | |||||
| 1799 | return <<'MAKE_FRAG'; | ||||
| 1800 | signature : | ||||
| 1801 | cpansign -s | ||||
| 1802 | MAKE_FRAG | ||||
| 1803 | |||||
| 1804 | } | ||||
| 1805 | |||||
| 1806 | |||||
| 1807 | =head3 distsignature_target | ||||
| 1808 | |||||
| 1809 | my $make_frag = $mm->distsignature_target; | ||||
| 1810 | |||||
| 1811 | Generates the distsignature target to add SIGNATURE to the MANIFEST in the | ||||
| 1812 | distdir. | ||||
| 1813 | |||||
| 1814 | =cut | ||||
| 1815 | |||||
| 1816 | sub distsignature_target { | ||||
| 1817 | my $self = shift; | ||||
| 1818 | |||||
| 1819 | my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']); | ||||
| 1820 | eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } | ||||
| 1821 | or die "Could not add SIGNATURE to MANIFEST: ${'@'}" | ||||
| 1822 | CODE | ||||
| 1823 | |||||
| 1824 | my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s'); | ||||
| 1825 | |||||
| 1826 | # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not | ||||
| 1827 | # exist | ||||
| 1828 | my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE'); | ||||
| 1829 | my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign ); | ||||
| 1830 | |||||
| 1831 | return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist | ||||
| 1832 | distsignature : distmeta | ||||
| 1833 | $(NOECHO) %s | ||||
| 1834 | $(NOECHO) %s | ||||
| 1835 | %s | ||||
| 1836 | |||||
| 1837 | MAKE | ||||
| 1838 | |||||
| 1839 | } | ||||
| 1840 | |||||
| 1841 | |||||
| 1842 | =head3 special_targets | ||||
| 1843 | |||||
| 1844 | my $make_frag = $mm->special_targets | ||||
| 1845 | |||||
| 1846 | Returns a make fragment containing any targets which have special | ||||
| 1847 | meaning to make. For example, .SUFFIXES and .PHONY. | ||||
| 1848 | |||||
| 1849 | =cut | ||||
| 1850 | |||||
| 1851 | sub special_targets { | ||||
| 1852 | my $make_frag = <<'MAKE_FRAG'; | ||||
| 1853 | .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT) | ||||
| 1854 | |||||
| 1855 | .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static | ||||
| 1856 | |||||
| 1857 | MAKE_FRAG | ||||
| 1858 | |||||
| 1859 | $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT}; | ||||
| 1860 | .NO_CONFIG_REC: Makefile | ||||
| 1861 | |||||
| 1862 | MAKE_FRAG | ||||
| 1863 | |||||
| 1864 | return $make_frag; | ||||
| 1865 | } | ||||
| 1866 | |||||
| - - | |||||
| 1870 | =head2 Init methods | ||||
| 1871 | |||||
| 1872 | Methods which help initialize the MakeMaker object and macros. | ||||
| 1873 | |||||
| 1874 | |||||
| 1875 | =head3 init_ABSTRACT | ||||
| 1876 | |||||
| 1877 | $mm->init_ABSTRACT | ||||
| 1878 | |||||
| 1879 | =cut | ||||
| 1880 | |||||
| 1881 | sub init_ABSTRACT { | ||||
| 1882 | my $self = shift; | ||||
| 1883 | |||||
| 1884 | if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) { | ||||
| 1885 | warn "Both ABSTRACT_FROM and ABSTRACT are set. ". | ||||
| 1886 | "Ignoring ABSTRACT_FROM.\n"; | ||||
| 1887 | return; | ||||
| 1888 | } | ||||
| 1889 | |||||
| 1890 | if ($self->{ABSTRACT_FROM}){ | ||||
| 1891 | $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or | ||||
| 1892 | carp "WARNING: Setting ABSTRACT via file ". | ||||
| 1893 | "'$self->{ABSTRACT_FROM}' failed\n"; | ||||
| 1894 | } | ||||
| 1895 | |||||
| 1896 | if ($self->{ABSTRACT} && $self->{ABSTRACT} =~ m![[:cntrl:]]+!) { | ||||
| 1897 | warn "WARNING: ABSTRACT contains control character(s),". | ||||
| 1898 | " they will be removed\n"; | ||||
| 1899 | $self->{ABSTRACT} =~ s![[:cntrl:]]+!!g; | ||||
| 1900 | return; | ||||
| 1901 | } | ||||
| 1902 | } | ||||
| 1903 | |||||
| 1904 | =head3 init_INST | ||||
| 1905 | |||||
| 1906 | $mm->init_INST; | ||||
| 1907 | |||||
| 1908 | Called by init_main. Sets up all INST_* variables except those related | ||||
| 1909 | to XS code. Those are handled in init_xs. | ||||
| 1910 | |||||
| 1911 | =cut | ||||
| 1912 | |||||
| 1913 | sub init_INST { | ||||
| 1914 | my($self) = shift; | ||||
| 1915 | |||||
| 1916 | $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch"); | ||||
| 1917 | $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin'); | ||||
| 1918 | |||||
| 1919 | # INST_LIB typically pre-set if building an extension after | ||||
| 1920 | # perl has been built and installed. Setting INST_LIB allows | ||||
| 1921 | # you to build directly into, say $Config{privlibexp}. | ||||
| 1922 | unless ($self->{INST_LIB}){ | ||||
| 1923 | if ($self->{PERL_CORE}) { | ||||
| 1924 | $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB}; | ||||
| 1925 | } else { | ||||
| 1926 | $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib"); | ||||
| 1927 | } | ||||
| 1928 | } | ||||
| 1929 | |||||
| 1930 | my @parentdir = split(/::/, $self->{PARENT_NAME}); | ||||
| 1931 | $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir); | ||||
| 1932 | $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir); | ||||
| 1933 | $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto', | ||||
| 1934 | '$(FULLEXT)'); | ||||
| 1935 | $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto', | ||||
| 1936 | '$(FULLEXT)'); | ||||
| 1937 | |||||
| 1938 | $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script'); | ||||
| 1939 | |||||
| 1940 | $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1'); | ||||
| 1941 | $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3'); | ||||
| 1942 | |||||
| 1943 | return 1; | ||||
| 1944 | } | ||||
| 1945 | |||||
| 1946 | |||||
| 1947 | =head3 init_INSTALL | ||||
| 1948 | |||||
| 1949 | $mm->init_INSTALL; | ||||
| 1950 | |||||
| 1951 | Called by init_main. Sets up all INSTALL_* variables (except | ||||
| 1952 | INSTALLDIRS) and *PREFIX. | ||||
| 1953 | |||||
| 1954 | =cut | ||||
| 1955 | |||||
| 1956 | sub init_INSTALL { | ||||
| 1957 | my($self) = shift; | ||||
| 1958 | |||||
| 1959 | if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) { | ||||
| 1960 | die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n"; | ||||
| 1961 | } | ||||
| 1962 | |||||
| 1963 | if( $self->{ARGS}{INSTALL_BASE} ) { | ||||
| 1964 | $self->init_INSTALL_from_INSTALL_BASE; | ||||
| 1965 | } | ||||
| 1966 | else { | ||||
| 1967 | $self->init_INSTALL_from_PREFIX; | ||||
| 1968 | } | ||||
| 1969 | } | ||||
| 1970 | |||||
| 1971 | |||||
| 1972 | =head3 init_INSTALL_from_PREFIX | ||||
| 1973 | |||||
| 1974 | $mm->init_INSTALL_from_PREFIX; | ||||
| 1975 | |||||
| 1976 | =cut | ||||
| 1977 | |||||
| 1978 | sub init_INSTALL_from_PREFIX { | ||||
| 1979 | my $self = shift; | ||||
| 1980 | |||||
| 1981 | $self->init_lib2arch; | ||||
| 1982 | |||||
| 1983 | # There are often no Config.pm defaults for these new man variables so | ||||
| 1984 | # we fall back to the old behavior which is to use installman*dir | ||||
| 1985 | foreach my $num (1, 3) { | ||||
| 1986 | my $k = 'installsiteman'.$num.'dir'; | ||||
| 1987 | |||||
| 1988 | $self->{uc $k} ||= uc "\$(installman${num}dir)" | ||||
| 1989 | unless $Config{$k}; | ||||
| 1990 | } | ||||
| 1991 | |||||
| 1992 | foreach my $num (1, 3) { | ||||
| 1993 | my $k = 'installvendorman'.$num.'dir'; | ||||
| 1994 | |||||
| 1995 | unless( $Config{$k} ) { | ||||
| 1996 | $self->{uc $k} ||= $Config{usevendorprefix} | ||||
| 1997 | ? uc "\$(installman${num}dir)" | ||||
| 1998 | : ''; | ||||
| 1999 | } | ||||
| 2000 | } | ||||
| 2001 | |||||
| 2002 | $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)' | ||||
| 2003 | unless $Config{installsitebin}; | ||||
| 2004 | $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)' | ||||
| 2005 | unless $Config{installsitescript}; | ||||
| 2006 | |||||
| 2007 | unless( $Config{installvendorbin} ) { | ||||
| 2008 | $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} | ||||
| 2009 | ? $Config{installbin} | ||||
| 2010 | : ''; | ||||
| 2011 | } | ||||
| 2012 | unless( $Config{installvendorscript} ) { | ||||
| 2013 | $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix} | ||||
| 2014 | ? $Config{installscript} | ||||
| 2015 | : ''; | ||||
| 2016 | } | ||||
| 2017 | |||||
| 2018 | |||||
| 2019 | my $iprefix = $Config{installprefixexp} || $Config{installprefix} || | ||||
| 2020 | $Config{prefixexp} || $Config{prefix} || ''; | ||||
| 2021 | my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : ''; | ||||
| 2022 | my $sprefix = $Config{siteprefixexp} || ''; | ||||
| 2023 | |||||
| 2024 | # 5.005_03 doesn't have a siteprefix. | ||||
| 2025 | $sprefix = $iprefix unless $sprefix; | ||||
| 2026 | |||||
| 2027 | |||||
| 2028 | $self->{PREFIX} ||= ''; | ||||
| 2029 | |||||
| 2030 | if( $self->{PREFIX} ) { | ||||
| 2031 | @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} = | ||||
| 2032 | ('$(PREFIX)') x 3; | ||||
| 2033 | } | ||||
| 2034 | else { | ||||
| 2035 | $self->{PERLPREFIX} ||= $iprefix; | ||||
| 2036 | $self->{SITEPREFIX} ||= $sprefix; | ||||
| 2037 | $self->{VENDORPREFIX} ||= $vprefix; | ||||
| 2038 | |||||
| 2039 | # Lots of MM extension authors like to use $(PREFIX) so we | ||||
| 2040 | # put something sensible in there no matter what. | ||||
| 2041 | $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)'; | ||||
| 2042 | } | ||||
| 2043 | |||||
| 2044 | my $arch = $Config{archname}; | ||||
| 2045 | my $version = $Config{version}; | ||||
| 2046 | |||||
| 2047 | # default style | ||||
| 2048 | my $libstyle = $Config{installstyle} || 'lib/perl5'; | ||||
| 2049 | my $manstyle = ''; | ||||
| 2050 | |||||
| 2051 | if( $self->{LIBSTYLE} ) { | ||||
| 2052 | $libstyle = $self->{LIBSTYLE}; | ||||
| 2053 | $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : ''; | ||||
| 2054 | } | ||||
| 2055 | |||||
| 2056 | # Some systems, like VOS, set installman*dir to '' if they can't | ||||
| 2057 | # read man pages. | ||||
| 2058 | for my $num (1, 3) { | ||||
| 2059 | $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none' | ||||
| 2060 | unless $Config{'installman'.$num.'dir'}; | ||||
| 2061 | } | ||||
| 2062 | |||||
| 2063 | my %bin_layouts = | ||||
| 2064 | ( | ||||
| 2065 | bin => { s => $iprefix, | ||||
| 2066 | t => 'perl', | ||||
| 2067 | d => 'bin' }, | ||||
| 2068 | vendorbin => { s => $vprefix, | ||||
| 2069 | t => 'vendor', | ||||
| 2070 | d => 'bin' }, | ||||
| 2071 | sitebin => { s => $sprefix, | ||||
| 2072 | t => 'site', | ||||
| 2073 | d => 'bin' }, | ||||
| 2074 | script => { s => $iprefix, | ||||
| 2075 | t => 'perl', | ||||
| 2076 | d => 'bin' }, | ||||
| 2077 | vendorscript=> { s => $vprefix, | ||||
| 2078 | t => 'vendor', | ||||
| 2079 | d => 'bin' }, | ||||
| 2080 | sitescript => { s => $sprefix, | ||||
| 2081 | t => 'site', | ||||
| 2082 | d => 'bin' }, | ||||
| 2083 | ); | ||||
| 2084 | |||||
| 2085 | my %man_layouts = | ||||
| 2086 | ( | ||||
| 2087 | man1dir => { s => $iprefix, | ||||
| 2088 | t => 'perl', | ||||
| 2089 | d => 'man/man1', | ||||
| 2090 | style => $manstyle, }, | ||||
| 2091 | siteman1dir => { s => $sprefix, | ||||
| 2092 | t => 'site', | ||||
| 2093 | d => 'man/man1', | ||||
| 2094 | style => $manstyle, }, | ||||
| 2095 | vendorman1dir => { s => $vprefix, | ||||
| 2096 | t => 'vendor', | ||||
| 2097 | d => 'man/man1', | ||||
| 2098 | style => $manstyle, }, | ||||
| 2099 | |||||
| 2100 | man3dir => { s => $iprefix, | ||||
| 2101 | t => 'perl', | ||||
| 2102 | d => 'man/man3', | ||||
| 2103 | style => $manstyle, }, | ||||
| 2104 | siteman3dir => { s => $sprefix, | ||||
| 2105 | t => 'site', | ||||
| 2106 | d => 'man/man3', | ||||
| 2107 | style => $manstyle, }, | ||||
| 2108 | vendorman3dir => { s => $vprefix, | ||||
| 2109 | t => 'vendor', | ||||
| 2110 | d => 'man/man3', | ||||
| 2111 | style => $manstyle, }, | ||||
| 2112 | ); | ||||
| 2113 | |||||
| 2114 | my %lib_layouts = | ||||
| 2115 | ( | ||||
| 2116 | privlib => { s => $iprefix, | ||||
| 2117 | t => 'perl', | ||||
| 2118 | d => '', | ||||
| 2119 | style => $libstyle, }, | ||||
| 2120 | vendorlib => { s => $vprefix, | ||||
| 2121 | t => 'vendor', | ||||
| 2122 | d => '', | ||||
| 2123 | style => $libstyle, }, | ||||
| 2124 | sitelib => { s => $sprefix, | ||||
| 2125 | t => 'site', | ||||
| 2126 | d => 'site_perl', | ||||
| 2127 | style => $libstyle, }, | ||||
| 2128 | |||||
| 2129 | archlib => { s => $iprefix, | ||||
| 2130 | t => 'perl', | ||||
| 2131 | d => "$version/$arch", | ||||
| 2132 | style => $libstyle }, | ||||
| 2133 | vendorarch => { s => $vprefix, | ||||
| 2134 | t => 'vendor', | ||||
| 2135 | d => "$version/$arch", | ||||
| 2136 | style => $libstyle }, | ||||
| 2137 | sitearch => { s => $sprefix, | ||||
| 2138 | t => 'site', | ||||
| 2139 | d => "site_perl/$version/$arch", | ||||
| 2140 | style => $libstyle }, | ||||
| 2141 | ); | ||||
| 2142 | |||||
| 2143 | |||||
| 2144 | # Special case for LIB. | ||||
| 2145 | if( $self->{LIB} ) { | ||||
| 2146 | foreach my $var (keys %lib_layouts) { | ||||
| 2147 | my $Installvar = uc "install$var"; | ||||
| 2148 | |||||
| 2149 | if( $var =~ /arch/ ) { | ||||
| 2150 | $self->{$Installvar} ||= | ||||
| 2151 | $self->catdir($self->{LIB}, $Config{archname}); | ||||
| 2152 | } | ||||
| 2153 | else { | ||||
| 2154 | $self->{$Installvar} ||= $self->{LIB}; | ||||
| 2155 | } | ||||
| 2156 | } | ||||
| 2157 | } | ||||
| 2158 | |||||
| 2159 | my %type2prefix = ( perl => 'PERLPREFIX', | ||||
| 2160 | site => 'SITEPREFIX', | ||||
| 2161 | vendor => 'VENDORPREFIX' | ||||
| 2162 | ); | ||||
| 2163 | |||||
| 2164 | my %layouts = (%bin_layouts, %man_layouts, %lib_layouts); | ||||
| 2165 | while( my($var, $layout) = each(%layouts) ) { | ||||
| 2166 | my($s, $t, $d, $style) = @{$layout}{qw(s t d style)}; | ||||
| 2167 | my $r = '$('.$type2prefix{$t}.')'; | ||||
| 2168 | |||||
| 2169 | warn "Prefixing $var\n" if $Verbose >= 2; | ||||
| 2170 | |||||
| 2171 | my $installvar = "install$var"; | ||||
| 2172 | my $Installvar = uc $installvar; | ||||
| 2173 | next if $self->{$Installvar}; | ||||
| 2174 | |||||
| 2175 | $d = "$style/$d" if $style; | ||||
| 2176 | $self->prefixify($installvar, $s, $r, $d); | ||||
| 2177 | |||||
| 2178 | warn " $Installvar == $self->{$Installvar}\n" | ||||
| 2179 | if $Verbose >= 2; | ||||
| 2180 | } | ||||
| 2181 | |||||
| 2182 | # Generate these if they weren't figured out. | ||||
| 2183 | $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH}; | ||||
| 2184 | $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB}; | ||||
| 2185 | |||||
| 2186 | return 1; | ||||
| 2187 | } | ||||
| 2188 | |||||
| 2189 | |||||
| 2190 | =head3 init_from_INSTALL_BASE | ||||
| 2191 | |||||
| 2192 | $mm->init_from_INSTALL_BASE | ||||
| 2193 | |||||
| 2194 | =cut | ||||
| 2195 | |||||
| 2196 | my %map = ( | ||||
| 2197 | lib => [qw(lib perl5)], | ||||
| 2198 | 1 | 4µs | arch => [('lib', 'perl5', $Config{archname})], | ||
| 2199 | bin => [qw(bin)], | ||||
| 2200 | man1dir => [qw(man man1)], | ||||
| 2201 | man3dir => [qw(man man3)] | ||||
| 2202 | ); | ||||
| 2203 | 1 | 600ns | $map{script} = $map{bin}; | ||
| 2204 | |||||
| 2205 | sub init_INSTALL_from_INSTALL_BASE { | ||||
| 2206 | my $self = shift; | ||||
| 2207 | |||||
| 2208 | @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = | ||||
| 2209 | '$(INSTALL_BASE)'; | ||||
| 2210 | |||||
| 2211 | my %install; | ||||
| 2212 | foreach my $thing (keys %map) { | ||||
| 2213 | foreach my $dir (('', 'SITE', 'VENDOR')) { | ||||
| 2214 | my $uc_thing = uc $thing; | ||||
| 2215 | my $key = "INSTALL".$dir.$uc_thing; | ||||
| 2216 | |||||
| 2217 | $install{$key} ||= | ||||
| 2218 | ($thing =~ /^man.dir$/ and not $Config{lc $key}) | ||||
| 2219 | ? 'none' | ||||
| 2220 | : $self->catdir('$(INSTALL_BASE)', @{$map{$thing}}); | ||||
| 2221 | } | ||||
| 2222 | } | ||||
| 2223 | |||||
| 2224 | # Adjust for variable quirks. | ||||
| 2225 | $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH}; | ||||
| 2226 | $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB}; | ||||
| 2227 | |||||
| 2228 | foreach my $key (keys %install) { | ||||
| 2229 | $self->{$key} ||= $install{$key}; | ||||
| 2230 | } | ||||
| 2231 | |||||
| 2232 | return 1; | ||||
| 2233 | } | ||||
| 2234 | |||||
| 2235 | |||||
| 2236 | =head3 init_VERSION I<Abstract> | ||||
| 2237 | |||||
| 2238 | $mm->init_VERSION | ||||
| 2239 | |||||
| 2240 | Initialize macros representing versions of MakeMaker and other tools | ||||
| 2241 | |||||
| 2242 | MAKEMAKER: path to the MakeMaker module. | ||||
| 2243 | |||||
| 2244 | MM_VERSION: ExtUtils::MakeMaker Version | ||||
| 2245 | |||||
| 2246 | MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards | ||||
| 2247 | compat) | ||||
| 2248 | |||||
| 2249 | VERSION: version of your module | ||||
| 2250 | |||||
| 2251 | VERSION_MACRO: which macro represents the version (usually 'VERSION') | ||||
| 2252 | |||||
| 2253 | VERSION_SYM: like version but safe for use as an RCS revision number | ||||
| 2254 | |||||
| 2255 | DEFINE_VERSION: -D line to set the module version when compiling | ||||
| 2256 | |||||
| 2257 | XS_VERSION: version in your .xs file. Defaults to $(VERSION) | ||||
| 2258 | |||||
| 2259 | XS_VERSION_MACRO: which macro represents the XS version. | ||||
| 2260 | |||||
| 2261 | XS_DEFINE_VERSION: -D line to set the xs version when compiling. | ||||
| 2262 | |||||
| 2263 | Called by init_main. | ||||
| 2264 | |||||
| 2265 | =cut | ||||
| 2266 | |||||
| 2267 | sub init_VERSION { | ||||
| 2268 | my($self) = shift; | ||||
| 2269 | |||||
| 2270 | $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename; | ||||
| 2271 | $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION; | ||||
| 2272 | $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision; | ||||
| 2273 | $self->{VERSION_FROM} ||= ''; | ||||
| 2274 | |||||
| 2275 | if ($self->{VERSION_FROM}){ | ||||
| 2276 | $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}); | ||||
| 2277 | if( $self->{VERSION} eq 'undef' ) { | ||||
| 2278 | carp("WARNING: Setting VERSION via file ". | ||||
| 2279 | "'$self->{VERSION_FROM}' failed\n"); | ||||
| 2280 | } | ||||
| 2281 | } | ||||
| 2282 | |||||
| 2283 | if (defined $self->{VERSION}) { | ||||
| 2284 | if ( $self->{VERSION} !~ /^\s*v?[\d_\.]+\s*$/ ) { | ||||
| 2285 | require version; | ||||
| 2286 | my $normal = eval { version->new( $self->{VERSION} ) }; | ||||
| 2287 | $self->{VERSION} = $normal if defined $normal; | ||||
| 2288 | } | ||||
| 2289 | $self->{VERSION} =~ s/^\s+//; | ||||
| 2290 | $self->{VERSION} =~ s/\s+$//; | ||||
| 2291 | } | ||||
| 2292 | else { | ||||
| 2293 | $self->{VERSION} = ''; | ||||
| 2294 | } | ||||
| 2295 | |||||
| 2296 | |||||
| 2297 | $self->{VERSION_MACRO} = 'VERSION'; | ||||
| 2298 | ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g; | ||||
| 2299 | $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"'; | ||||
| 2300 | |||||
| 2301 | |||||
| 2302 | # Graham Barr and Paul Marquess had some ideas how to ensure | ||||
| 2303 | # version compatibility between the *.pm file and the | ||||
| 2304 | # corresponding *.xs file. The bottom line was, that we need an | ||||
| 2305 | # XS_VERSION macro that defaults to VERSION: | ||||
| 2306 | $self->{XS_VERSION} ||= $self->{VERSION}; | ||||
| 2307 | |||||
| 2308 | $self->{XS_VERSION_MACRO} = 'XS_VERSION'; | ||||
| 2309 | $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"'; | ||||
| 2310 | |||||
| 2311 | } | ||||
| 2312 | |||||
| 2313 | |||||
| 2314 | =head3 init_tools | ||||
| 2315 | |||||
| 2316 | $MM->init_tools(); | ||||
| 2317 | |||||
| 2318 | Initializes the simple macro definitions used by tools_other() and | ||||
| 2319 | places them in the $MM object. These use conservative cross platform | ||||
| 2320 | versions and should be overridden with platform specific versions for | ||||
| 2321 | performance. | ||||
| 2322 | |||||
| 2323 | Defines at least these macros. | ||||
| 2324 | |||||
| 2325 | Macro Description | ||||
| 2326 | |||||
| 2327 | NOOP Do nothing | ||||
| 2328 | NOECHO Tell make not to display the command itself | ||||
| 2329 | |||||
| 2330 | SHELL Program used to run shell commands | ||||
| 2331 | |||||
| 2332 | ECHO Print text adding a newline on the end | ||||
| 2333 | RM_F Remove a file | ||||
| 2334 | RM_RF Remove a directory | ||||
| 2335 | TOUCH Update a file's timestamp | ||||
| 2336 | TEST_F Test for a file's existence | ||||
| 2337 | TEST_S Test the size of a file | ||||
| 2338 | CP Copy a file | ||||
| 2339 | CP_NONEMPTY Copy a file if it is not empty | ||||
| 2340 | MV Move a file | ||||
| 2341 | CHMOD Change permissions on a file | ||||
| 2342 | FALSE Exit with non-zero | ||||
| 2343 | TRUE Exit with zero | ||||
| 2344 | |||||
| 2345 | UMASK_NULL Nullify umask | ||||
| 2346 | DEV_NULL Suppress all command output | ||||
| 2347 | |||||
| 2348 | =cut | ||||
| 2349 | |||||
| 2350 | sub init_tools { | ||||
| 2351 | my $self = shift; | ||||
| 2352 | |||||
| 2353 | $self->{ECHO} ||= $self->oneliner('binmode STDOUT, qq{:raw}; print qq{@ARGV}', ['-l']); | ||||
| 2354 | $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}'); | ||||
| 2355 | |||||
| 2356 | $self->{TOUCH} ||= $self->oneliner('touch', ["-MExtUtils::Command"]); | ||||
| 2357 | $self->{CHMOD} ||= $self->oneliner('chmod', ["-MExtUtils::Command"]); | ||||
| 2358 | $self->{RM_F} ||= $self->oneliner('rm_f', ["-MExtUtils::Command"]); | ||||
| 2359 | $self->{RM_RF} ||= $self->oneliner('rm_rf', ["-MExtUtils::Command"]); | ||||
| 2360 | $self->{TEST_F} ||= $self->oneliner('test_f', ["-MExtUtils::Command"]); | ||||
| 2361 | $self->{TEST_S} ||= $self->oneliner('test_s', ["-MExtUtils::Command::MM"]); | ||||
| 2362 | $self->{CP_NONEMPTY} ||= $self->oneliner('cp_nonempty', ["-MExtUtils::Command::MM"]); | ||||
| 2363 | $self->{FALSE} ||= $self->oneliner('exit 1'); | ||||
| 2364 | $self->{TRUE} ||= $self->oneliner('exit 0'); | ||||
| 2365 | |||||
| 2366 | $self->{MKPATH} ||= $self->oneliner('mkpath', ["-MExtUtils::Command"]); | ||||
| 2367 | |||||
| 2368 | $self->{CP} ||= $self->oneliner('cp', ["-MExtUtils::Command"]); | ||||
| 2369 | $self->{MV} ||= $self->oneliner('mv', ["-MExtUtils::Command"]); | ||||
| 2370 | |||||
| 2371 | $self->{MOD_INSTALL} ||= | ||||
| 2372 | $self->oneliner(<<'CODE', ['-MExtUtils::Install']); | ||||
| 2373 | install([ from_to => {@ARGV}, verbose => '$(VERBINST)', uninstall_shadows => '$(UNINST)', dir_mode => '$(PERM_DIR)' ]); | ||||
| 2374 | CODE | ||||
| 2375 | $self->{DOC_INSTALL} ||= $self->oneliner('perllocal_install', ["-MExtUtils::Command::MM"]); | ||||
| 2376 | $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]); | ||||
| 2377 | $self->{WARN_IF_OLD_PACKLIST} ||= | ||||
| 2378 | $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]); | ||||
| 2379 | $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]); | ||||
| 2380 | $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]); | ||||
| 2381 | |||||
| 2382 | $self->{UNINST} ||= 0; | ||||
| 2383 | $self->{VERBINST} ||= 0; | ||||
| 2384 | |||||
| 2385 | $self->{SHELL} ||= $Config{sh}; | ||||
| 2386 | |||||
| 2387 | # UMASK_NULL is not used by MakeMaker but some CPAN modules | ||||
| 2388 | # make use of it. | ||||
| 2389 | $self->{UMASK_NULL} ||= "umask 0"; | ||||
| 2390 | |||||
| 2391 | # Not the greatest default, but its something. | ||||
| 2392 | $self->{DEV_NULL} ||= "> /dev/null 2>&1"; | ||||
| 2393 | |||||
| 2394 | $self->{NOOP} ||= '$(TRUE)'; | ||||
| 2395 | $self->{NOECHO} = '@' unless defined $self->{NOECHO}; | ||||
| 2396 | |||||
| 2397 | $self->{FIRST_MAKEFILE} ||= $self->{MAKEFILE} || 'Makefile'; | ||||
| 2398 | $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE}; | ||||
| 2399 | $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old'; | ||||
| 2400 | $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl'; | ||||
| 2401 | |||||
| 2402 | # Not everybody uses -f to indicate "use this Makefile instead" | ||||
| 2403 | $self->{USEMAKEFILE} ||= '-f'; | ||||
| 2404 | |||||
| 2405 | # Some makes require a wrapper around macros passed in on the command | ||||
| 2406 | # line. | ||||
| 2407 | $self->{MACROSTART} ||= ''; | ||||
| 2408 | $self->{MACROEND} ||= ''; | ||||
| 2409 | |||||
| 2410 | return; | ||||
| 2411 | } | ||||
| 2412 | |||||
| 2413 | |||||
| 2414 | =head3 init_others | ||||
| 2415 | |||||
| 2416 | $MM->init_others(); | ||||
| 2417 | |||||
| 2418 | Initializes the macro definitions having to do with compiling and | ||||
| 2419 | linking used by tools_other() and places them in the $MM object. | ||||
| 2420 | |||||
| 2421 | If there is no description, its the same as the parameter to | ||||
| 2422 | WriteMakefile() documented in L<ExtUtils::MakeMaker>. | ||||
| 2423 | |||||
| 2424 | =cut | ||||
| 2425 | |||||
| 2426 | sub init_others { | ||||
| 2427 | my $self = shift; | ||||
| 2428 | |||||
| 2429 | $self->{LD_RUN_PATH} = ""; | ||||
| 2430 | |||||
| 2431 | $self->{LIBS} = $self->_fix_libs($self->{LIBS}); | ||||
| 2432 | |||||
| 2433 | # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS} | ||||
| 2434 | foreach my $libs ( @{$self->{LIBS}} ){ | ||||
| 2435 | $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace | ||||
| 2436 | my(@libs) = $self->extliblist($libs); | ||||
| 2437 | if ($libs[0] or $libs[1] or $libs[2]){ | ||||
| 2438 | # LD_RUN_PATH now computed by ExtUtils::Liblist | ||||
| 2439 | ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, | ||||
| 2440 | $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs; | ||||
| 2441 | last; | ||||
| 2442 | } | ||||
| 2443 | } | ||||
| 2444 | |||||
| 2445 | if ( $self->{OBJECT} ) { | ||||
| 2446 | $self->{OBJECT} = join(" ", @{$self->{OBJECT}}) if ref $self->{OBJECT}; | ||||
| 2447 | $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g; | ||||
| 2448 | } elsif ( ($self->{MAGICXS} || $self->{XSMULTI}) && @{$self->{O_FILES}||[]} ) { | ||||
| 2449 | $self->{OBJECT} = join(" ", @{$self->{O_FILES}}); | ||||
| 2450 | $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g; | ||||
| 2451 | } else { | ||||
| 2452 | # init_dirscan should have found out, if we have C files | ||||
| 2453 | $self->{OBJECT} = ""; | ||||
| 2454 | $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]}; | ||||
| 2455 | } | ||||
| 2456 | $self->{OBJECT} =~ s/\n+/ \\\n\t/g; | ||||
| 2457 | |||||
| 2458 | $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : ""; | ||||
| 2459 | $self->{PERLMAINCC} ||= '$(CC)'; | ||||
| 2460 | $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM}; | ||||
| 2461 | |||||
| 2462 | # Sanity check: don't define LINKTYPE = dynamic if we're skipping | ||||
| 2463 | # the 'dynamic' section of MM. We don't have this problem with | ||||
| 2464 | # 'static', since we either must use it (%Config says we can't | ||||
| 2465 | # use dynamic loading) or the caller asked for it explicitly. | ||||
| 2466 | if (!$self->{LINKTYPE}) { | ||||
| 2467 | $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'} | ||||
| 2468 | ? 'static' | ||||
| 2469 | : ($Config{usedl} ? 'dynamic' : 'static'); | ||||
| 2470 | } | ||||
| 2471 | |||||
| 2472 | return; | ||||
| 2473 | } | ||||
| 2474 | |||||
| 2475 | |||||
| 2476 | # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or | ||||
| 2477 | # undefined. In any case we turn it into an anon array | ||||
| 2478 | sub _fix_libs { | ||||
| 2479 | my($self, $libs) = @_; | ||||
| 2480 | |||||
| 2481 | return !defined $libs ? [''] : | ||||
| 2482 | !ref $libs ? [$libs] : | ||||
| 2483 | !defined $libs->[0] ? [''] : | ||||
| 2484 | $libs ; | ||||
| 2485 | } | ||||
| 2486 | |||||
| 2487 | |||||
| 2488 | =head3 tools_other | ||||
| 2489 | |||||
| 2490 | my $make_frag = $MM->tools_other; | ||||
| 2491 | |||||
| 2492 | Returns a make fragment containing definitions for the macros init_others() | ||||
| 2493 | initializes. | ||||
| 2494 | |||||
| 2495 | =cut | ||||
| 2496 | |||||
| 2497 | sub tools_other { | ||||
| 2498 | my($self) = shift; | ||||
| 2499 | my @m; | ||||
| 2500 | |||||
| 2501 | # We set PM_FILTER as late as possible so it can see all the earlier | ||||
| 2502 | # on macro-order sensitive makes such as nmake. | ||||
| 2503 | for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH | ||||
| 2504 | UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP | ||||
| 2505 | FALSE TRUE | ||||
| 2506 | ECHO ECHO_N | ||||
| 2507 | UNINST VERBINST | ||||
| 2508 | MOD_INSTALL DOC_INSTALL UNINSTALL | ||||
| 2509 | WARN_IF_OLD_PACKLIST | ||||
| 2510 | MACROSTART MACROEND | ||||
| 2511 | USEMAKEFILE | ||||
| 2512 | PM_FILTER | ||||
| 2513 | FIXIN | ||||
| 2514 | CP_NONEMPTY | ||||
| 2515 | } ) | ||||
| 2516 | { | ||||
| 2517 | next unless defined $self->{$tool}; | ||||
| 2518 | push @m, "$tool = $self->{$tool}\n"; | ||||
| 2519 | } | ||||
| 2520 | |||||
| 2521 | return join "", @m; | ||||
| 2522 | } | ||||
| 2523 | |||||
| 2524 | |||||
| 2525 | =head3 init_DIRFILESEP I<Abstract> | ||||
| 2526 | |||||
| 2527 | $MM->init_DIRFILESEP; | ||||
| 2528 | my $dirfilesep = $MM->{DIRFILESEP}; | ||||
| 2529 | |||||
| 2530 | Initializes the DIRFILESEP macro which is the separator between the | ||||
| 2531 | directory and filename in a filepath. ie. / on Unix, \ on Win32 and | ||||
| 2532 | nothing on VMS. | ||||
| 2533 | |||||
| 2534 | For example: | ||||
| 2535 | |||||
| 2536 | # instead of $(INST_ARCHAUTODIR)/extralibs.ld | ||||
| 2537 | $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld | ||||
| 2538 | |||||
| 2539 | Something of a hack but it prevents a lot of code duplication between | ||||
| 2540 | MM_* variants. | ||||
| 2541 | |||||
| 2542 | Do not use this as a separator between directories. Some operating | ||||
| 2543 | systems use different separators between subdirectories as between | ||||
| 2544 | directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS). | ||||
| 2545 | |||||
| 2546 | =head3 init_linker I<Abstract> | ||||
| 2547 | |||||
| 2548 | $mm->init_linker; | ||||
| 2549 | |||||
| 2550 | Initialize macros which have to do with linking. | ||||
| 2551 | |||||
| 2552 | PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic | ||||
| 2553 | extensions. | ||||
| 2554 | |||||
| 2555 | PERL_ARCHIVE_AFTER: path to a library which should be put on the | ||||
| 2556 | linker command line I<after> the external libraries to be linked to | ||||
| 2557 | dynamic extensions. This may be needed if the linker is one-pass, and | ||||
| 2558 | Perl includes some overrides for C RTL functions, such as malloc(). | ||||
| 2559 | |||||
| 2560 | EXPORT_LIST: name of a file that is passed to linker to define symbols | ||||
| 2561 | to be exported. | ||||
| 2562 | |||||
| 2563 | Some OSes do not need these in which case leave it blank. | ||||
| 2564 | |||||
| 2565 | |||||
| 2566 | =head3 init_platform | ||||
| 2567 | |||||
| 2568 | $mm->init_platform | ||||
| 2569 | |||||
| 2570 | Initialize any macros which are for platform specific use only. | ||||
| 2571 | |||||
| 2572 | A typical one is the version number of your OS specific module. | ||||
| 2573 | (ie. MM_Unix_VERSION or MM_VMS_VERSION). | ||||
| 2574 | |||||
| 2575 | =cut | ||||
| 2576 | |||||
| 2577 | sub init_platform { | ||||
| 2578 | return ''; | ||||
| 2579 | } | ||||
| 2580 | |||||
| 2581 | |||||
| 2582 | =head3 init_MAKE | ||||
| 2583 | |||||
| 2584 | $mm->init_MAKE | ||||
| 2585 | |||||
| 2586 | Initialize MAKE from either a MAKE environment variable or $Config{make}. | ||||
| 2587 | |||||
| 2588 | =cut | ||||
| 2589 | |||||
| 2590 | sub init_MAKE { | ||||
| 2591 | my $self = shift; | ||||
| 2592 | |||||
| 2593 | $self->{MAKE} ||= $ENV{MAKE} || $Config{make}; | ||||
| 2594 | } | ||||
| 2595 | |||||
| 2596 | |||||
| 2597 | =head2 Tools | ||||
| 2598 | |||||
| 2599 | A grab bag of methods to generate specific macros and commands. | ||||
| 2600 | |||||
| - - | |||||
| 2603 | =head3 manifypods | ||||
| 2604 | |||||
| 2605 | Defines targets and routines to translate the pods into manpages and | ||||
| 2606 | put them into the INST_* directories. | ||||
| 2607 | |||||
| 2608 | =cut | ||||
| 2609 | |||||
| 2610 | sub manifypods { | ||||
| 2611 | my $self = shift; | ||||
| 2612 | |||||
| 2613 | my $POD2MAN_macro = $self->POD2MAN_macro(); | ||||
| 2614 | my $manifypods_target = $self->manifypods_target(); | ||||
| 2615 | |||||
| 2616 | return <<END_OF_TARGET; | ||||
| 2617 | |||||
| 2618 | $POD2MAN_macro | ||||
| 2619 | |||||
| 2620 | $manifypods_target | ||||
| 2621 | |||||
| 2622 | END_OF_TARGET | ||||
| 2623 | |||||
| 2624 | } | ||||
| 2625 | |||||
| 2626 | |||||
| 2627 | =head3 POD2MAN_macro | ||||
| 2628 | |||||
| 2629 | my $pod2man_macro = $self->POD2MAN_macro | ||||
| 2630 | |||||
| 2631 | Returns a definition for the POD2MAN macro. This is a program | ||||
| 2632 | which emulates the pod2man utility. You can add more switches to the | ||||
| 2633 | command by simply appending them on the macro. | ||||
| 2634 | |||||
| 2635 | Typical usage: | ||||
| 2636 | |||||
| 2637 | $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ... | ||||
| 2638 | |||||
| 2639 | =cut | ||||
| 2640 | |||||
| 2641 | sub POD2MAN_macro { | ||||
| 2642 | my $self = shift; | ||||
| 2643 | |||||
| 2644 | # Need the trailing '--' so perl stops gobbling arguments and - happens | ||||
| 2645 | # to be an alternative end of line separator on VMS so we quote it | ||||
| 2646 | return <<'END_OF_DEF'; | ||||
| 2647 | POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" | ||||
| 2648 | POD2MAN = $(POD2MAN_EXE) | ||||
| 2649 | END_OF_DEF | ||||
| 2650 | } | ||||
| 2651 | |||||
| 2652 | |||||
| 2653 | =head3 test_via_harness | ||||
| 2654 | |||||
| 2655 | my $command = $mm->test_via_harness($perl, $tests); | ||||
| 2656 | |||||
| 2657 | Returns a $command line which runs the given set of $tests with | ||||
| 2658 | Test::Harness and the given $perl. | ||||
| 2659 | |||||
| 2660 | Used on the t/*.t files. | ||||
| 2661 | |||||
| 2662 | =cut | ||||
| 2663 | |||||
| 2664 | sub test_via_harness { | ||||
| 2665 | my($self, $perl, $tests) = @_; | ||||
| 2666 | |||||
| 2667 | return qq{\t$perl "-MExtUtils::Command::MM" "-MTest::Harness" }. | ||||
| 2668 | qq{"-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n}; | ||||
| 2669 | } | ||||
| 2670 | |||||
| 2671 | =head3 test_via_script | ||||
| 2672 | |||||
| 2673 | my $command = $mm->test_via_script($perl, $script); | ||||
| 2674 | |||||
| 2675 | Returns a $command line which just runs a single test without | ||||
| 2676 | Test::Harness. No checks are done on the results, they're just | ||||
| 2677 | printed. | ||||
| 2678 | |||||
| 2679 | Used for test.pl, since they don't always follow Test::Harness | ||||
| 2680 | formatting. | ||||
| 2681 | |||||
| 2682 | =cut | ||||
| 2683 | |||||
| 2684 | sub test_via_script { | ||||
| 2685 | my($self, $perl, $script) = @_; | ||||
| 2686 | return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n}; | ||||
| 2687 | } | ||||
| 2688 | |||||
| 2689 | |||||
| 2690 | =head3 tool_autosplit | ||||
| 2691 | |||||
| 2692 | Defines a simple perl call that runs autosplit. May be deprecated by | ||||
| 2693 | pm_to_blib soon. | ||||
| 2694 | |||||
| 2695 | =cut | ||||
| 2696 | |||||
| 2697 | sub tool_autosplit { | ||||
| 2698 | my($self, %attribs) = @_; | ||||
| 2699 | |||||
| 2700 | my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};' | ||||
| 2701 | : ''; | ||||
| 2702 | |||||
| 2703 | my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen); | ||||
| 2704 | use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) | ||||
| 2705 | PERL_CODE | ||||
| 2706 | |||||
| 2707 | return sprintf <<'MAKE_FRAG', $asplit; | ||||
| 2708 | # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto | ||||
| 2709 | AUTOSPLITFILE = %s | ||||
| 2710 | |||||
| 2711 | MAKE_FRAG | ||||
| 2712 | |||||
| 2713 | } | ||||
| 2714 | |||||
| 2715 | |||||
| 2716 | =head3 arch_check | ||||
| 2717 | |||||
| 2718 | my $arch_ok = $mm->arch_check( | ||||
| 2719 | $INC{"Config.pm"}, | ||||
| 2720 | File::Spec->catfile($Config{archlibexp}, "Config.pm") | ||||
| 2721 | ); | ||||
| 2722 | |||||
| 2723 | A sanity check that what Perl thinks the architecture is and what | ||||
| 2724 | Config thinks the architecture is are the same. If they're not it | ||||
| 2725 | will return false and show a diagnostic message. | ||||
| 2726 | |||||
| 2727 | When building Perl it will always return true, as nothing is installed | ||||
| 2728 | yet. | ||||
| 2729 | |||||
| 2730 | The interface is a bit odd because this is the result of a | ||||
| 2731 | quick refactoring. Don't rely on it. | ||||
| 2732 | |||||
| 2733 | =cut | ||||
| 2734 | |||||
| 2735 | sub arch_check { | ||||
| 2736 | my $self = shift; | ||||
| 2737 | my($pconfig, $cconfig) = @_; | ||||
| 2738 | |||||
| 2739 | return 1 if $self->{PERL_SRC}; | ||||
| 2740 | |||||
| 2741 | my($pvol, $pthinks) = $self->splitpath($pconfig); | ||||
| 2742 | my($cvol, $cthinks) = $self->splitpath($cconfig); | ||||
| 2743 | |||||
| 2744 | return 1 if $pthinks =~ /perl-base/; # https://bugs.debian.org/962138 | ||||
| 2745 | |||||
| 2746 | $pthinks = $self->canonpath($pthinks); | ||||
| 2747 | $cthinks = $self->canonpath($cthinks); | ||||
| 2748 | |||||
| 2749 | my $ret = 1; | ||||
| 2750 | if ($pthinks ne $cthinks) { | ||||
| 2751 | print "Have $pthinks\n"; | ||||
| 2752 | print "Want $cthinks\n"; | ||||
| 2753 | |||||
| 2754 | $ret = 0; | ||||
| 2755 | |||||
| 2756 | my $arch = (grep length, $self->splitdir($pthinks))[-1]; | ||||
| 2757 | |||||
| 2758 | print <<END unless $self->{UNINSTALLED_PERL}; | ||||
| 2759 | Your perl and your Config.pm seem to have different ideas about the | ||||
| 2760 | architecture they are running on. | ||||
| 2761 | Perl thinks: [$arch] | ||||
| 2762 | Config says: [$Config{archname}] | ||||
| 2763 | This may or may not cause problems. Please check your installation of perl | ||||
| 2764 | if you have problems building this extension. | ||||
| 2765 | END | ||||
| 2766 | } | ||||
| 2767 | |||||
| 2768 | return $ret; | ||||
| 2769 | } | ||||
| 2770 | |||||
| - - | |||||
| 2773 | =head2 File::Spec wrappers | ||||
| 2774 | |||||
| 2775 | ExtUtils::MM_Any is a subclass of L<File::Spec>. The methods noted here | ||||
| 2776 | override File::Spec. | ||||
| 2777 | |||||
| - - | |||||
| 2780 | =head3 catfile | ||||
| 2781 | |||||
| 2782 | File::Spec <= 0.83 has a bug where the file part of catfile is not | ||||
| 2783 | canonicalized. This override fixes that bug. | ||||
| 2784 | |||||
| 2785 | =cut | ||||
| 2786 | |||||
| 2787 | sub catfile { | ||||
| 2788 | my $self = shift; | ||||
| 2789 | return $self->canonpath($self->SUPER::catfile(@_)); | ||||
| 2790 | } | ||||
| 2791 | |||||
| - - | |||||
| 2794 | =head2 Misc | ||||
| 2795 | |||||
| 2796 | Methods I can't really figure out where they should go yet. | ||||
| 2797 | |||||
| 2798 | |||||
| 2799 | =head3 find_tests | ||||
| 2800 | |||||
| 2801 | my $test = $mm->find_tests; | ||||
| 2802 | |||||
| 2803 | Returns a string suitable for feeding to the shell to return all | ||||
| 2804 | tests in t/*.t. | ||||
| 2805 | |||||
| 2806 | =cut | ||||
| 2807 | |||||
| 2808 | sub find_tests { | ||||
| 2809 | my($self) = shift; | ||||
| 2810 | return -d 't' ? 't/*.t' : ''; | ||||
| 2811 | } | ||||
| 2812 | |||||
| 2813 | =head3 find_tests_recursive | ||||
| 2814 | |||||
| 2815 | my $tests = $mm->find_tests_recursive; | ||||
| 2816 | |||||
| 2817 | Returns a string suitable for feeding to the shell to return all | ||||
| 2818 | tests in t/ but recursively. Equivalent to | ||||
| 2819 | |||||
| 2820 | my $tests = $mm->find_tests_recursive_in('t'); | ||||
| 2821 | |||||
| 2822 | =cut | ||||
| 2823 | |||||
| 2824 | sub find_tests_recursive { | ||||
| 2825 | my $self = shift; | ||||
| 2826 | return $self->find_tests_recursive_in('t'); | ||||
| 2827 | } | ||||
| 2828 | |||||
| 2829 | =head3 find_tests_recursive_in | ||||
| 2830 | |||||
| 2831 | my $tests = $mm->find_tests_recursive_in($dir); | ||||
| 2832 | |||||
| 2833 | Returns a string suitable for feeding to the shell to return all | ||||
| 2834 | tests in $dir recursively. | ||||
| 2835 | |||||
| 2836 | =cut | ||||
| 2837 | |||||
| 2838 | sub find_tests_recursive_in { | ||||
| 2839 | my($self, $dir) = @_; | ||||
| 2840 | return '' unless -d $dir; | ||||
| 2841 | |||||
| 2842 | require File::Find; | ||||
| 2843 | |||||
| 2844 | my $base_depth = grep { $_ ne '' } File::Spec->splitdir( (File::Spec->splitpath($dir))[1] ); | ||||
| 2845 | my %depths; | ||||
| 2846 | |||||
| 2847 | my $wanted = sub { | ||||
| 2848 | return unless m!\.t$!; | ||||
| 2849 | my ($volume,$directories,$file) = | ||||
| 2850 | File::Spec->splitpath( $File::Find::name ); | ||||
| 2851 | my $depth = grep { $_ ne '' } File::Spec->splitdir( $directories ); | ||||
| 2852 | $depth -= $base_depth; | ||||
| 2853 | $depths{ $depth } = 1; | ||||
| 2854 | }; | ||||
| 2855 | |||||
| 2856 | File::Find::find( $wanted, $dir ); | ||||
| 2857 | |||||
| 2858 | return join ' ', | ||||
| 2859 | map { $dir . '/*' x $_ . '.t' } | ||||
| 2860 | sort { $a <=> $b } | ||||
| 2861 | keys %depths; | ||||
| 2862 | } | ||||
| 2863 | |||||
| 2864 | =head3 extra_clean_files | ||||
| 2865 | |||||
| 2866 | my @files_to_clean = $MM->extra_clean_files; | ||||
| 2867 | |||||
| 2868 | Returns a list of OS specific files to be removed in the clean target in | ||||
| 2869 | addition to the usual set. | ||||
| 2870 | |||||
| 2871 | =cut | ||||
| 2872 | |||||
| 2873 | # An empty method here tickled a perl 5.8.1 bug and would return its object. | ||||
| 2874 | sub extra_clean_files { | ||||
| 2875 | return; | ||||
| 2876 | } | ||||
| 2877 | |||||
| 2878 | |||||
| 2879 | =head3 installvars | ||||
| 2880 | |||||
| 2881 | my @installvars = $mm->installvars; | ||||
| 2882 | |||||
| 2883 | A list of all the INSTALL* variables without the INSTALL prefix. Useful | ||||
| 2884 | for iteration or building related variable sets. | ||||
| 2885 | |||||
| 2886 | =cut | ||||
| 2887 | |||||
| 2888 | sub installvars { | ||||
| 2889 | return qw(PRIVLIB SITELIB VENDORLIB | ||||
| 2890 | ARCHLIB SITEARCH VENDORARCH | ||||
| 2891 | BIN SITEBIN VENDORBIN | ||||
| 2892 | SCRIPT SITESCRIPT VENDORSCRIPT | ||||
| 2893 | MAN1DIR SITEMAN1DIR VENDORMAN1DIR | ||||
| 2894 | MAN3DIR SITEMAN3DIR VENDORMAN3DIR | ||||
| 2895 | ); | ||||
| 2896 | } | ||||
| 2897 | |||||
| 2898 | |||||
| 2899 | =head3 libscan | ||||
| 2900 | |||||
| 2901 | my $wanted = $self->libscan($path); | ||||
| 2902 | |||||
| 2903 | Takes a path to a file or dir and returns an empty string if we don't | ||||
| 2904 | want to include this file in the library. Otherwise it returns the | ||||
| 2905 | the $path unchanged. | ||||
| 2906 | |||||
| 2907 | Mainly used to exclude version control administrative directories | ||||
| 2908 | and base-level F<README.pod> from installation. | ||||
| 2909 | |||||
| 2910 | =cut | ||||
| 2911 | |||||
| 2912 | sub libscan { | ||||
| 2913 | my($self,$path) = @_; | ||||
| 2914 | |||||
| 2915 | if ($path =~ m<^README\.pod$>i) { | ||||
| 2916 | warn "WARNING: Older versions of ExtUtils::MakeMaker may errantly install $path as part of this distribution. It is recommended to avoid using this path in CPAN modules.\n"; | ||||
| 2917 | return ''; | ||||
| 2918 | } | ||||
| 2919 | |||||
| 2920 | my($dirs,$file) = ($self->splitpath($path))[1,2]; | ||||
| 2921 | return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/, | ||||
| 2922 | $self->splitdir($dirs), $file; | ||||
| 2923 | |||||
| 2924 | return $path; | ||||
| 2925 | } | ||||
| 2926 | |||||
| 2927 | |||||
| 2928 | =head3 platform_constants | ||||
| 2929 | |||||
| 2930 | my $make_frag = $mm->platform_constants | ||||
| 2931 | |||||
| 2932 | Returns a make fragment defining all the macros initialized in | ||||
| 2933 | init_platform() rather than put them in constants(). | ||||
| 2934 | |||||
| 2935 | =cut | ||||
| 2936 | |||||
| 2937 | sub platform_constants { | ||||
| 2938 | return ''; | ||||
| 2939 | } | ||||
| 2940 | |||||
| 2941 | =head3 post_constants (o) | ||||
| 2942 | |||||
| 2943 | Returns an empty string per default. Dedicated to overrides from | ||||
| 2944 | within Makefile.PL after all constants have been defined. | ||||
| 2945 | |||||
| 2946 | =cut | ||||
| 2947 | |||||
| 2948 | sub post_constants { | ||||
| 2949 | ""; | ||||
| 2950 | } | ||||
| 2951 | |||||
| 2952 | =head3 post_initialize (o) | ||||
| 2953 | |||||
| 2954 | Returns an empty string per default. Used in Makefile.PLs to add some | ||||
| 2955 | chunk of text to the Makefile after the object is initialized. | ||||
| 2956 | |||||
| 2957 | =cut | ||||
| 2958 | |||||
| 2959 | sub post_initialize { | ||||
| 2960 | ""; | ||||
| 2961 | } | ||||
| 2962 | |||||
| 2963 | =head3 postamble (o) | ||||
| 2964 | |||||
| 2965 | Returns an empty string. Can be used in Makefile.PLs to write some | ||||
| 2966 | text to the Makefile at the end. | ||||
| 2967 | |||||
| 2968 | =cut | ||||
| 2969 | |||||
| 2970 | sub postamble { | ||||
| 2971 | ""; | ||||
| 2972 | } | ||||
| 2973 | |||||
| 2974 | =begin private | ||||
| 2975 | |||||
| 2976 | =head3 _PREREQ_PRINT | ||||
| 2977 | |||||
| 2978 | $self->_PREREQ_PRINT; | ||||
| 2979 | |||||
| 2980 | Implements PREREQ_PRINT. | ||||
| 2981 | |||||
| 2982 | Refactored out of MakeMaker->new(). | ||||
| 2983 | |||||
| 2984 | =end private | ||||
| 2985 | |||||
| 2986 | =cut | ||||
| 2987 | |||||
| 2988 | sub _PREREQ_PRINT { | ||||
| 2989 | my $self = shift; | ||||
| 2990 | |||||
| 2991 | require Data::Dumper; | ||||
| 2992 | my @what = ('PREREQ_PM'); | ||||
| 2993 | push @what, 'MIN_PERL_VERSION' if $self->{MIN_PERL_VERSION}; | ||||
| 2994 | push @what, 'BUILD_REQUIRES' if $self->{BUILD_REQUIRES}; | ||||
| 2995 | print Data::Dumper->Dump([@{$self}{@what}], \@what); | ||||
| 2996 | exit 0; | ||||
| 2997 | } | ||||
| 2998 | |||||
| 2999 | |||||
| 3000 | =begin private | ||||
| 3001 | |||||
| 3002 | =head3 _PRINT_PREREQ | ||||
| 3003 | |||||
| 3004 | $mm->_PRINT_PREREQ; | ||||
| 3005 | |||||
| 3006 | Implements PRINT_PREREQ, a slightly different version of PREREQ_PRINT | ||||
| 3007 | added by Redhat to, I think, support generating RPMs from Perl modules. | ||||
| 3008 | |||||
| 3009 | Should not include BUILD_REQUIRES as RPMs do not include them. | ||||
| 3010 | |||||
| 3011 | Refactored out of MakeMaker->new(). | ||||
| 3012 | |||||
| 3013 | =end private | ||||
| 3014 | |||||
| 3015 | =cut | ||||
| 3016 | |||||
| 3017 | sub _PRINT_PREREQ { | ||||
| 3018 | my $self = shift; | ||||
| 3019 | |||||
| 3020 | my $prereqs= $self->{PREREQ_PM}; | ||||
| 3021 | my @prereq = map { [$_, $prereqs->{$_}] } keys %$prereqs; | ||||
| 3022 | |||||
| 3023 | if ( $self->{MIN_PERL_VERSION} ) { | ||||
| 3024 | push @prereq, ['perl' => $self->{MIN_PERL_VERSION}]; | ||||
| 3025 | } | ||||
| 3026 | |||||
| 3027 | print join(" ", map { "perl($_->[0])>=$_->[1] " } | ||||
| 3028 | sort { $a->[0] cmp $b->[0] } @prereq), "\n"; | ||||
| 3029 | exit 0; | ||||
| 3030 | } | ||||
| 3031 | |||||
| 3032 | |||||
| 3033 | =begin private | ||||
| 3034 | |||||
| 3035 | =head3 _perl_header_files | ||||
| 3036 | |||||
| 3037 | my $perl_header_files= $self->_perl_header_files; | ||||
| 3038 | |||||
| 3039 | returns a sorted list of header files as found in PERL_SRC or $archlibexp/CORE. | ||||
| 3040 | |||||
| 3041 | Used by perldepend() in MM_Unix and MM_VMS via _perl_header_files_fragment() | ||||
| 3042 | |||||
| 3043 | =end private | ||||
| 3044 | |||||
| 3045 | =cut | ||||
| 3046 | |||||
| 3047 | sub _perl_header_files { | ||||
| 3048 | my $self = shift; | ||||
| 3049 | |||||
| 3050 | my $header_dir = $self->{PERL_SRC} || $ENV{PERL_SRC} || $self->catdir($Config{archlibexp}, 'CORE'); | ||||
| 3051 | opendir my $dh, $header_dir | ||||
| 3052 | or die "Failed to opendir '$header_dir' to find header files: $!"; | ||||
| 3053 | |||||
| 3054 | # we need to use a temporary here as the sort in scalar context would have undefined results. | ||||
| 3055 | my @perl_headers= sort grep { /\.h\z/ } readdir($dh); | ||||
| 3056 | |||||
| 3057 | closedir $dh; | ||||
| 3058 | |||||
| 3059 | return @perl_headers; | ||||
| 3060 | } | ||||
| 3061 | |||||
| 3062 | =begin private | ||||
| 3063 | |||||
| 3064 | =head3 _perl_header_files_fragment ($o, $separator) | ||||
| 3065 | |||||
| 3066 | my $perl_header_files_fragment= $self->_perl_header_files_fragment("/"); | ||||
| 3067 | |||||
| 3068 | return a Makefile fragment which holds the list of perl header files which | ||||
| 3069 | XS code depends on $(PERL_INC), and sets up the dependency for the $(OBJECT) file. | ||||
| 3070 | |||||
| 3071 | The $separator argument defaults to "". MM_VMS will set it to "" and MM_UNIX to "/" | ||||
| 3072 | in perldepend(). This reason child subclasses need to control this is that in | ||||
| 3073 | VMS the $(PERL_INC) directory will already have delimiters in it, but in | ||||
| 3074 | UNIX $(PERL_INC) will need a slash between it an the filename. Hypothetically | ||||
| 3075 | win32 could use "\\" (but it doesn't need to). | ||||
| 3076 | |||||
| 3077 | =end private | ||||
| 3078 | |||||
| 3079 | =cut | ||||
| 3080 | |||||
| 3081 | sub _perl_header_files_fragment { | ||||
| 3082 | my ($self, $separator)= @_; | ||||
| 3083 | $separator ||= ""; | ||||
| 3084 | return join("\\\n", | ||||
| 3085 | "PERL_HDRS = ", | ||||
| 3086 | map { | ||||
| 3087 | sprintf( " \$(PERL_INCDEP)%s%s ", $separator, $_ ) | ||||
| 3088 | } $self->_perl_header_files() | ||||
| 3089 | ) . "\n\n" | ||||
| 3090 | . "\$(OBJECT) : \$(PERL_HDRS)\n"; | ||||
| 3091 | } | ||||
| 3092 | |||||
| 3093 | |||||
| 3094 | =head1 AUTHOR | ||||
| 3095 | |||||
| 3096 | Michael G Schwern <schwern@pobox.com> and the denizens of | ||||
| 3097 | makemaker@perl.org with code from ExtUtils::MM_Unix and | ||||
| 3098 | ExtUtils::MM_Win32. | ||||
| 3099 | |||||
| 3100 | |||||
| 3101 | =cut | ||||
| 3102 | |||||
| 3103 | 1 | 8µs | 1; | ||
# spent 400ns within ExtUtils::MM_Any::__ANON__ which was called:
# once (400ns+0s) by ExtUtils::MM_Any::BEGIN@9 at line 9 |