Commit | Line | Data |
f6d6199c |
1 | package ExtUtils::MM_Any; |
2 | |
3 | use strict; |
8b19c1f8 |
4 | our $VERSION = '6.55_03'; |
f6d6199c |
5 | |
2977d345 |
6 | use Carp; |
f6d6199c |
7 | use File::Spec; |
5bdf71cc |
8 | use File::Basename; |
a592ba15 |
9 | BEGIN { our @ISA = qw(File::Spec); } |
7292dc67 |
10 | |
11 | # We need $Verbose |
12 | use ExtUtils::MakeMaker qw($Verbose); |
13 | |
14 | use ExtUtils::MakeMaker::Config; |
15 | |
16 | |
17 | # So we don't have to keep calling the methods over and over again, |
18 | # we have these globals to cache the values. Faster and shrtr. |
19 | my $Curdir = __PACKAGE__->curdir; |
20 | my $Rootdir = __PACKAGE__->rootdir; |
21 | my $Updir = __PACKAGE__->updir; |
f6d6199c |
22 | |
23 | |
24 | =head1 NAME |
25 | |
30361541 |
26 | ExtUtils::MM_Any - Platform-agnostic MM methods |
f6d6199c |
27 | |
28 | =head1 SYNOPSIS |
29 | |
30 | FOR INTERNAL USE ONLY! |
31 | |
32 | package ExtUtils::MM_SomeOS; |
33 | |
34 | # Temporarily, you have to subclass both. Put MM_Any first. |
35 | require ExtUtils::MM_Any; |
36 | require ExtUtils::MM_Unix; |
37 | @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix); |
38 | |
39 | =head1 DESCRIPTION |
40 | |
41 | B<FOR INTERNAL USE ONLY!> |
42 | |
43 | ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of |
44 | modules. It contains methods which are either inherently |
45 | cross-platform or are written in a cross-platform manner. |
46 | |
47 | Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix. This is a |
48 | temporary solution. |
49 | |
50 | B<THIS MAY BE TEMPORARY!> |
51 | |
f6d6199c |
52 | |
7292dc67 |
53 | =head1 METHODS |
f6d6199c |
54 | |
7292dc67 |
55 | Any methods marked I<Abstract> must be implemented by subclasses. |
dedf98bc |
56 | |
5e719f03 |
57 | |
7292dc67 |
58 | =head2 Cross-platform helper methods |
5e719f03 |
59 | |
7292dc67 |
60 | These are methods which help writing cross-platform code. |
5e719f03 |
61 | |
5e719f03 |
62 | |
5e719f03 |
63 | |
7292dc67 |
64 | =head3 os_flavor I<Abstract> |
65 | |
66 | my @os_flavor = $mm->os_flavor; |
67 | |
68 | @os_flavor is the style of operating system this is, usually |
69 | corresponding to the MM_*.pm file we're using. |
70 | |
71 | The first element of @os_flavor is the major family (ie. Unix, |
72 | Windows, VMS, OS/2, etc...) and the rest are sub families. |
73 | |
74 | Some examples: |
75 | |
76 | Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x') |
b6d6132c |
77 | Windows ('Win32') |
7292dc67 |
78 | Win98 ('Win32', 'Win9x') |
79 | Linux ('Unix', 'Linux') |
80 | MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X') |
81 | OS/2 ('OS/2') |
82 | |
83 | This is used to write code for styles of operating system. |
84 | See os_flavor_is() for use. |
85 | |
dedf98bc |
86 | |
7292dc67 |
87 | =head3 os_flavor_is |
88 | |
89 | my $is_this_flavor = $mm->os_flavor_is($this_flavor); |
90 | my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors); |
dedf98bc |
91 | |
92 | Checks to see if the current operating system is one of the given flavors. |
93 | |
94 | This is useful for code like: |
95 | |
96 | if( $mm->os_flavor_is('Unix') ) { |
97 | $out = `foo 2>&1`; |
98 | } |
99 | else { |
100 | $out = `foo`; |
101 | } |
102 | |
103 | =cut |
104 | |
105 | sub os_flavor_is { |
106 | my $self = shift; |
107 | my %flavors = map { ($_ => 1) } $self->os_flavor; |
108 | return (grep { $flavors{$_} } @_) ? 1 : 0; |
109 | } |
110 | |
5dca256e |
111 | |
c0956255 |
112 | =head3 can_load_xs |
113 | |
114 | my $can_load_xs = $self->can_load_xs; |
115 | |
116 | Returns true if we have the ability to load XS. |
117 | |
118 | This is important because miniperl, used to build XS modules in the |
119 | core, can not load XS. |
120 | |
121 | =cut |
122 | |
123 | sub can_load_xs { |
124 | return defined &DynaLoader::boot_DynaLoader ? 1 : 0; |
125 | } |
126 | |
127 | |
7292dc67 |
128 | =head3 split_command |
479d2113 |
129 | |
130 | my @cmds = $MM->split_command($cmd, @args); |
131 | |
132 | Most OS have a maximum command length they can execute at once. Large |
133 | modules can easily generate commands well past that limit. Its |
134 | necessary to split long commands up into a series of shorter commands. |
135 | |
7292dc67 |
136 | C<split_command> will return a series of @cmds each processing part of |
479d2113 |
137 | the args. Collectively they will process all the arguments. Each |
138 | individual line in @cmds will not be longer than the |
139 | $self->max_exec_len being careful to take into account macro expansion. |
140 | |
141 | $cmd should include any switches and repeated initial arguments. |
142 | |
143 | If no @args are given, no @cmds will be returned. |
144 | |
145 | Pairs of arguments will always be preserved in a single command, this |
146 | is a heuristic for things like pm_to_blib and pod2man which work on |
147 | pairs of arguments. This makes things like this safe: |
148 | |
149 | $self->split_command($cmd, %pod2man); |
150 | |
f6d6199c |
151 | |
152 | =cut |
153 | |
479d2113 |
154 | sub split_command { |
155 | my($self, $cmd, @args) = @_; |
156 | |
157 | my @cmds = (); |
158 | return(@cmds) unless @args; |
159 | |
160 | # If the command was given as a here-doc, there's probably a trailing |
161 | # newline. |
162 | chomp $cmd; |
163 | |
a592ba15 |
164 | # set aside 30% for macro expansion. |
165 | my $len_left = int($self->max_exec_len * 0.70); |
479d2113 |
166 | $len_left -= length $self->_expand_macros($cmd); |
167 | |
168 | do { |
169 | my $arg_str = ''; |
170 | my @next_args; |
171 | while( @next_args = splice(@args, 0, 2) ) { |
172 | # Two at a time to preserve pairs. |
173 | my $next_arg_str = "\t ". join ' ', @next_args, "\n"; |
174 | |
175 | if( !length $arg_str ) { |
176 | $arg_str .= $next_arg_str |
177 | } |
178 | elsif( length($arg_str) + length($next_arg_str) > $len_left ) { |
179 | unshift @args, @next_args; |
180 | last; |
181 | } |
182 | else { |
183 | $arg_str .= $next_arg_str; |
184 | } |
185 | } |
186 | chop $arg_str; |
187 | |
a7d1454b |
188 | push @cmds, $self->escape_newlines("$cmd \n$arg_str"); |
479d2113 |
189 | } while @args; |
190 | |
191 | return @cmds; |
f6d6199c |
192 | } |
193 | |
479d2113 |
194 | |
195 | sub _expand_macros { |
196 | my($self, $cmd) = @_; |
197 | |
198 | $cmd =~ s{\$\((\w+)\)}{ |
199 | defined $self->{$1} ? $self->{$1} : "\$($1)" |
200 | }e; |
201 | return $cmd; |
202 | } |
203 | |
204 | |
7292dc67 |
205 | =head3 echo |
479d2113 |
206 | |
207 | my @commands = $MM->echo($text); |
208 | my @commands = $MM->echo($text, $file); |
209 | my @commands = $MM->echo($text, $file, $appending); |
210 | |
211 | Generates a set of @commands which print the $text to a $file. |
212 | |
213 | If $file is not given, output goes to STDOUT. |
214 | |
215 | If $appending is true the $file will be appended to rather than |
216 | overwritten. |
f6d6199c |
217 | |
218 | =cut |
219 | |
479d2113 |
220 | sub echo { |
221 | my($self, $text, $file, $appending) = @_; |
222 | $appending ||= 0; |
223 | |
224 | my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) } |
225 | split /\n/, $text; |
226 | if( $file ) { |
227 | my $redirect = $appending ? '>>' : '>'; |
228 | $cmds[0] .= " $redirect $file"; |
229 | $_ .= " >> $file" foreach @cmds[1..$#cmds]; |
230 | } |
231 | |
232 | return @cmds; |
f6d6199c |
233 | } |
234 | |
479d2113 |
235 | |
7292dc67 |
236 | =head3 wraplist |
479d2113 |
237 | |
7292dc67 |
238 | my $args = $mm->wraplist(@list); |
479d2113 |
239 | |
7292dc67 |
240 | Takes an array of items and turns them into a well-formatted list of |
241 | arguments. In most cases this is simply something like: |
479d2113 |
242 | |
7292dc67 |
243 | FOO \ |
244 | BAR \ |
245 | BAZ |
479d2113 |
246 | |
7292dc67 |
247 | =cut |
479d2113 |
248 | |
7292dc67 |
249 | sub wraplist { |
250 | my $self = shift; |
251 | return join " \\\n\t", @_; |
252 | } |
479d2113 |
253 | |
479d2113 |
254 | |
6d6be53e |
255 | =head3 maketext_filter |
256 | |
257 | my $filter_make_text = $mm->maketext_filter($make_text); |
258 | |
259 | The text of the Makefile is run through this method before writing to |
260 | disk. It allows systems a chance to make portability fixes to the |
261 | Makefile. |
262 | |
263 | By default it does nothing. |
264 | |
265 | This method is protected and not intended to be called outside of |
266 | MakeMaker. |
267 | |
268 | =cut |
269 | |
270 | sub maketext_filter { return $_[1] } |
271 | |
272 | |
7292dc67 |
273 | =head3 cd I<Abstract> |
479d2113 |
274 | |
7292dc67 |
275 | my $subdir_cmd = $MM->cd($subdir, @cmds); |
479d2113 |
276 | |
7292dc67 |
277 | This will generate a make fragment which runs the @cmds in the given |
278 | $dir. The rough equivalent to this, except cross platform. |
479d2113 |
279 | |
7292dc67 |
280 | cd $subdir && $cmd |
479d2113 |
281 | |
7292dc67 |
282 | Currently $dir can only go down one level. "foo" is fine. "foo/bar" is |
283 | not. "../foo" is right out. |
479d2113 |
284 | |
7292dc67 |
285 | The resulting $subdir_cmd has no leading tab nor trailing newline. This |
286 | makes it easier to embed in a make string. For example. |
479d2113 |
287 | |
7292dc67 |
288 | my $make = sprintf <<'CODE', $subdir_cmd; |
289 | foo : |
290 | $(ECHO) what |
291 | %s |
292 | $(ECHO) mouche |
293 | CODE |
f6d6199c |
294 | |
f6d6199c |
295 | |
7292dc67 |
296 | =head3 oneliner I<Abstract> |
479d2113 |
297 | |
7292dc67 |
298 | my $oneliner = $MM->oneliner($perl_code); |
299 | my $oneliner = $MM->oneliner($perl_code, \@switches); |
479d2113 |
300 | |
7292dc67 |
301 | This will generate a perl one-liner safe for the particular platform |
302 | you're on based on the given $perl_code and @switches (a -e is |
303 | assumed) suitable for using in a make target. It will use the proper |
304 | shell quoting and escapes. |
479d2113 |
305 | |
7292dc67 |
306 | $(PERLRUN) will be used as perl. |
479d2113 |
307 | |
7292dc67 |
308 | Any newlines in $perl_code will be escaped. Leading and trailing |
309 | newlines will be stripped. Makes this idiom much easier: |
479d2113 |
310 | |
7292dc67 |
311 | my $code = $MM->oneliner(<<'CODE', [...switches...]); |
312 | some code here |
313 | another line here |
314 | CODE |
479d2113 |
315 | |
7292dc67 |
316 | Usage might be something like: |
479d2113 |
317 | |
7292dc67 |
318 | # an echo emulation |
319 | $oneliner = $MM->oneliner('print "Foo\n"'); |
320 | $make = '$oneliner > somefile'; |
479d2113 |
321 | |
7292dc67 |
322 | All dollar signs must be doubled in the $perl_code if you expect them |
323 | to be interpreted normally, otherwise it will be considered a make |
324 | macro. Also remember to quote make macros else it might be used as a |
325 | bareword. For example: |
479d2113 |
326 | |
7292dc67 |
327 | # Assign the value of the $(VERSION_FROM) make macro to $vf. |
328 | $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"'); |
f6d6199c |
329 | |
7292dc67 |
330 | Its currently very simple and may be expanded sometime in the figure |
331 | to include more flexible code and switches. |
479d2113 |
332 | |
479d2113 |
333 | |
7292dc67 |
334 | =head3 quote_literal I<Abstract> |
f6d6199c |
335 | |
7292dc67 |
336 | my $safe_text = $MM->quote_literal($text); |
f6d6199c |
337 | |
7292dc67 |
338 | This will quote $text so it is interpreted literally in the shell. |
f6d6199c |
339 | |
7292dc67 |
340 | For example, on Unix this would escape any single-quotes in $text and |
341 | put single-quotes around the whole thing. |
479d2113 |
342 | |
f6d6199c |
343 | |
7292dc67 |
344 | =head3 escape_newlines I<Abstract> |
f6d6199c |
345 | |
7292dc67 |
346 | my $escaped_text = $MM->escape_newlines($text); |
479d2113 |
347 | |
7292dc67 |
348 | Shell escapes newlines in $text. |
479d2113 |
349 | |
479d2113 |
350 | |
7292dc67 |
351 | =head3 max_exec_len I<Abstract> |
479d2113 |
352 | |
7292dc67 |
353 | my $max_exec_len = $MM->max_exec_len; |
479d2113 |
354 | |
7292dc67 |
355 | Calculates the maximum command size the OS can exec. Effectively, |
356 | this is the max size of a shell command line. |
479d2113 |
357 | |
7292dc67 |
358 | =for _private |
359 | $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes. |
f6d6199c |
360 | |
479d2113 |
361 | |
2977d345 |
362 | =head3 make |
479d2113 |
363 | |
2977d345 |
364 | my $make = $MM->make; |
365 | |
366 | Returns the make variant we're generating the Makefile for. This attempts |
367 | to do some normalization on the information from %Config or the user. |
368 | |
369 | =cut |
370 | |
371 | sub make { |
372 | my $self = shift; |
373 | |
1487aac6 |
374 | my $make = lc $self->{MAKE}; |
2977d345 |
375 | |
376 | # Truncate anything like foomake6 to just foomake. |
377 | $make =~ s/^(\w+make).*/$1/; |
378 | |
379 | # Turn gnumake into gmake. |
380 | $make =~ s/^gnu/g/; |
381 | |
382 | return $make; |
383 | } |
479d2113 |
384 | |
f6d6199c |
385 | |
7292dc67 |
386 | =head2 Targets |
f6d6199c |
387 | |
7292dc67 |
388 | These are methods which produce make targets. |
479d2113 |
389 | |
479d2113 |
390 | |
7292dc67 |
391 | =head3 all_target |
479d2113 |
392 | |
7292dc67 |
393 | Generate the default target 'all'. |
479d2113 |
394 | |
7292dc67 |
395 | =cut |
479d2113 |
396 | |
7292dc67 |
397 | sub all_target { |
398 | my $self = shift; |
479d2113 |
399 | |
7292dc67 |
400 | return <<'MAKE_EXT'; |
401 | all :: pure_all |
402 | $(NOECHO) $(NOOP) |
403 | MAKE_EXT |
479d2113 |
404 | |
f6d6199c |
405 | } |
406 | |
479d2113 |
407 | |
7292dc67 |
408 | =head3 blibdirs_target |
479d2113 |
409 | |
7292dc67 |
410 | my $make_frag = $mm->blibdirs_target; |
479d2113 |
411 | |
7292dc67 |
412 | Creates the blibdirs target which creates all the directories we use |
413 | in blib/. |
f6d6199c |
414 | |
7292dc67 |
415 | The blibdirs.ts target is deprecated. Depend on blibdirs instead. |
f6d6199c |
416 | |
479d2113 |
417 | |
7292dc67 |
418 | =cut |
419 | |
420 | sub blibdirs_target { |
421 | my $self = shift; |
422 | |
423 | my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib |
424 | autodir archautodir |
425 | bin script |
426 | man1dir man3dir |
427 | ); |
f6d6199c |
428 | |
7292dc67 |
429 | my @exists = map { $_.'$(DFSEP).exists' } @dirs; |
479d2113 |
430 | |
7292dc67 |
431 | my $make = sprintf <<'MAKE', join(' ', @exists); |
432 | blibdirs : %s |
433 | $(NOECHO) $(NOOP) |
479d2113 |
434 | |
7292dc67 |
435 | # Backwards compat with 6.18 through 6.25 |
436 | blibdirs.ts : blibdirs |
437 | $(NOECHO) $(NOOP) |
479d2113 |
438 | |
7292dc67 |
439 | MAKE |
440 | |
441 | $make .= $self->dir_target(@dirs); |
442 | |
443 | return $make; |
444 | } |
445 | |
446 | |
447 | =head3 clean (o) |
448 | |
449 | Defines the clean target. |
f6d6199c |
450 | |
451 | =cut |
452 | |
7292dc67 |
453 | sub clean { |
454 | # --- Cleanup and Distribution Sections --- |
479d2113 |
455 | |
7292dc67 |
456 | my($self, %attribs) = @_; |
457 | my @m; |
458 | push(@m, ' |
459 | # Delete temporary files but do not touch installed files. We don\'t delete |
460 | # the Makefile here so a later make realclean still has a makefile to use. |
461 | |
462 | clean :: clean_subdirs |
463 | '); |
464 | |
465 | my @files = values %{$self->{XS}}; # .c files from *.xs files |
466 | my @dirs = qw(blib); |
467 | |
468 | # Normally these are all under blib but they might have been |
469 | # redefined. |
470 | # XXX normally this would be a good idea, but the Perl core sets |
471 | # INST_LIB = ../../lib rather than actually installing the files. |
472 | # So a "make clean" in an ext/ directory would blow away lib. |
473 | # Until the core is adjusted let's leave this out. |
474 | # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB) |
475 | # $(INST_BIN) $(INST_SCRIPT) |
476 | # $(INST_MAN1DIR) $(INST_MAN3DIR) |
477 | # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR) |
478 | # $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT) |
479 | # ); |
480 | |
481 | |
482 | if( $attribs{FILES} ) { |
483 | # Use @dirs because we don't know what's in here. |
484 | push @dirs, ref $attribs{FILES} ? |
485 | @{$attribs{FILES}} : |
486 | split /\s+/, $attribs{FILES} ; |
487 | } |
479d2113 |
488 | |
7292dc67 |
489 | push(@files, qw[$(MAKE_APERL_FILE) |
490 | perlmain.c tmon.out mon.out so_locations |
491 | blibdirs.ts pm_to_blib pm_to_blib.ts |
492 | *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT) |
493 | $(BOOTSTRAP) $(BASEEXT).bso |
494 | $(BASEEXT).def lib$(BASEEXT).def |
495 | $(BASEEXT).exp $(BASEEXT).x |
496 | ]); |
479d2113 |
497 | |
7292dc67 |
498 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all')); |
499 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld')); |
479d2113 |
500 | |
7292dc67 |
501 | # core files |
502 | push(@files, qw[core core.*perl.*.? *perl.core]); |
503 | push(@files, map { "core." . "[0-9]"x$_ } (1..5)); |
479d2113 |
504 | |
7292dc67 |
505 | # OS specific things to clean up. Use @dirs since we don't know |
506 | # what might be in here. |
507 | push @dirs, $self->extra_clean_files; |
f6d6199c |
508 | |
7292dc67 |
509 | # Occasionally files are repeated several times from different sources |
510 | { my(%f) = map { ($_ => 1) } @files; @files = keys %f; } |
511 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; } |
f6d6199c |
512 | |
7292dc67 |
513 | push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files); |
514 | push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs); |
f6d6199c |
515 | |
7292dc67 |
516 | # Leave Makefile.old around for realclean |
517 | push @m, <<'MAKE'; |
518 | - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL) |
519 | MAKE |
479d2113 |
520 | |
7292dc67 |
521 | push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP}; |
479d2113 |
522 | |
7292dc67 |
523 | join("", @m); |
524 | } |
525 | |
526 | |
527 | =head3 clean_subdirs_target |
528 | |
529 | my $make_frag = $MM->clean_subdirs_target; |
530 | |
531 | Returns the clean_subdirs target. This is used by the clean target to |
532 | call clean on any subdirectories which contain Makefiles. |
479d2113 |
533 | |
534 | =cut |
535 | |
7292dc67 |
536 | sub clean_subdirs_target { |
537 | my($self) = shift; |
479d2113 |
538 | |
7292dc67 |
539 | # No subdirectories, no cleaning. |
540 | return <<'NOOP_FRAG' unless @{$self->{DIR}}; |
541 | clean_subdirs : |
542 | $(NOECHO) $(NOOP) |
543 | NOOP_FRAG |
544 | |
545 | |
546 | my $clean = "clean_subdirs :\n"; |
547 | |
548 | for my $dir (@{$self->{DIR}}) { |
549 | my $subclean = $self->oneliner(sprintf <<'CODE', $dir); |
550 | chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)'; |
551 | CODE |
552 | |
553 | $clean .= "\t$subclean\n"; |
554 | } |
555 | |
556 | return $clean; |
479d2113 |
557 | } |
f6d6199c |
558 | |
f6d6199c |
559 | |
7292dc67 |
560 | =head3 dir_target |
f6d6199c |
561 | |
7292dc67 |
562 | my $make_frag = $mm->dir_target(@directories); |
f6d6199c |
563 | |
7292dc67 |
564 | Generates targets to create the specified directories and set its |
5bdf71cc |
565 | permission to PERM_DIR. |
f6d6199c |
566 | |
7292dc67 |
567 | Because depending on a directory to just ensure it exists doesn't work |
568 | too well (the modified time changes too often) dir_target() creates a |
569 | .exists file in the created directory. It is this you should depend on. |
570 | For portability purposes you should use the $(DIRFILESEP) macro rather |
571 | than a '/' to seperate the directory from the file. |
572 | |
573 | yourdirectory$(DIRFILESEP).exists |
f6d6199c |
574 | |
575 | =cut |
576 | |
7292dc67 |
577 | sub dir_target { |
578 | my($self, @dirs) = @_; |
f6d6199c |
579 | |
7292dc67 |
580 | my $make = ''; |
581 | foreach my $dir (@dirs) { |
582 | $make .= sprintf <<'MAKE', ($dir) x 7; |
087dded7 |
583 | %s$(DFSEP).exists :: Makefile.PL |
7292dc67 |
584 | $(NOECHO) $(MKPATH) %s |
5bdf71cc |
585 | $(NOECHO) $(CHMOD) $(PERM_DIR) %s |
7292dc67 |
586 | $(NOECHO) $(TOUCH) %s$(DFSEP).exists |
f6d6199c |
587 | |
7292dc67 |
588 | MAKE |
f6d6199c |
589 | |
7292dc67 |
590 | } |
f6d6199c |
591 | |
7292dc67 |
592 | return $make; |
593 | } |
f6d6199c |
594 | |
7292dc67 |
595 | |
596 | =head3 distdir |
597 | |
598 | Defines the scratch directory target that will hold the distribution |
599 | before tar-ing (or shar-ing). |
f6d6199c |
600 | |
601 | =cut |
602 | |
7292dc67 |
603 | # For backwards compatibility. |
604 | *dist_dir = *distdir; |
f6d6199c |
605 | |
7292dc67 |
606 | sub distdir { |
607 | my($self) = shift; |
479d2113 |
608 | |
7292dc67 |
609 | my $meta_target = $self->{NO_META} ? '' : 'distmeta'; |
610 | my $sign_target = !$self->{SIGN} ? '' : 'distsignature'; |
479d2113 |
611 | |
7292dc67 |
612 | return sprintf <<'MAKE_FRAG', $meta_target, $sign_target; |
613 | create_distdir : |
614 | $(RM_RF) $(DISTVNAME) |
615 | $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \ |
616 | -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');" |
479d2113 |
617 | |
7292dc67 |
618 | distdir : create_distdir %s %s |
619 | $(NOECHO) $(NOOP) |
620 | |
621 | MAKE_FRAG |
622 | |
623 | } |
624 | |
625 | |
626 | =head3 dist_test |
627 | |
628 | Defines a target that produces the distribution in the |
629 | scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that |
630 | subdirectory. |
479d2113 |
631 | |
632 | =cut |
633 | |
7292dc67 |
634 | sub dist_test { |
635 | my($self) = shift; |
636 | |
637 | my $mpl_args = join " ", map qq["$_"], @ARGV; |
638 | |
639 | my $test = $self->cd('$(DISTVNAME)', |
640 | '$(ABSPERLRUN) Makefile.PL '.$mpl_args, |
641 | '$(MAKE) $(PASTHRU)', |
642 | '$(MAKE) test $(PASTHRU)' |
643 | ); |
644 | |
645 | return sprintf <<'MAKE_FRAG', $test; |
646 | disttest : distdir |
647 | %s |
648 | |
649 | MAKE_FRAG |
650 | |
479d2113 |
651 | |
479d2113 |
652 | } |
653 | |
479d2113 |
654 | |
7292dc67 |
655 | =head3 dynamic (o) |
656 | |
657 | Defines the dynamic target. |
479d2113 |
658 | |
659 | =cut |
660 | |
7292dc67 |
661 | sub dynamic { |
662 | # --- Dynamic Loading Sections --- |
479d2113 |
663 | |
7292dc67 |
664 | my($self) = shift; |
665 | ' |
666 | dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT) |
667 | $(NOECHO) $(NOOP) |
668 | '; |
669 | } |
479d2113 |
670 | |
479d2113 |
671 | |
7292dc67 |
672 | =head3 makemakerdflt_target |
673 | |
674 | my $make_frag = $mm->makemakerdflt_target |
675 | |
676 | Returns a make fragment with the makemakerdeflt_target specified. |
677 | This target is the first target in the Makefile, is the default target |
678 | and simply points off to 'all' just in case any make variant gets |
679 | confused or something gets snuck in before the real 'all' target. |
479d2113 |
680 | |
7292dc67 |
681 | =cut |
682 | |
683 | sub makemakerdflt_target { |
684 | return <<'MAKE_FRAG'; |
3a0105ce |
685 | makemakerdflt : all |
7292dc67 |
686 | $(NOECHO) $(NOOP) |
479d2113 |
687 | MAKE_FRAG |
688 | |
689 | } |
690 | |
691 | |
7292dc67 |
692 | =head3 manifypods_target |
479d2113 |
693 | |
7292dc67 |
694 | my $manifypods_target = $self->manifypods_target; |
695 | |
696 | Generates the manifypods target. This target generates man pages from |
697 | all POD files in MAN1PODS and MAN3PODS. |
479d2113 |
698 | |
699 | =cut |
700 | |
7292dc67 |
701 | sub manifypods_target { |
702 | my($self) = shift; |
479d2113 |
703 | |
7292dc67 |
704 | my $man1pods = ''; |
705 | my $man3pods = ''; |
706 | my $dependencies = ''; |
707 | |
708 | # populate manXpods & dependencies: |
709 | foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) { |
710 | $dependencies .= " \\\n\t$name"; |
711 | } |
712 | |
7292dc67 |
713 | my $manify = <<END; |
714 | manifypods : pure_all $dependencies |
715 | END |
716 | |
717 | my @man_cmds; |
718 | foreach my $section (qw(1 3)) { |
719 | my $pods = $self->{"MAN${section}PODS"}; |
720 | push @man_cmds, $self->split_command(<<CMD, %$pods); |
721 | \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW) |
722 | CMD |
723 | } |
724 | |
725 | $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds; |
726 | $manify .= join '', map { "$_\n" } @man_cmds; |
479d2113 |
727 | |
7292dc67 |
728 | return $manify; |
479d2113 |
729 | } |
730 | |
731 | |
7292dc67 |
732 | =head3 metafile_target |
479d2113 |
733 | |
734 | my $target = $mm->metafile_target; |
735 | |
736 | Generate the metafile target. |
737 | |
7292dc67 |
738 | Writes the file META.yml YAML encoded meta-data about the module in |
739 | the distdir. The format follows Module::Build's as closely as |
562c8117 |
740 | possible. |
479d2113 |
741 | |
742 | =cut |
743 | |
744 | sub metafile_target { |
745 | my $self = shift; |
746 | |
431b0fc4 |
747 | return <<'MAKE_FRAG' if $self->{NO_META}; |
3a0105ce |
748 | metafile : |
431b0fc4 |
749 | $(NOECHO) $(NOOP) |
750 | MAKE_FRAG |
751 | |
2e65e370 |
752 | my @metadata = $self->metafile_data( |
753 | $self->{META_ADD} || {}, |
754 | $self->{META_MERGE} || {}, |
755 | ); |
756 | my $meta = $self->metafile_file(@metadata); |
757 | my @write_meta = $self->echo($meta, 'META_new.yml'); |
758 | |
759 | return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta); |
760 | metafile : create_distdir |
761 | $(NOECHO) $(ECHO) Generating META.yml |
762 | %s |
763 | -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml |
764 | MAKE_FRAG |
765 | |
766 | } |
767 | |
768 | |
769 | =begin private |
770 | |
771 | =head3 _sort_pairs |
772 | |
773 | my @pairs = _sort_pairs($sort_sub, \%hash); |
774 | |
775 | Sorts the pairs of a hash based on keys ordered according |
776 | to C<$sort_sub>. |
777 | |
778 | =end private |
779 | |
780 | =cut |
781 | |
782 | sub _sort_pairs { |
783 | my $sort = shift; |
784 | my $pairs = shift; |
785 | return map { $_ => $pairs->{$_} } |
786 | sort $sort |
787 | keys %$pairs; |
788 | } |
789 | |
790 | |
791 | # Taken from Module::Build::Base |
792 | sub _hash_merge { |
793 | my ($self, $h, $k, $v) = @_; |
794 | if (ref $h->{$k} eq 'ARRAY') { |
795 | push @{$h->{$k}}, ref $v ? @$v : $v; |
796 | } elsif (ref $h->{$k} eq 'HASH') { |
797 | $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v; |
798 | } else { |
799 | $h->{$k} = $v; |
479d2113 |
800 | } |
2e65e370 |
801 | } |
a7d1454b |
802 | |
c8d65f10 |
803 | |
2e65e370 |
804 | =head3 metafile_data |
805 | |
806 | my @metadata_pairs = $mm->metafile_data(\%meta_add, \%meta_merge); |
807 | |
808 | Returns the data which MakeMaker turns into the META.yml file. |
809 | |
810 | Values of %meta_add will overwrite any existing metadata in those |
811 | keys. %meta_merge will be merged with them. |
812 | |
813 | =cut |
814 | |
815 | sub metafile_data { |
816 | my $self = shift; |
817 | my($meta_add, $meta_merge) = @_; |
818 | |
819 | # The order in which standard meta keys should be written. |
820 | my @meta_order = qw( |
821 | name |
822 | version |
823 | abstract |
824 | author |
825 | license |
826 | distribution_type |
827 | |
828 | configure_requires |
829 | build_requires |
830 | requires |
831 | |
832 | resources |
833 | |
834 | provides |
835 | no_index |
836 | |
837 | generated_by |
838 | meta-spec |
839 | ); |
840 | |
b6d6132c |
841 | # Check the original args so we can tell between the user setting it |
842 | # to an empty hash and it just being initialized. |
5bdf71cc |
843 | my $configure_requires; |
b6d6132c |
844 | if( $self->{ARGS}{CONFIGURE_REQUIRES} ) { |
5bdf71cc |
845 | $configure_requires = $self->{CONFIGURE_REQUIRES}; |
846 | } else { |
847 | $configure_requires = { |
848 | 'ExtUtils::MakeMaker' => 0, |
849 | }; |
850 | } |
b6d6132c |
851 | my $build_requires; |
852 | if( $self->{ARGS}{BUILD_REQUIRES} ) { |
853 | $build_requires = $self->{BUILD_REQUIRES}; |
854 | } else { |
855 | $build_requires = { |
856 | 'ExtUtils::MakeMaker' => 0, |
857 | }; |
858 | } |
5bdf71cc |
859 | |
2e65e370 |
860 | my %meta = ( |
2977d345 |
861 | name => $self->{DISTNAME}, |
862 | version => $self->{VERSION}, |
863 | abstract => $self->{ABSTRACT}, |
2e65e370 |
864 | license => $self->{LICENSE} || 'unknown', |
2977d345 |
865 | distribution_type => $self->{PM} ? 'module' : 'script', |
2e65e370 |
866 | |
5bdf71cc |
867 | configure_requires => $configure_requires, |
2e65e370 |
868 | |
b6d6132c |
869 | build_requires => $build_requires, |
1487aac6 |
870 | |
2e65e370 |
871 | no_index => { |
872 | directory => [qw(t inc)] |
873 | }, |
874 | |
875 | generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION", |
876 | 'meta-spec' => { |
877 | url => 'http://module-build.sourceforge.net/META-spec-v1.4.html', |
878 | version => 1.4 |
879 | }, |
2977d345 |
880 | ); |
bf87a6a1 |
881 | |
882 | # The author key is required and it takes a list. |
2e65e370 |
883 | $meta{author} = defined $self->{AUTHOR} ? [$self->{AUTHOR}] : []; |
bf87a6a1 |
884 | |
2e65e370 |
885 | $meta{requires} = $self->{PREREQ_PM} if defined $self->{PREREQ_PM}; |
bf87a6a1 |
886 | $meta{requires}{perl} = $self->{MIN_PERL_VERSION} if $self->{MIN_PERL_VERSION}; |
2977d345 |
887 | |
2e65e370 |
888 | while( my($key, $val) = each %$meta_add ) { |
889 | $meta{$key} = $val; |
890 | } |
2977d345 |
891 | |
2e65e370 |
892 | while( my($key, $val) = each %$meta_merge ) { |
893 | $self->_hash_merge(\%meta, $key, $val); |
894 | } |
2977d345 |
895 | |
2e65e370 |
896 | my @meta_pairs; |
897 | |
898 | # Put the standard keys first in the proper order. |
899 | for my $key (@meta_order) { |
900 | next unless exists $meta{$key}; |
901 | |
902 | push @meta_pairs, $key, delete $meta{$key}; |
903 | } |
904 | |
905 | # Then tack everything else onto the end, alpha sorted. |
906 | for my $key (sort {lc $a cmp lc $b} keys %meta) { |
907 | push @meta_pairs, $key, $meta{$key}; |
908 | } |
909 | |
910 | return @meta_pairs |
911 | } |
2977d345 |
912 | |
2e65e370 |
913 | =begin private |
914 | |
915 | =head3 _dump_hash |
916 | |
917 | $yaml = _dump_hash(\%options, %hash); |
918 | |
919 | Implements a fake YAML dumper for a hash given |
920 | as a list of pairs. No quoting/escaping is done. Keys |
921 | are supposed to be strings. Values are undef, strings, |
922 | hash refs or array refs of strings. |
923 | |
924 | Supported options are: |
925 | |
926 | delta => STR - indentation delta |
927 | use_header => BOOL - whether to include a YAML header |
928 | indent => STR - a string of spaces |
929 | default: '' |
930 | |
931 | max_key_length => INT - maximum key length used to align |
932 | keys and values of the same hash |
933 | default: 20 |
934 | key_sort => CODE - a sort sub |
935 | It may be undef, which means no sorting by keys |
936 | default: sub { lc $a cmp lc $b } |
937 | |
938 | customs => HASH - special options for certain keys |
939 | (whose values are hashes themselves) |
940 | may contain: max_key_length, key_sort, customs |
941 | |
942 | =end private |
943 | |
944 | =cut |
945 | |
946 | sub _dump_hash { |
947 | croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH'; |
948 | my $options = shift; |
949 | my %hash = @_; |
950 | |
951 | # Use a list to preserve order. |
952 | my @pairs; |
953 | |
954 | my $k_sort |
955 | = exists $options->{key_sort} ? $options->{key_sort} |
956 | : sub { lc $a cmp lc $b }; |
957 | if ($k_sort) { |
958 | croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE'; |
959 | @pairs = _sort_pairs($k_sort, \%hash); |
960 | } else { # list of pairs, no sorting |
961 | @pairs = @_; |
962 | } |
963 | |
964 | my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : ''; |
965 | my $indent = $options->{indent} || ''; |
966 | my $k_length = min( |
967 | ($options->{max_key_length} || 20), |
968 | max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash) |
969 | ); |
970 | my $customs = $options->{customs} || {}; |
971 | |
972 | # printf format for key |
973 | my $k_format = "%-${k_length}s"; |
974 | |
975 | while( @pairs ) { |
976 | my($key, $val) = splice @pairs, 0, 2; |
977 | $val = '~' unless defined $val; |
978 | if(ref $val eq 'HASH') { |
979 | if ( keys %$val ) { |
980 | my %k_options = ( # options for recursive call |
981 | delta => $options->{delta}, |
982 | use_header => 0, |
983 | indent => $indent . $options->{delta}, |
984 | ); |
985 | if (exists $customs->{$key}) { |
986 | my %k_custom = %{$customs->{$key}}; |
987 | foreach my $k qw(key_sort max_key_length customs) { |
988 | $k_options{$k} = $k_custom{$k} if exists $k_custom{$k}; |
989 | } |
990 | } |
991 | $yaml .= $indent . "$key:\n" |
992 | . _dump_hash(\%k_options, %$val); |
993 | } |
994 | else { |
995 | $yaml .= $indent . "$key: {}\n"; |
996 | } |
997 | } |
998 | elsif (ref $val eq 'ARRAY') { |
999 | if( @$val ) { |
1000 | $yaml .= $indent . "$key:\n"; |
1001 | |
1002 | for (@$val) { |
1003 | croak "only nested arrays of non-refs are supported" if ref $_; |
1004 | $yaml .= $indent . $options->{delta} . "- $_\n"; |
1005 | } |
1006 | } |
1007 | else { |
1008 | $yaml .= $indent . "$key: []\n"; |
1009 | } |
1010 | } |
1011 | elsif( ref $val and !blessed($val) ) { |
1012 | croak "only nested hashes, arrays and objects are supported"; |
1013 | } |
1014 | else { # if it's an object, just stringify it |
1015 | $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val; |
1016 | } |
2977d345 |
1017 | }; |
1018 | |
2e65e370 |
1019 | return $yaml; |
479d2113 |
1020 | |
2e65e370 |
1021 | } |
2977d345 |
1022 | |
2e65e370 |
1023 | sub blessed { |
1024 | return eval { $_[0]->isa("UNIVERSAL"); }; |
1025 | } |
a7d1454b |
1026 | |
2e65e370 |
1027 | sub max { |
1028 | return (sort { $b <=> $a } @_)[0]; |
1029 | } |
1030 | |
1031 | sub min { |
1032 | return (sort { $a <=> $b } @_)[0]; |
1033 | } |
1034 | |
1035 | =head3 metafile_file |
1036 | |
1037 | my $meta_yml = $mm->metafile_file(@metadata_pairs); |
1038 | |
1039 | Turns the @metadata_pairs into YAML. |
1040 | |
1041 | This method does not implement a complete YAML dumper, being limited |
1042 | to dump a hash with values which are strings, undef's or nested hashes |
1043 | and arrays of strings. No quoting/escaping is done. |
1044 | |
1045 | =cut |
1046 | |
1047 | sub metafile_file { |
1048 | my $self = shift; |
1049 | |
1050 | my %dump_options = ( |
1051 | use_header => 1, |
1052 | delta => ' ' x 4, |
1053 | key_sort => undef, |
1054 | ); |
1055 | return _dump_hash(\%dump_options, @_); |
479d2113 |
1056 | |
1057 | } |
1058 | |
1059 | |
7292dc67 |
1060 | =head3 distmeta_target |
bb68fe9e |
1061 | |
7292dc67 |
1062 | my $make_frag = $mm->distmeta_target; |
bb68fe9e |
1063 | |
7292dc67 |
1064 | Generates the distmeta target to add META.yml to the MANIFEST in the |
1065 | distdir. |
bb68fe9e |
1066 | |
1067 | =cut |
1068 | |
7292dc67 |
1069 | sub distmeta_target { |
bb68fe9e |
1070 | my $self = shift; |
1071 | |
7292dc67 |
1072 | my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']); |
1073 | eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) } |
1074 | or print "Could not add META.yml to MANIFEST: $${'@'}\n" |
1075 | CODE |
bb68fe9e |
1076 | |
7292dc67 |
1077 | my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta); |
bb68fe9e |
1078 | |
7292dc67 |
1079 | return sprintf <<'MAKE', $add_meta_to_distdir; |
1080 | distmeta : create_distdir metafile |
1081 | $(NOECHO) %s |
1082 | |
1083 | MAKE |
bb68fe9e |
1084 | |
7292dc67 |
1085 | } |
bb68fe9e |
1086 | |
479d2113 |
1087 | |
7292dc67 |
1088 | =head3 realclean (o) |
479d2113 |
1089 | |
7292dc67 |
1090 | Defines the realclean target. |
479d2113 |
1091 | |
1092 | =cut |
1093 | |
7292dc67 |
1094 | sub realclean { |
1095 | my($self, %attribs) = @_; |
479d2113 |
1096 | |
7292dc67 |
1097 | my @dirs = qw($(DISTVNAME)); |
1098 | my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD)); |
431b0fc4 |
1099 | |
76ca89ed |
1100 | # Special exception for the perl core where INST_* is not in blib. |
1101 | # This cleans up the files built from the ext/ directory (all XS). |
1102 | if( $self->{PERL_CORE} ) { |
7292dc67 |
1103 | push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR)); |
76ca89ed |
1104 | push @files, values %{$self->{PM}}; |
7292dc67 |
1105 | } |
479d2113 |
1106 | |
7292dc67 |
1107 | if( $self->has_link_code ){ |
1108 | push @files, qw($(OBJECT)); |
1109 | } |
1110 | |
1111 | if( $attribs{FILES} ) { |
1112 | if( ref $attribs{FILES} ) { |
1113 | push @dirs, @{ $attribs{FILES} }; |
1114 | } |
1115 | else { |
1116 | push @dirs, split /\s+/, $attribs{FILES}; |
1117 | } |
1118 | } |
1119 | |
1120 | # Occasionally files are repeated several times from different sources |
1121 | { my(%f) = map { ($_ => 1) } @files; @files = keys %f; } |
1122 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; } |
1123 | |
1124 | my $rm_cmd = join "\n\t", map { "$_" } |
1125 | $self->split_command('- $(RM_F)', @files); |
1126 | my $rmf_cmd = join "\n\t", map { "$_" } |
1127 | $self->split_command('- $(RM_RF)', @dirs); |
1128 | |
1129 | my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd; |
1130 | # Delete temporary files (via clean) and also delete dist files |
1131 | realclean purge :: clean realclean_subdirs |
1132 | %s |
1133 | %s |
1134 | MAKE |
1135 | |
1136 | $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP}; |
479d2113 |
1137 | |
7292dc67 |
1138 | return $m; |
479d2113 |
1139 | } |
1140 | |
1141 | |
7292dc67 |
1142 | =head3 realclean_subdirs_target |
bb68fe9e |
1143 | |
7292dc67 |
1144 | my $make_frag = $MM->realclean_subdirs_target; |
bb68fe9e |
1145 | |
7292dc67 |
1146 | Returns the realclean_subdirs target. This is used by the realclean |
1147 | target to call realclean on any subdirectories which contain Makefiles. |
bb68fe9e |
1148 | |
1149 | =cut |
1150 | |
7292dc67 |
1151 | sub realclean_subdirs_target { |
bb68fe9e |
1152 | my $self = shift; |
1153 | |
7292dc67 |
1154 | return <<'NOOP_FRAG' unless @{$self->{DIR}}; |
1155 | realclean_subdirs : |
bb68fe9e |
1156 | $(NOECHO) $(NOOP) |
7292dc67 |
1157 | NOOP_FRAG |
bb68fe9e |
1158 | |
7292dc67 |
1159 | my $rclean = "realclean_subdirs :\n"; |
1160 | |
1161 | foreach my $dir (@{$self->{DIR}}) { |
1162 | foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) { |
1163 | my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2); |
1164 | chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s'; |
bb68fe9e |
1165 | CODE |
1166 | |
7292dc67 |
1167 | $rclean .= sprintf <<'RCLEAN', $subrclean; |
1168 | - %s |
1169 | RCLEAN |
bb68fe9e |
1170 | |
7292dc67 |
1171 | } |
1172 | } |
bb68fe9e |
1173 | |
7292dc67 |
1174 | return $rclean; |
1175 | } |
bb68fe9e |
1176 | |
479d2113 |
1177 | |
7292dc67 |
1178 | =head3 signature_target |
479d2113 |
1179 | |
7292dc67 |
1180 | my $target = $mm->signature_target; |
479d2113 |
1181 | |
7292dc67 |
1182 | Generate the signature target. |
479d2113 |
1183 | |
7292dc67 |
1184 | Writes the file SIGNATURE with "cpansign -s". |
479d2113 |
1185 | |
7292dc67 |
1186 | =cut |
479d2113 |
1187 | |
7292dc67 |
1188 | sub signature_target { |
1189 | my $self = shift; |
479d2113 |
1190 | |
7292dc67 |
1191 | return <<'MAKE_FRAG'; |
1192 | signature : |
1193 | cpansign -s |
1194 | MAKE_FRAG |
479d2113 |
1195 | |
7292dc67 |
1196 | } |
479d2113 |
1197 | |
7292dc67 |
1198 | |
1199 | =head3 distsignature_target |
1200 | |
1201 | my $make_frag = $mm->distsignature_target; |
1202 | |
1203 | Generates the distsignature target to add SIGNATURE to the MANIFEST in the |
1204 | distdir. |
1205 | |
1206 | =cut |
1207 | |
1208 | sub distsignature_target { |
1209 | my $self = shift; |
1210 | |
1211 | my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']); |
1212 | eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } |
1213 | or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n" |
479d2113 |
1214 | CODE |
1215 | |
7292dc67 |
1216 | my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s'); |
479d2113 |
1217 | |
7292dc67 |
1218 | # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not |
1219 | # exist |
1220 | my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE'); |
1221 | my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign ); |
479d2113 |
1222 | |
7292dc67 |
1223 | return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist |
1224 | distsignature : create_distdir |
1225 | $(NOECHO) %s |
1226 | $(NOECHO) %s |
1227 | %s |
479d2113 |
1228 | |
7292dc67 |
1229 | MAKE |
479d2113 |
1230 | |
7292dc67 |
1231 | } |
479d2113 |
1232 | |
1233 | |
7292dc67 |
1234 | =head3 special_targets |
479d2113 |
1235 | |
7292dc67 |
1236 | my $make_frag = $mm->special_targets |
479d2113 |
1237 | |
7292dc67 |
1238 | Returns a make fragment containing any targets which have special |
1239 | meaning to make. For example, .SUFFIXES and .PHONY. |
479d2113 |
1240 | |
7292dc67 |
1241 | =cut |
479d2113 |
1242 | |
7292dc67 |
1243 | sub special_targets { |
1244 | my $make_frag = <<'MAKE_FRAG'; |
1245 | .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT) |
479d2113 |
1246 | |
7292dc67 |
1247 | .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir |
479d2113 |
1248 | |
7292dc67 |
1249 | MAKE_FRAG |
479d2113 |
1250 | |
7292dc67 |
1251 | $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT}; |
1252 | .NO_CONFIG_REC: Makefile |
479d2113 |
1253 | |
7292dc67 |
1254 | MAKE_FRAG |
479d2113 |
1255 | |
7292dc67 |
1256 | return $make_frag; |
1257 | } |
479d2113 |
1258 | |
479d2113 |
1259 | |
479d2113 |
1260 | |
479d2113 |
1261 | |
7292dc67 |
1262 | =head2 Init methods |
1263 | |
1264 | Methods which help initialize the MakeMaker object and macros. |
1265 | |
1266 | |
2977d345 |
1267 | =head3 init_ABSTRACT |
1268 | |
1269 | $mm->init_ABSTRACT |
1270 | |
1271 | =cut |
1272 | |
1273 | sub init_ABSTRACT { |
1274 | my $self = shift; |
1275 | |
1276 | if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) { |
1277 | warn "Both ABSTRACT_FROM and ABSTRACT are set. ". |
1278 | "Ignoring ABSTRACT_FROM.\n"; |
1279 | return; |
1280 | } |
1281 | |
1282 | if ($self->{ABSTRACT_FROM}){ |
1283 | $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or |
1284 | carp "WARNING: Setting ABSTRACT via file ". |
1285 | "'$self->{ABSTRACT_FROM}' failed\n"; |
1286 | } |
1287 | } |
1288 | |
7292dc67 |
1289 | =head3 init_INST |
1290 | |
1291 | $mm->init_INST; |
1292 | |
1293 | Called by init_main. Sets up all INST_* variables except those related |
1294 | to XS code. Those are handled in init_xs. |
1295 | |
1296 | =cut |
1297 | |
1298 | sub init_INST { |
1299 | my($self) = shift; |
1300 | |
1301 | $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch"); |
1302 | $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin'); |
1303 | |
1304 | # INST_LIB typically pre-set if building an extension after |
1305 | # perl has been built and installed. Setting INST_LIB allows |
1306 | # you to build directly into, say $Config{privlibexp}. |
1307 | unless ($self->{INST_LIB}){ |
1308 | if ($self->{PERL_CORE}) { |
1309 | if (defined $Cross::platform) { |
1310 | $self->{INST_LIB} = $self->{INST_ARCHLIB} = |
1311 | $self->catdir($self->{PERL_LIB},"..","xlib", |
1312 | $Cross::platform); |
1313 | } |
1314 | else { |
1315 | $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB}; |
1316 | } |
1317 | } else { |
1318 | $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib"); |
1319 | } |
1320 | } |
1321 | |
1322 | my @parentdir = split(/::/, $self->{PARENT_NAME}); |
1323 | $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir); |
1324 | $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir); |
1325 | $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto', |
1326 | '$(FULLEXT)'); |
1327 | $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto', |
1328 | '$(FULLEXT)'); |
1329 | |
1330 | $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script'); |
1331 | |
1332 | $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1'); |
1333 | $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3'); |
1334 | |
1335 | return 1; |
1336 | } |
1337 | |
1338 | |
1339 | =head3 init_INSTALL |
1340 | |
1341 | $mm->init_INSTALL; |
1342 | |
1343 | Called by init_main. Sets up all INSTALL_* variables (except |
1344 | INSTALLDIRS) and *PREFIX. |
1345 | |
1346 | =cut |
1347 | |
1348 | sub init_INSTALL { |
1349 | my($self) = shift; |
1350 | |
2977d345 |
1351 | if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) { |
1352 | die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n"; |
7292dc67 |
1353 | } |
1354 | |
2977d345 |
1355 | if( $self->{ARGS}{INSTALL_BASE} ) { |
1356 | $self->init_INSTALL_from_INSTALL_BASE; |
7292dc67 |
1357 | } |
1358 | else { |
1359 | $self->init_INSTALL_from_PREFIX; |
1360 | } |
1361 | } |
1362 | |
1363 | |
1364 | =head3 init_INSTALL_from_PREFIX |
1365 | |
1366 | $mm->init_INSTALL_from_PREFIX; |
1367 | |
1368 | =cut |
1369 | |
1370 | sub init_INSTALL_from_PREFIX { |
1371 | my $self = shift; |
1372 | |
1373 | $self->init_lib2arch; |
1374 | |
1375 | # There are often no Config.pm defaults for these new man variables so |
1376 | # we fall back to the old behavior which is to use installman*dir |
1377 | foreach my $num (1, 3) { |
1378 | my $k = 'installsiteman'.$num.'dir'; |
1379 | |
1380 | $self->{uc $k} ||= uc "\$(installman${num}dir)" |
1381 | unless $Config{$k}; |
1382 | } |
1383 | |
1384 | foreach my $num (1, 3) { |
1385 | my $k = 'installvendorman'.$num.'dir'; |
1386 | |
1387 | unless( $Config{$k} ) { |
1388 | $self->{uc $k} ||= $Config{usevendorprefix} |
1389 | ? uc "\$(installman${num}dir)" |
1390 | : ''; |
1391 | } |
1392 | } |
1393 | |
1394 | $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)' |
1395 | unless $Config{installsitebin}; |
002b9267 |
1396 | $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)' |
1397 | unless $Config{installsitescript}; |
7292dc67 |
1398 | |
1399 | unless( $Config{installvendorbin} ) { |
1400 | $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} |
1401 | ? $Config{installbin} |
1402 | : ''; |
1403 | } |
002b9267 |
1404 | unless( $Config{installvendorscript} ) { |
1405 | $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix} |
1406 | ? $Config{installscript} |
1407 | : ''; |
1408 | } |
7292dc67 |
1409 | |
1410 | |
1411 | my $iprefix = $Config{installprefixexp} || $Config{installprefix} || |
1412 | $Config{prefixexp} || $Config{prefix} || ''; |
1413 | my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : ''; |
1414 | my $sprefix = $Config{siteprefixexp} || ''; |
1415 | |
1416 | # 5.005_03 doesn't have a siteprefix. |
1417 | $sprefix = $iprefix unless $sprefix; |
1418 | |
1419 | |
1420 | $self->{PREFIX} ||= ''; |
1421 | |
1422 | if( $self->{PREFIX} ) { |
1423 | @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} = |
1424 | ('$(PREFIX)') x 3; |
1425 | } |
1426 | else { |
1427 | $self->{PERLPREFIX} ||= $iprefix; |
1428 | $self->{SITEPREFIX} ||= $sprefix; |
1429 | $self->{VENDORPREFIX} ||= $vprefix; |
1430 | |
1431 | # Lots of MM extension authors like to use $(PREFIX) so we |
1432 | # put something sensible in there no matter what. |
1433 | $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)'; |
1434 | } |
1435 | |
1436 | my $arch = $Config{archname}; |
1437 | my $version = $Config{version}; |
1438 | |
1439 | # default style |
1440 | my $libstyle = $Config{installstyle} || 'lib/perl5'; |
1441 | my $manstyle = ''; |
1442 | |
1443 | if( $self->{LIBSTYLE} ) { |
1444 | $libstyle = $self->{LIBSTYLE}; |
1445 | $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : ''; |
1446 | } |
1447 | |
1448 | # Some systems, like VOS, set installman*dir to '' if they can't |
1449 | # read man pages. |
1450 | for my $num (1, 3) { |
1451 | $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none' |
1452 | unless $Config{'installman'.$num.'dir'}; |
1453 | } |
1454 | |
1455 | my %bin_layouts = |
1456 | ( |
1457 | bin => { s => $iprefix, |
1458 | t => 'perl', |
1459 | d => 'bin' }, |
1460 | vendorbin => { s => $vprefix, |
1461 | t => 'vendor', |
1462 | d => 'bin' }, |
1463 | sitebin => { s => $sprefix, |
1464 | t => 'site', |
1465 | d => 'bin' }, |
1466 | script => { s => $iprefix, |
1467 | t => 'perl', |
1468 | d => 'bin' }, |
002b9267 |
1469 | vendorscript=> { s => $vprefix, |
1470 | t => 'vendor', |
1471 | d => 'bin' }, |
1472 | sitescript => { s => $sprefix, |
1473 | t => 'site', |
1474 | d => 'bin' }, |
7292dc67 |
1475 | ); |
1476 | |
1477 | my %man_layouts = |
1478 | ( |
1479 | man1dir => { s => $iprefix, |
1480 | t => 'perl', |
1481 | d => 'man/man1', |
1482 | style => $manstyle, }, |
1483 | siteman1dir => { s => $sprefix, |
1484 | t => 'site', |
1485 | d => 'man/man1', |
1486 | style => $manstyle, }, |
1487 | vendorman1dir => { s => $vprefix, |
1488 | t => 'vendor', |
1489 | d => 'man/man1', |
1490 | style => $manstyle, }, |
1491 | |
1492 | man3dir => { s => $iprefix, |
1493 | t => 'perl', |
1494 | d => 'man/man3', |
1495 | style => $manstyle, }, |
1496 | siteman3dir => { s => $sprefix, |
1497 | t => 'site', |
1498 | d => 'man/man3', |
1499 | style => $manstyle, }, |
1500 | vendorman3dir => { s => $vprefix, |
1501 | t => 'vendor', |
1502 | d => 'man/man3', |
1503 | style => $manstyle, }, |
1504 | ); |
1505 | |
1506 | my %lib_layouts = |
1507 | ( |
1508 | privlib => { s => $iprefix, |
1509 | t => 'perl', |
1510 | d => '', |
1511 | style => $libstyle, }, |
1512 | vendorlib => { s => $vprefix, |
1513 | t => 'vendor', |
1514 | d => '', |
1515 | style => $libstyle, }, |
1516 | sitelib => { s => $sprefix, |
1517 | t => 'site', |
1518 | d => 'site_perl', |
1519 | style => $libstyle, }, |
1520 | |
1521 | archlib => { s => $iprefix, |
1522 | t => 'perl', |
1523 | d => "$version/$arch", |
1524 | style => $libstyle }, |
1525 | vendorarch => { s => $vprefix, |
1526 | t => 'vendor', |
1527 | d => "$version/$arch", |
1528 | style => $libstyle }, |
1529 | sitearch => { s => $sprefix, |
1530 | t => 'site', |
1531 | d => "site_perl/$version/$arch", |
1532 | style => $libstyle }, |
1533 | ); |
1534 | |
1535 | |
1536 | # Special case for LIB. |
1537 | if( $self->{LIB} ) { |
1538 | foreach my $var (keys %lib_layouts) { |
1539 | my $Installvar = uc "install$var"; |
1540 | |
1541 | if( $var =~ /arch/ ) { |
1542 | $self->{$Installvar} ||= |
1543 | $self->catdir($self->{LIB}, $Config{archname}); |
1544 | } |
1545 | else { |
1546 | $self->{$Installvar} ||= $self->{LIB}; |
1547 | } |
1548 | } |
1549 | } |
1550 | |
1551 | my %type2prefix = ( perl => 'PERLPREFIX', |
1552 | site => 'SITEPREFIX', |
1553 | vendor => 'VENDORPREFIX' |
1554 | ); |
1555 | |
1556 | my %layouts = (%bin_layouts, %man_layouts, %lib_layouts); |
1557 | while( my($var, $layout) = each(%layouts) ) { |
1558 | my($s, $t, $d, $style) = @{$layout}{qw(s t d style)}; |
1559 | my $r = '$('.$type2prefix{$t}.')'; |
1560 | |
1561 | print STDERR "Prefixing $var\n" if $Verbose >= 2; |
1562 | |
1563 | my $installvar = "install$var"; |
1564 | my $Installvar = uc $installvar; |
1565 | next if $self->{$Installvar}; |
1566 | |
1567 | $d = "$style/$d" if $style; |
1568 | $self->prefixify($installvar, $s, $r, $d); |
1569 | |
1570 | print STDERR " $Installvar == $self->{$Installvar}\n" |
1571 | if $Verbose >= 2; |
1572 | } |
1573 | |
1574 | # Generate these if they weren't figured out. |
1575 | $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH}; |
1576 | $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB}; |
1577 | |
1578 | return 1; |
1579 | } |
1580 | |
1581 | |
2977d345 |
1582 | =head3 init_from_INSTALL_BASE |
7292dc67 |
1583 | |
2977d345 |
1584 | $mm->init_from_INSTALL_BASE |
7292dc67 |
1585 | |
1586 | =cut |
1587 | |
1588 | my %map = ( |
1589 | lib => [qw(lib perl5)], |
1590 | arch => [('lib', 'perl5', $Config{archname})], |
1591 | bin => [qw(bin)], |
1592 | man1dir => [qw(man man1)], |
1593 | man3dir => [qw(man man3)] |
1594 | ); |
1595 | $map{script} = $map{bin}; |
1596 | |
2977d345 |
1597 | sub init_INSTALL_from_INSTALL_BASE { |
7292dc67 |
1598 | my $self = shift; |
1599 | |
1600 | @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = |
2977d345 |
1601 | '$(INSTALL_BASE)'; |
7292dc67 |
1602 | |
1603 | my %install; |
1604 | foreach my $thing (keys %map) { |
1605 | foreach my $dir (('', 'SITE', 'VENDOR')) { |
1606 | my $uc_thing = uc $thing; |
1607 | my $key = "INSTALL".$dir.$uc_thing; |
1608 | |
1609 | $install{$key} ||= |
2977d345 |
1610 | $self->catdir('$(INSTALL_BASE)', @{$map{$thing}}); |
7292dc67 |
1611 | } |
1612 | } |
1613 | |
1614 | # Adjust for variable quirks. |
1615 | $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH}; |
1616 | $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB}; |
7292dc67 |
1617 | |
1618 | foreach my $key (keys %install) { |
1619 | $self->{$key} ||= $install{$key}; |
1620 | } |
1621 | |
1622 | return 1; |
1623 | } |
1624 | |
1625 | |
1626 | =head3 init_VERSION I<Abstract> |
1627 | |
1628 | $mm->init_VERSION |
1629 | |
1630 | Initialize macros representing versions of MakeMaker and other tools |
1631 | |
1632 | MAKEMAKER: path to the MakeMaker module. |
1633 | |
1634 | MM_VERSION: ExtUtils::MakeMaker Version |
1635 | |
1636 | MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards |
1637 | compat) |
1638 | |
1639 | VERSION: version of your module |
1640 | |
1641 | VERSION_MACRO: which macro represents the version (usually 'VERSION') |
1642 | |
1643 | VERSION_SYM: like version but safe for use as an RCS revision number |
1644 | |
1645 | DEFINE_VERSION: -D line to set the module version when compiling |
1646 | |
1647 | XS_VERSION: version in your .xs file. Defaults to $(VERSION) |
1648 | |
1649 | XS_VERSION_MACRO: which macro represents the XS version. |
1650 | |
1651 | XS_DEFINE_VERSION: -D line to set the xs version when compiling. |
1652 | |
1653 | Called by init_main. |
1654 | |
1655 | =cut |
1656 | |
1657 | sub init_VERSION { |
1658 | my($self) = shift; |
1659 | |
1660 | $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename; |
1661 | $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION; |
1662 | $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision; |
1663 | $self->{VERSION_FROM} ||= ''; |
1664 | |
1665 | if ($self->{VERSION_FROM}){ |
1666 | $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}); |
1667 | if( $self->{VERSION} eq 'undef' ) { |
2977d345 |
1668 | carp("WARNING: Setting VERSION via file ". |
1669 | "'$self->{VERSION_FROM}' failed\n"); |
7292dc67 |
1670 | } |
1671 | } |
1672 | |
1673 | # strip blanks |
1674 | if (defined $self->{VERSION}) { |
1675 | $self->{VERSION} =~ s/^\s+//; |
1676 | $self->{VERSION} =~ s/\s+$//; |
1677 | } |
1678 | else { |
1679 | $self->{VERSION} = ''; |
1680 | } |
1681 | |
1682 | |
1683 | $self->{VERSION_MACRO} = 'VERSION'; |
1684 | ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g; |
1685 | $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"'; |
1686 | |
1687 | |
1688 | # Graham Barr and Paul Marquess had some ideas how to ensure |
1689 | # version compatibility between the *.pm file and the |
1690 | # corresponding *.xs file. The bottomline was, that we need an |
1691 | # XS_VERSION macro that defaults to VERSION: |
1692 | $self->{XS_VERSION} ||= $self->{VERSION}; |
1693 | |
1694 | $self->{XS_VERSION_MACRO} = 'XS_VERSION'; |
1695 | $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"'; |
1696 | |
1697 | } |
1698 | |
1699 | |
5bdf71cc |
1700 | =head3 init_others |
479d2113 |
1701 | |
1702 | $MM->init_others(); |
1703 | |
1704 | Initializes the macro definitions used by tools_other() and places them |
1705 | in the $MM object. |
1706 | |
1707 | If there is no description, its the same as the parameter to |
1708 | WriteMakefile() documented in ExtUtils::MakeMaker. |
1709 | |
1710 | Defines at least these macros. |
1711 | |
1712 | Macro Description |
1713 | |
dedf98bc |
1714 | NOOP Do nothing |
1715 | NOECHO Tell make not to display the command itself |
479d2113 |
1716 | |
1717 | MAKEFILE |
1718 | FIRST_MAKEFILE |
1719 | MAKEFILE_OLD |
1720 | MAKE_APERL_FILE File used by MAKE_APERL |
1721 | |
2977d345 |
1722 | SHELL Program used to run shell commands |
479d2113 |
1723 | |
dedf98bc |
1724 | ECHO Print text adding a newline on the end |
479d2113 |
1725 | RM_F Remove a file |
1726 | RM_RF Remove a directory |
1727 | TOUCH Update a file's timestamp |
1728 | TEST_F Test for a file's existence |
1729 | CP Copy a file |
1730 | MV Move a file |
5bdf71cc |
1731 | CHMOD Change permissions on a file |
1732 | FALSE Exit with non-zero |
1733 | TRUE Exit with zero |
479d2113 |
1734 | |
1735 | UMASK_NULL Nullify umask |
3c4b39be |
1736 | DEV_NULL Suppress all command output |
479d2113 |
1737 | |
5bdf71cc |
1738 | =cut |
1739 | |
1740 | sub init_others { |
1741 | my $self = shift; |
1742 | |
1743 | $self->{ECHO} ||= $self->oneliner('print qq{@ARGV}', ['-l']); |
1744 | $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}'); |
1745 | |
1746 | $self->{TOUCH} ||= $self->oneliner('touch', ["-MExtUtils::Command"]); |
1747 | $self->{CHMOD} ||= $self->oneliner('chmod', ["-MExtUtils::Command"]); |
1748 | $self->{RM_F} ||= $self->oneliner('rm_f', ["-MExtUtils::Command"]); |
1749 | $self->{RM_RF} ||= $self->oneliner('rm_rf', ["-MExtUtils::Command"]); |
1750 | $self->{TEST_F} ||= $self->oneliner('test_f', ["-MExtUtils::Command"]); |
1751 | $self->{FALSE} ||= $self->oneliner('exit 1'); |
1752 | $self->{TRUE} ||= $self->oneliner('exit 0'); |
1753 | |
1754 | $self->{MKPATH} ||= $self->oneliner('mkpath', ["-MExtUtils::Command"]); |
1755 | |
1756 | $self->{CP} ||= $self->oneliner('cp', ["-MExtUtils::Command"]); |
1757 | $self->{MV} ||= $self->oneliner('mv', ["-MExtUtils::Command"]); |
1758 | |
1759 | $self->{MOD_INSTALL} ||= |
1760 | $self->oneliner(<<'CODE', ['-MExtUtils::Install']); |
1761 | install([ from_to => {@ARGV}, verbose => '$(VERBINST)', uninstall_shadows => '$(UNINST)', dir_mode => '$(PERM_DIR)' ]); |
1762 | CODE |
1763 | $self->{DOC_INSTALL} ||= $self->oneliner('perllocal_install', ["-MExtUtils::Command::MM"]); |
1764 | $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]); |
1765 | $self->{WARN_IF_OLD_PACKLIST} ||= |
1766 | $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]); |
1767 | $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]); |
1768 | $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]); |
1769 | |
1770 | $self->{UNINST} ||= 0; |
1771 | $self->{VERBINST} ||= 0; |
1772 | |
1773 | $self->{FIRST_MAKEFILE} ||= $self->{MAKEFILE} || 'Makefile'; |
1774 | $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE}; |
1775 | $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old'; |
1776 | $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl'; |
1777 | |
1778 | # Not everybody uses -f to indicate "use this Makefile instead" |
1779 | $self->{USEMAKEFILE} ||= '-f'; |
1780 | |
1781 | # Some makes require a wrapper around macros passed in on the command |
1782 | # line. |
1783 | $self->{MACROSTART} ||= ''; |
1784 | $self->{MACROEND} ||= ''; |
1785 | |
1786 | $self->{SHELL} ||= $Config{sh}; |
1787 | |
1788 | # UMASK_NULL is not used by MakeMaker but some CPAN modules |
1789 | # make use of it. |
1790 | $self->{UMASK_NULL} ||= "umask 0"; |
1791 | |
1792 | # Not the greatest default, but its something. |
1793 | $self->{DEV_NULL} ||= "> /dev/null 2>&1"; |
1794 | |
1795 | $self->{NOOP} ||= '$(TRUE)'; |
1796 | $self->{NOECHO} = '@' unless defined $self->{NOECHO}; |
1797 | |
1798 | $self->{LD_RUN_PATH} = ""; |
1799 | |
c0956255 |
1800 | $self->{LIBS} = $self->_fix_libs($self->{LIBS}); |
5bdf71cc |
1801 | |
c0956255 |
1802 | # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS} |
5bdf71cc |
1803 | foreach my $libs ( @{$self->{LIBS}} ){ |
1804 | $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace |
1805 | my(@libs) = $self->extliblist($libs); |
1806 | if ($libs[0] or $libs[1] or $libs[2]){ |
1807 | # LD_RUN_PATH now computed by ExtUtils::Liblist |
1808 | ($self->{EXTRALIBS}, $self->{BSLOADLIBS}, |
1809 | $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs; |
1810 | last; |
1811 | } |
1812 | } |
1813 | |
1814 | if ( $self->{OBJECT} ) { |
1815 | $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g; |
1816 | } else { |
1817 | # init_dirscan should have found out, if we have C files |
1818 | $self->{OBJECT} = ""; |
1819 | $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]}; |
1820 | } |
1821 | $self->{OBJECT} =~ s/\n+/ \\\n\t/g; |
1822 | |
1823 | $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : ""; |
1824 | $self->{PERLMAINCC} ||= '$(CC)'; |
1825 | $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM}; |
1826 | |
1827 | # Sanity check: don't define LINKTYPE = dynamic if we're skipping |
1828 | # the 'dynamic' section of MM. We don't have this problem with |
1829 | # 'static', since we either must use it (%Config says we can't |
1830 | # use dynamic loading) or the caller asked for it explicitly. |
1831 | if (!$self->{LINKTYPE}) { |
1832 | $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'} |
1833 | ? 'static' |
1834 | : ($Config{usedl} ? 'dynamic' : 'static'); |
1835 | } |
1836 | |
1837 | return 1; |
1838 | } |
1839 | |
1840 | |
c0956255 |
1841 | # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or |
1842 | # undefined. In any case we turn it into an anon array |
1843 | sub _fix_libs { |
1844 | my($self, $libs) = @_; |
1845 | |
1846 | return !defined $libs ? [''] : |
1847 | !ref $libs ? [$libs] : |
1848 | !defined $libs->[0] ? [''] : |
1849 | $libs ; |
1850 | } |
1851 | |
1852 | |
5bdf71cc |
1853 | =head3 tools_other |
1854 | |
1855 | my $make_frag = $MM->tools_other; |
1856 | |
1857 | Returns a make fragment containing definitions for the macros init_others() |
1858 | initializes. |
1859 | |
1860 | =cut |
1861 | |
1862 | sub tools_other { |
1863 | my($self) = shift; |
1864 | my @m; |
1865 | |
1866 | # We set PM_FILTER as late as possible so it can see all the earlier |
1867 | # on macro-order sensitive makes such as nmake. |
1868 | for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH |
1869 | UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP |
1870 | FALSE TRUE |
1871 | ECHO ECHO_N |
1872 | UNINST VERBINST |
1873 | MOD_INSTALL DOC_INSTALL UNINSTALL |
1874 | WARN_IF_OLD_PACKLIST |
1875 | MACROSTART MACROEND |
1876 | USEMAKEFILE |
1877 | PM_FILTER |
1878 | FIXIN |
1879 | } ) |
1880 | { |
1881 | next unless defined $self->{$tool}; |
1882 | push @m, "$tool = $self->{$tool}\n"; |
1883 | } |
1884 | |
1885 | return join "", @m; |
1886 | } |
1887 | |
7292dc67 |
1888 | |
1889 | =head3 init_DIRFILESEP I<Abstract> |
479d2113 |
1890 | |
1891 | $MM->init_DIRFILESEP; |
1892 | my $dirfilesep = $MM->{DIRFILESEP}; |
1893 | |
1894 | Initializes the DIRFILESEP macro which is the seperator between the |
1895 | directory and filename in a filepath. ie. / on Unix, \ on Win32 and |
1896 | nothing on VMS. |
1897 | |
1898 | For example: |
1899 | |
1900 | # instead of $(INST_ARCHAUTODIR)/extralibs.ld |
1901 | $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld |
1902 | |
1903 | Something of a hack but it prevents a lot of code duplication between |
1904 | MM_* variants. |
1905 | |
1906 | Do not use this as a seperator between directories. Some operating |
1907 | systems use different seperators between subdirectories as between |
1908 | directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS). |
1909 | |
7292dc67 |
1910 | =head3 init_linker I<Abstract> |
479d2113 |
1911 | |
1912 | $mm->init_linker; |
1913 | |
1914 | Initialize macros which have to do with linking. |
1915 | |
1916 | PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic |
1917 | extensions. |
1918 | |
1919 | PERL_ARCHIVE_AFTER: path to a library which should be put on the |
1920 | linker command line I<after> the external libraries to be linked to |
1921 | dynamic extensions. This may be needed if the linker is one-pass, and |
1922 | Perl includes some overrides for C RTL functions, such as malloc(). |
1923 | |
1924 | EXPORT_LIST: name of a file that is passed to linker to define symbols |
1925 | to be exported. |
1926 | |
1927 | Some OSes do not need these in which case leave it blank. |
1928 | |
1929 | |
7292dc67 |
1930 | =head3 init_platform |
479d2113 |
1931 | |
1932 | $mm->init_platform |
1933 | |
1934 | Initialize any macros which are for platform specific use only. |
1935 | |
1936 | A typical one is the version number of your OS specific mocule. |
1937 | (ie. MM_Unix_VERSION or MM_VMS_VERSION). |
1938 | |
7292dc67 |
1939 | =cut |
479d2113 |
1940 | |
7292dc67 |
1941 | sub init_platform { |
1942 | return ''; |
1943 | } |
479d2113 |
1944 | |
7292dc67 |
1945 | |
2977d345 |
1946 | =head3 init_MAKE |
1947 | |
1948 | $mm->init_MAKE |
7292dc67 |
1949 | |
2977d345 |
1950 | Initialize MAKE from either a MAKE environment variable or $Config{make}. |
1951 | |
1952 | =cut |
1953 | |
1954 | sub init_MAKE { |
1955 | my $self = shift; |
1956 | |
1957 | $self->{MAKE} ||= $ENV{MAKE} || $Config{make}; |
1958 | } |
7292dc67 |
1959 | |
1960 | |
1961 | =head2 Tools |
1962 | |
1963 | A grab bag of methods to generate specific macros and commands. |
1964 | |
1965 | |
1966 | |
1967 | =head3 manifypods |
1968 | |
1969 | Defines targets and routines to translate the pods into manpages and |
1970 | put them into the INST_* directories. |
479d2113 |
1971 | |
1972 | =cut |
1973 | |
7292dc67 |
1974 | sub manifypods { |
1975 | my $self = shift; |
1976 | |
1977 | my $POD2MAN_macro = $self->POD2MAN_macro(); |
1978 | my $manifypods_target = $self->manifypods_target(); |
1979 | |
1980 | return <<END_OF_TARGET; |
1981 | |
1982 | $POD2MAN_macro |
1983 | |
1984 | $manifypods_target |
1985 | |
1986 | END_OF_TARGET |
1987 | |
479d2113 |
1988 | } |
1989 | |
7292dc67 |
1990 | |
1991 | =head3 POD2MAN_macro |
1992 | |
1993 | my $pod2man_macro = $self->POD2MAN_macro |
1994 | |
1995 | Returns a definition for the POD2MAN macro. This is a program |
1996 | which emulates the pod2man utility. You can add more switches to the |
1997 | command by simply appending them on the macro. |
1998 | |
1999 | Typical usage: |
2000 | |
2001 | $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ... |
2002 | |
2003 | =cut |
2004 | |
2005 | sub POD2MAN_macro { |
2006 | my $self = shift; |
2007 | |
2008 | # Need the trailing '--' so perl stops gobbling arguments and - happens |
2009 | # to be an alternative end of line seperator on VMS so we quote it |
2010 | return <<'END_OF_DEF'; |
2011 | POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" |
2012 | POD2MAN = $(POD2MAN_EXE) |
2013 | END_OF_DEF |
479d2113 |
2014 | } |
2015 | |
dedf98bc |
2016 | |
7292dc67 |
2017 | =head3 test_via_harness |
dedf98bc |
2018 | |
7292dc67 |
2019 | my $command = $mm->test_via_harness($perl, $tests); |
dedf98bc |
2020 | |
7292dc67 |
2021 | Returns a $command line which runs the given set of $tests with |
2022 | Test::Harness and the given $perl. |
dedf98bc |
2023 | |
7292dc67 |
2024 | Used on the t/*.t files. |
dedf98bc |
2025 | |
7292dc67 |
2026 | =cut |
dedf98bc |
2027 | |
7292dc67 |
2028 | sub test_via_harness { |
2029 | my($self, $perl, $tests) = @_; |
2030 | |
2031 | return qq{\t$perl "-MExtUtils::Command::MM" }. |
2032 | qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n}; |
2033 | } |
2034 | |
2035 | =head3 test_via_script |
2036 | |
2037 | my $command = $mm->test_via_script($perl, $script); |
2038 | |
2039 | Returns a $command line which just runs a single test without |
2040 | Test::Harness. No checks are done on the results, they're just |
2041 | printed. |
dedf98bc |
2042 | |
7292dc67 |
2043 | Used for test.pl, since they don't always follow Test::Harness |
2044 | formatting. |
2045 | |
2046 | =cut |
2047 | |
2048 | sub test_via_script { |
2049 | my($self, $perl, $script) = @_; |
2050 | return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n}; |
2051 | } |
2052 | |
2053 | |
2054 | =head3 tool_autosplit |
2055 | |
2056 | Defines a simple perl call that runs autosplit. May be deprecated by |
2057 | pm_to_blib soon. |
2058 | |
2059 | =cut |
2060 | |
2061 | sub tool_autosplit { |
2062 | my($self, %attribs) = @_; |
2063 | |
2064 | my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};' |
2065 | : ''; |
2066 | |
2067 | my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen); |
2068 | use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) |
2069 | PERL_CODE |
2070 | |
2071 | return sprintf <<'MAKE_FRAG', $asplit; |
2072 | # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto |
2073 | AUTOSPLITFILE = %s |
2074 | |
2075 | MAKE_FRAG |
2076 | |
2077 | } |
2078 | |
2079 | |
5bdf71cc |
2080 | =head3 arch_check |
2081 | |
2082 | my $arch_ok = $mm->arch_check( |
2083 | $INC{"Config.pm"}, |
2084 | File::Spec->catfile($Config{archlibexp}, "Config.pm") |
2085 | ); |
2086 | |
2087 | A sanity check that what Perl thinks the architecture is and what |
2088 | Config thinks the architecture is are the same. If they're not it |
2089 | will return false and show a diagnostic message. |
2090 | |
2091 | When building Perl it will always return true, as nothing is installed |
2092 | yet. |
2093 | |
2094 | The interface is a bit odd because this is the result of a |
2095 | quick refactoring. Don't rely on it. |
2096 | |
2097 | =cut |
2098 | |
2099 | sub arch_check { |
2100 | my $self = shift; |
2101 | my($pconfig, $cconfig) = @_; |
2102 | |
2103 | return 1 if $self->{PERL_SRC}; |
2104 | |
2105 | my($pvol, $pthinks) = $self->splitpath($pconfig); |
2106 | my($cvol, $cthinks) = $self->splitpath($cconfig); |
2107 | |
2108 | $pthinks = $self->canonpath($pthinks); |
2109 | $cthinks = $self->canonpath($cthinks); |
2110 | |
2111 | my $ret = 1; |
2112 | if ($pthinks ne $cthinks) { |
2113 | print "Have $pthinks\n"; |
2114 | print "Want $cthinks\n"; |
2115 | |
2116 | $ret = 0; |
2117 | |
2118 | my $arch = (grep length, $self->splitdir($pthinks))[-1]; |
2119 | |
2120 | print STDOUT <<END unless $self->{UNINSTALLED_PERL}; |
2121 | Your perl and your Config.pm seem to have different ideas about the |
2122 | architecture they are running on. |
2123 | Perl thinks: [$arch] |
2124 | Config says: [$Config{archname}] |
2125 | This may or may not cause problems. Please check your installation of perl |
2126 | if you have problems building this extension. |
2127 | END |
2128 | } |
2129 | |
2130 | return $ret; |
2131 | } |
2132 | |
7292dc67 |
2133 | |
2134 | |
2135 | =head2 File::Spec wrappers |
2136 | |
2137 | ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here |
2138 | override File::Spec. |
2139 | |
2140 | |
2141 | |
2142 | =head3 catfile |
2143 | |
2144 | File::Spec <= 0.83 has a bug where the file part of catfile is not |
2145 | canonicalized. This override fixes that bug. |
2146 | |
2147 | =cut |
2148 | |
2149 | sub catfile { |
2150 | my $self = shift; |
2151 | return $self->canonpath($self->SUPER::catfile(@_)); |
2152 | } |
2153 | |
2154 | |
2155 | |
2156 | =head2 Misc |
2157 | |
2158 | Methods I can't really figure out where they should go yet. |
2159 | |
2160 | |
2161 | =head3 find_tests |
2162 | |
2163 | my $test = $mm->find_tests; |
2164 | |
2165 | Returns a string suitable for feeding to the shell to return all |
2166 | tests in t/*.t. |
2167 | |
2168 | =cut |
2169 | |
2170 | sub find_tests { |
2171 | my($self) = shift; |
2172 | return -d 't' ? 't/*.t' : ''; |
2173 | } |
2174 | |
2175 | |
2176 | =head3 extra_clean_files |
2177 | |
2178 | my @files_to_clean = $MM->extra_clean_files; |
2179 | |
2180 | Returns a list of OS specific files to be removed in the clean target in |
2181 | addition to the usual set. |
2182 | |
2183 | =cut |
2184 | |
2185 | # An empty method here tickled a perl 5.8.1 bug and would return its object. |
2186 | sub extra_clean_files { |
2187 | return; |
2188 | } |
2189 | |
2190 | |
2191 | =head3 installvars |
2192 | |
2193 | my @installvars = $mm->installvars; |
2194 | |
2195 | A list of all the INSTALL* variables without the INSTALL prefix. Useful |
2196 | for iteration or building related variable sets. |
2197 | |
2198 | =cut |
2199 | |
2200 | sub installvars { |
2201 | return qw(PRIVLIB SITELIB VENDORLIB |
2202 | ARCHLIB SITEARCH VENDORARCH |
2203 | BIN SITEBIN VENDORBIN |
002b9267 |
2204 | SCRIPT SITESCRIPT VENDORSCRIPT |
7292dc67 |
2205 | MAN1DIR SITEMAN1DIR VENDORMAN1DIR |
2206 | MAN3DIR SITEMAN3DIR VENDORMAN3DIR |
2207 | ); |
2208 | } |
2209 | |
2210 | |
2211 | =head3 libscan |
2212 | |
2213 | my $wanted = $self->libscan($path); |
2214 | |
2215 | Takes a path to a file or dir and returns an empty string if we don't |
2216 | want to include this file in the library. Otherwise it returns the |
2217 | the $path unchanged. |
2218 | |
2219 | Mainly used to exclude version control administrative directories from |
2220 | installation. |
2221 | |
2222 | =cut |
2223 | |
2224 | sub libscan { |
2225 | my($self,$path) = @_; |
2226 | my($dirs,$file) = ($self->splitpath($path))[1,2]; |
2227 | return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/, |
2228 | $self->splitdir($dirs), $file; |
2229 | |
2230 | return $path; |
2231 | } |
2232 | |
2233 | |
2234 | =head3 platform_constants |
2235 | |
2236 | my $make_frag = $mm->platform_constants |
2237 | |
2238 | Returns a make fragment defining all the macros initialized in |
2239 | init_platform() rather than put them in constants(). |
2240 | |
2241 | =cut |
2242 | |
2243 | sub platform_constants { |
2244 | return ''; |
2245 | } |
479d2113 |
2246 | |
b6d6132c |
2247 | =begin private |
2248 | |
2249 | =head3 _PREREQ_PRINT |
2250 | |
2251 | $self->_PREREQ_PRINT; |
2252 | |
2253 | Implements PREREQ_PRINT. |
2254 | |
2255 | Refactored out of MakeMaker->new(). |
2256 | |
2257 | =end private |
2258 | |
2259 | =cut |
2260 | |
2261 | sub _PREREQ_PRINT { |
2262 | my $self = shift; |
2263 | |
2264 | require Data::Dumper; |
2265 | my @what = ('PREREQ_PM'); |
2266 | push @what, 'MIN_PERL_VERSION' if $self->{MIN_PERL_VERSION}; |
2267 | push @what, 'BUILD_REQUIRES' if $self->{BUILD_REQUIRES}; |
2268 | print Data::Dumper->Dump([@{$self}{@what}], \@what); |
2269 | exit 0; |
2270 | } |
2271 | |
2272 | |
2273 | =begin private |
2274 | |
2275 | =head3 _PRINT_PREREQ |
2276 | |
2277 | $mm->_PRINT_PREREQ; |
2278 | |
2279 | Implements PRINT_PREREQ, a slightly different version of PREREQ_PRINT |
2280 | added by Redhat to, I think, support generating RPMs from Perl modules. |
2281 | |
8b19c1f8 |
2282 | Should not include BUILD_REQUIRES as RPMs do not incluide them. |
2283 | |
b6d6132c |
2284 | Refactored out of MakeMaker->new(). |
2285 | |
2286 | =end private |
2287 | |
2288 | =cut |
2289 | |
2290 | sub _PRINT_PREREQ { |
2291 | my $self = shift; |
2292 | |
8b19c1f8 |
2293 | my $prereqs= $self->{PREREQ_PM}; |
b6d6132c |
2294 | my @prereq = map { [$_, $prereqs->{$_}] } keys %$prereqs; |
2295 | |
2296 | if ( $self->{MIN_PERL_VERSION} ) { |
2297 | push @prereq, ['perl' => $self->{MIN_PERL_VERSION}]; |
2298 | } |
2299 | |
2300 | print join(" ", map { "perl($_->[0])>=$_->[1] " } |
2301 | sort { $a->[0] cmp $b->[0] } @prereq), "\n"; |
2302 | exit 0; |
2303 | } |
2304 | |
2305 | |
2306 | =begin private |
2307 | |
2308 | =head3 _all_prereqs |
2309 | |
2310 | my $prereqs = $self->_all_prereqs; |
2311 | |
2312 | Returns a hash ref of both PREREQ_PM and BUILD_REQUIRES. |
2313 | |
2314 | =end private |
2315 | |
2316 | =cut |
2317 | |
2318 | sub _all_prereqs { |
2319 | my $self = shift; |
2320 | |
2321 | return { %{$self->{PREREQ_PM}}, %{$self->{BUILD_REQUIRES}} }; |
2322 | } |
2323 | |
f6d6199c |
2324 | |
2325 | =head1 AUTHOR |
2326 | |
479d2113 |
2327 | Michael G Schwern <schwern@pobox.com> and the denizens of |
2328 | makemaker@perl.org with code from ExtUtils::MM_Unix and |
2329 | ExtUtils::MM_Win32. |
f6d6199c |
2330 | |
2331 | |
2332 | =cut |
2333 | |
2334 | 1; |