Commit | Line | Data |
f6d6199c |
1 | package ExtUtils::MM_Any; |
2 | |
3 | use strict; |
4 | use vars qw($VERSION @ISA); |
2977d345 |
5 | $VERSION = '0.13_02'; |
f6d6199c |
6 | |
2977d345 |
7 | use Carp; |
f6d6199c |
8 | use File::Spec; |
7292dc67 |
9 | BEGIN { @ISA = qw(File::Spec); } |
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') |
77 | Windows NT ('Win32', 'WinNT') |
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 | |
7292dc67 |
112 | =head3 split_command |
479d2113 |
113 | |
114 | my @cmds = $MM->split_command($cmd, @args); |
115 | |
116 | Most OS have a maximum command length they can execute at once. Large |
117 | modules can easily generate commands well past that limit. Its |
118 | necessary to split long commands up into a series of shorter commands. |
119 | |
7292dc67 |
120 | C<split_command> will return a series of @cmds each processing part of |
479d2113 |
121 | the args. Collectively they will process all the arguments. Each |
122 | individual line in @cmds will not be longer than the |
123 | $self->max_exec_len being careful to take into account macro expansion. |
124 | |
125 | $cmd should include any switches and repeated initial arguments. |
126 | |
127 | If no @args are given, no @cmds will be returned. |
128 | |
129 | Pairs of arguments will always be preserved in a single command, this |
130 | is a heuristic for things like pm_to_blib and pod2man which work on |
131 | pairs of arguments. This makes things like this safe: |
132 | |
133 | $self->split_command($cmd, %pod2man); |
134 | |
f6d6199c |
135 | |
136 | =cut |
137 | |
479d2113 |
138 | sub split_command { |
139 | my($self, $cmd, @args) = @_; |
140 | |
141 | my @cmds = (); |
142 | return(@cmds) unless @args; |
143 | |
144 | # If the command was given as a here-doc, there's probably a trailing |
145 | # newline. |
146 | chomp $cmd; |
147 | |
148 | # set aside 20% for macro expansion. |
149 | my $len_left = int($self->max_exec_len * 0.80); |
150 | $len_left -= length $self->_expand_macros($cmd); |
151 | |
152 | do { |
153 | my $arg_str = ''; |
154 | my @next_args; |
155 | while( @next_args = splice(@args, 0, 2) ) { |
156 | # Two at a time to preserve pairs. |
157 | my $next_arg_str = "\t ". join ' ', @next_args, "\n"; |
158 | |
159 | if( !length $arg_str ) { |
160 | $arg_str .= $next_arg_str |
161 | } |
162 | elsif( length($arg_str) + length($next_arg_str) > $len_left ) { |
163 | unshift @args, @next_args; |
164 | last; |
165 | } |
166 | else { |
167 | $arg_str .= $next_arg_str; |
168 | } |
169 | } |
170 | chop $arg_str; |
171 | |
a7d1454b |
172 | push @cmds, $self->escape_newlines("$cmd \n$arg_str"); |
479d2113 |
173 | } while @args; |
174 | |
175 | return @cmds; |
f6d6199c |
176 | } |
177 | |
479d2113 |
178 | |
179 | sub _expand_macros { |
180 | my($self, $cmd) = @_; |
181 | |
182 | $cmd =~ s{\$\((\w+)\)}{ |
183 | defined $self->{$1} ? $self->{$1} : "\$($1)" |
184 | }e; |
185 | return $cmd; |
186 | } |
187 | |
188 | |
7292dc67 |
189 | =head3 echo |
479d2113 |
190 | |
191 | my @commands = $MM->echo($text); |
192 | my @commands = $MM->echo($text, $file); |
193 | my @commands = $MM->echo($text, $file, $appending); |
194 | |
195 | Generates a set of @commands which print the $text to a $file. |
196 | |
197 | If $file is not given, output goes to STDOUT. |
198 | |
199 | If $appending is true the $file will be appended to rather than |
200 | overwritten. |
f6d6199c |
201 | |
202 | =cut |
203 | |
479d2113 |
204 | sub echo { |
205 | my($self, $text, $file, $appending) = @_; |
206 | $appending ||= 0; |
207 | |
208 | my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) } |
209 | split /\n/, $text; |
210 | if( $file ) { |
211 | my $redirect = $appending ? '>>' : '>'; |
212 | $cmds[0] .= " $redirect $file"; |
213 | $_ .= " >> $file" foreach @cmds[1..$#cmds]; |
214 | } |
215 | |
216 | return @cmds; |
f6d6199c |
217 | } |
218 | |
479d2113 |
219 | |
7292dc67 |
220 | =head3 wraplist |
479d2113 |
221 | |
7292dc67 |
222 | my $args = $mm->wraplist(@list); |
479d2113 |
223 | |
7292dc67 |
224 | Takes an array of items and turns them into a well-formatted list of |
225 | arguments. In most cases this is simply something like: |
479d2113 |
226 | |
7292dc67 |
227 | FOO \ |
228 | BAR \ |
229 | BAZ |
479d2113 |
230 | |
7292dc67 |
231 | =cut |
479d2113 |
232 | |
7292dc67 |
233 | sub wraplist { |
234 | my $self = shift; |
235 | return join " \\\n\t", @_; |
236 | } |
479d2113 |
237 | |
479d2113 |
238 | |
7292dc67 |
239 | =head3 cd I<Abstract> |
479d2113 |
240 | |
7292dc67 |
241 | my $subdir_cmd = $MM->cd($subdir, @cmds); |
479d2113 |
242 | |
7292dc67 |
243 | This will generate a make fragment which runs the @cmds in the given |
244 | $dir. The rough equivalent to this, except cross platform. |
479d2113 |
245 | |
7292dc67 |
246 | cd $subdir && $cmd |
479d2113 |
247 | |
7292dc67 |
248 | Currently $dir can only go down one level. "foo" is fine. "foo/bar" is |
249 | not. "../foo" is right out. |
479d2113 |
250 | |
7292dc67 |
251 | The resulting $subdir_cmd has no leading tab nor trailing newline. This |
252 | makes it easier to embed in a make string. For example. |
479d2113 |
253 | |
7292dc67 |
254 | my $make = sprintf <<'CODE', $subdir_cmd; |
255 | foo : |
256 | $(ECHO) what |
257 | %s |
258 | $(ECHO) mouche |
259 | CODE |
f6d6199c |
260 | |
f6d6199c |
261 | |
7292dc67 |
262 | =head3 oneliner I<Abstract> |
479d2113 |
263 | |
7292dc67 |
264 | my $oneliner = $MM->oneliner($perl_code); |
265 | my $oneliner = $MM->oneliner($perl_code, \@switches); |
479d2113 |
266 | |
7292dc67 |
267 | This will generate a perl one-liner safe for the particular platform |
268 | you're on based on the given $perl_code and @switches (a -e is |
269 | assumed) suitable for using in a make target. It will use the proper |
270 | shell quoting and escapes. |
479d2113 |
271 | |
7292dc67 |
272 | $(PERLRUN) will be used as perl. |
479d2113 |
273 | |
7292dc67 |
274 | Any newlines in $perl_code will be escaped. Leading and trailing |
275 | newlines will be stripped. Makes this idiom much easier: |
479d2113 |
276 | |
7292dc67 |
277 | my $code = $MM->oneliner(<<'CODE', [...switches...]); |
278 | some code here |
279 | another line here |
280 | CODE |
479d2113 |
281 | |
7292dc67 |
282 | Usage might be something like: |
479d2113 |
283 | |
7292dc67 |
284 | # an echo emulation |
285 | $oneliner = $MM->oneliner('print "Foo\n"'); |
286 | $make = '$oneliner > somefile'; |
479d2113 |
287 | |
7292dc67 |
288 | All dollar signs must be doubled in the $perl_code if you expect them |
289 | to be interpreted normally, otherwise it will be considered a make |
290 | macro. Also remember to quote make macros else it might be used as a |
291 | bareword. For example: |
479d2113 |
292 | |
7292dc67 |
293 | # Assign the value of the $(VERSION_FROM) make macro to $vf. |
294 | $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"'); |
f6d6199c |
295 | |
7292dc67 |
296 | Its currently very simple and may be expanded sometime in the figure |
297 | to include more flexible code and switches. |
479d2113 |
298 | |
479d2113 |
299 | |
7292dc67 |
300 | =head3 quote_literal I<Abstract> |
f6d6199c |
301 | |
7292dc67 |
302 | my $safe_text = $MM->quote_literal($text); |
f6d6199c |
303 | |
7292dc67 |
304 | This will quote $text so it is interpreted literally in the shell. |
f6d6199c |
305 | |
7292dc67 |
306 | For example, on Unix this would escape any single-quotes in $text and |
307 | put single-quotes around the whole thing. |
479d2113 |
308 | |
f6d6199c |
309 | |
7292dc67 |
310 | =head3 escape_newlines I<Abstract> |
f6d6199c |
311 | |
7292dc67 |
312 | my $escaped_text = $MM->escape_newlines($text); |
479d2113 |
313 | |
7292dc67 |
314 | Shell escapes newlines in $text. |
479d2113 |
315 | |
479d2113 |
316 | |
7292dc67 |
317 | =head3 max_exec_len I<Abstract> |
479d2113 |
318 | |
7292dc67 |
319 | my $max_exec_len = $MM->max_exec_len; |
479d2113 |
320 | |
7292dc67 |
321 | Calculates the maximum command size the OS can exec. Effectively, |
322 | this is the max size of a shell command line. |
479d2113 |
323 | |
7292dc67 |
324 | =for _private |
325 | $self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes. |
f6d6199c |
326 | |
479d2113 |
327 | |
2977d345 |
328 | =head3 make |
479d2113 |
329 | |
2977d345 |
330 | my $make = $MM->make; |
331 | |
332 | Returns the make variant we're generating the Makefile for. This attempts |
333 | to do some normalization on the information from %Config or the user. |
334 | |
335 | =cut |
336 | |
337 | sub make { |
338 | my $self = shift; |
339 | |
340 | my $make = lc $self->{MAKE}; |
341 | |
342 | # Truncate anything like foomake6 to just foomake. |
343 | $make =~ s/^(\w+make).*/$1/; |
344 | |
345 | # Turn gnumake into gmake. |
346 | $make =~ s/^gnu/g/; |
347 | |
348 | return $make; |
349 | } |
479d2113 |
350 | |
f6d6199c |
351 | |
7292dc67 |
352 | =head2 Targets |
f6d6199c |
353 | |
7292dc67 |
354 | These are methods which produce make targets. |
479d2113 |
355 | |
479d2113 |
356 | |
7292dc67 |
357 | =head3 all_target |
479d2113 |
358 | |
7292dc67 |
359 | Generate the default target 'all'. |
479d2113 |
360 | |
7292dc67 |
361 | =cut |
479d2113 |
362 | |
7292dc67 |
363 | sub all_target { |
364 | my $self = shift; |
479d2113 |
365 | |
7292dc67 |
366 | return <<'MAKE_EXT'; |
367 | all :: pure_all |
368 | $(NOECHO) $(NOOP) |
369 | MAKE_EXT |
479d2113 |
370 | |
f6d6199c |
371 | } |
372 | |
479d2113 |
373 | |
7292dc67 |
374 | =head3 blibdirs_target |
479d2113 |
375 | |
7292dc67 |
376 | my $make_frag = $mm->blibdirs_target; |
479d2113 |
377 | |
7292dc67 |
378 | Creates the blibdirs target which creates all the directories we use |
379 | in blib/. |
f6d6199c |
380 | |
7292dc67 |
381 | The blibdirs.ts target is deprecated. Depend on blibdirs instead. |
f6d6199c |
382 | |
479d2113 |
383 | |
7292dc67 |
384 | =cut |
385 | |
386 | sub blibdirs_target { |
387 | my $self = shift; |
388 | |
389 | my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib |
390 | autodir archautodir |
391 | bin script |
392 | man1dir man3dir |
393 | ); |
f6d6199c |
394 | |
7292dc67 |
395 | my @exists = map { $_.'$(DFSEP).exists' } @dirs; |
479d2113 |
396 | |
7292dc67 |
397 | my $make = sprintf <<'MAKE', join(' ', @exists); |
398 | blibdirs : %s |
399 | $(NOECHO) $(NOOP) |
479d2113 |
400 | |
7292dc67 |
401 | # Backwards compat with 6.18 through 6.25 |
402 | blibdirs.ts : blibdirs |
403 | $(NOECHO) $(NOOP) |
479d2113 |
404 | |
7292dc67 |
405 | MAKE |
406 | |
407 | $make .= $self->dir_target(@dirs); |
408 | |
409 | return $make; |
410 | } |
411 | |
412 | |
413 | =head3 clean (o) |
414 | |
415 | Defines the clean target. |
f6d6199c |
416 | |
417 | =cut |
418 | |
7292dc67 |
419 | sub clean { |
420 | # --- Cleanup and Distribution Sections --- |
479d2113 |
421 | |
7292dc67 |
422 | my($self, %attribs) = @_; |
423 | my @m; |
424 | push(@m, ' |
425 | # Delete temporary files but do not touch installed files. We don\'t delete |
426 | # the Makefile here so a later make realclean still has a makefile to use. |
427 | |
428 | clean :: clean_subdirs |
429 | '); |
430 | |
431 | my @files = values %{$self->{XS}}; # .c files from *.xs files |
432 | my @dirs = qw(blib); |
433 | |
434 | # Normally these are all under blib but they might have been |
435 | # redefined. |
436 | # XXX normally this would be a good idea, but the Perl core sets |
437 | # INST_LIB = ../../lib rather than actually installing the files. |
438 | # So a "make clean" in an ext/ directory would blow away lib. |
439 | # Until the core is adjusted let's leave this out. |
440 | # push @dirs, qw($(INST_ARCHLIB) $(INST_LIB) |
441 | # $(INST_BIN) $(INST_SCRIPT) |
442 | # $(INST_MAN1DIR) $(INST_MAN3DIR) |
443 | # $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR) |
444 | # $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT) |
445 | # ); |
446 | |
447 | |
448 | if( $attribs{FILES} ) { |
449 | # Use @dirs because we don't know what's in here. |
450 | push @dirs, ref $attribs{FILES} ? |
451 | @{$attribs{FILES}} : |
452 | split /\s+/, $attribs{FILES} ; |
453 | } |
479d2113 |
454 | |
7292dc67 |
455 | push(@files, qw[$(MAKE_APERL_FILE) |
456 | perlmain.c tmon.out mon.out so_locations |
457 | blibdirs.ts pm_to_blib pm_to_blib.ts |
458 | *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT) |
459 | $(BOOTSTRAP) $(BASEEXT).bso |
460 | $(BASEEXT).def lib$(BASEEXT).def |
461 | $(BASEEXT).exp $(BASEEXT).x |
462 | ]); |
479d2113 |
463 | |
7292dc67 |
464 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all')); |
465 | push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld')); |
479d2113 |
466 | |
7292dc67 |
467 | # core files |
468 | push(@files, qw[core core.*perl.*.? *perl.core]); |
469 | push(@files, map { "core." . "[0-9]"x$_ } (1..5)); |
479d2113 |
470 | |
7292dc67 |
471 | # OS specific things to clean up. Use @dirs since we don't know |
472 | # what might be in here. |
473 | push @dirs, $self->extra_clean_files; |
f6d6199c |
474 | |
7292dc67 |
475 | # Occasionally files are repeated several times from different sources |
476 | { my(%f) = map { ($_ => 1) } @files; @files = keys %f; } |
477 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; } |
f6d6199c |
478 | |
7292dc67 |
479 | push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files); |
480 | push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs); |
f6d6199c |
481 | |
7292dc67 |
482 | # Leave Makefile.old around for realclean |
483 | push @m, <<'MAKE'; |
484 | - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL) |
485 | MAKE |
479d2113 |
486 | |
7292dc67 |
487 | push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP}; |
479d2113 |
488 | |
7292dc67 |
489 | join("", @m); |
490 | } |
491 | |
492 | |
493 | =head3 clean_subdirs_target |
494 | |
495 | my $make_frag = $MM->clean_subdirs_target; |
496 | |
497 | Returns the clean_subdirs target. This is used by the clean target to |
498 | call clean on any subdirectories which contain Makefiles. |
479d2113 |
499 | |
500 | =cut |
501 | |
7292dc67 |
502 | sub clean_subdirs_target { |
503 | my($self) = shift; |
479d2113 |
504 | |
7292dc67 |
505 | # No subdirectories, no cleaning. |
506 | return <<'NOOP_FRAG' unless @{$self->{DIR}}; |
507 | clean_subdirs : |
508 | $(NOECHO) $(NOOP) |
509 | NOOP_FRAG |
510 | |
511 | |
512 | my $clean = "clean_subdirs :\n"; |
513 | |
514 | for my $dir (@{$self->{DIR}}) { |
515 | my $subclean = $self->oneliner(sprintf <<'CODE', $dir); |
516 | chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)'; |
517 | CODE |
518 | |
519 | $clean .= "\t$subclean\n"; |
520 | } |
521 | |
522 | return $clean; |
479d2113 |
523 | } |
f6d6199c |
524 | |
f6d6199c |
525 | |
7292dc67 |
526 | =head3 dir_target |
f6d6199c |
527 | |
7292dc67 |
528 | my $make_frag = $mm->dir_target(@directories); |
f6d6199c |
529 | |
7292dc67 |
530 | Generates targets to create the specified directories and set its |
531 | permission to 0755. |
f6d6199c |
532 | |
7292dc67 |
533 | Because depending on a directory to just ensure it exists doesn't work |
534 | too well (the modified time changes too often) dir_target() creates a |
535 | .exists file in the created directory. It is this you should depend on. |
536 | For portability purposes you should use the $(DIRFILESEP) macro rather |
537 | than a '/' to seperate the directory from the file. |
538 | |
539 | yourdirectory$(DIRFILESEP).exists |
f6d6199c |
540 | |
541 | =cut |
542 | |
7292dc67 |
543 | sub dir_target { |
544 | my($self, @dirs) = @_; |
f6d6199c |
545 | |
7292dc67 |
546 | my $make = ''; |
547 | foreach my $dir (@dirs) { |
548 | $make .= sprintf <<'MAKE', ($dir) x 7; |
087dded7 |
549 | %s$(DFSEP).exists :: Makefile.PL |
7292dc67 |
550 | $(NOECHO) $(MKPATH) %s |
551 | $(NOECHO) $(CHMOD) 755 %s |
552 | $(NOECHO) $(TOUCH) %s$(DFSEP).exists |
f6d6199c |
553 | |
7292dc67 |
554 | MAKE |
f6d6199c |
555 | |
7292dc67 |
556 | } |
f6d6199c |
557 | |
7292dc67 |
558 | return $make; |
559 | } |
f6d6199c |
560 | |
7292dc67 |
561 | |
562 | =head3 distdir |
563 | |
564 | Defines the scratch directory target that will hold the distribution |
565 | before tar-ing (or shar-ing). |
f6d6199c |
566 | |
567 | =cut |
568 | |
7292dc67 |
569 | # For backwards compatibility. |
570 | *dist_dir = *distdir; |
f6d6199c |
571 | |
7292dc67 |
572 | sub distdir { |
573 | my($self) = shift; |
479d2113 |
574 | |
7292dc67 |
575 | my $meta_target = $self->{NO_META} ? '' : 'distmeta'; |
576 | my $sign_target = !$self->{SIGN} ? '' : 'distsignature'; |
479d2113 |
577 | |
7292dc67 |
578 | return sprintf <<'MAKE_FRAG', $meta_target, $sign_target; |
579 | create_distdir : |
580 | $(RM_RF) $(DISTVNAME) |
581 | $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \ |
582 | -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');" |
479d2113 |
583 | |
7292dc67 |
584 | distdir : create_distdir %s %s |
585 | $(NOECHO) $(NOOP) |
586 | |
587 | MAKE_FRAG |
588 | |
589 | } |
590 | |
591 | |
592 | =head3 dist_test |
593 | |
594 | Defines a target that produces the distribution in the |
595 | scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that |
596 | subdirectory. |
479d2113 |
597 | |
598 | =cut |
599 | |
7292dc67 |
600 | sub dist_test { |
601 | my($self) = shift; |
602 | |
603 | my $mpl_args = join " ", map qq["$_"], @ARGV; |
604 | |
605 | my $test = $self->cd('$(DISTVNAME)', |
606 | '$(ABSPERLRUN) Makefile.PL '.$mpl_args, |
607 | '$(MAKE) $(PASTHRU)', |
608 | '$(MAKE) test $(PASTHRU)' |
609 | ); |
610 | |
611 | return sprintf <<'MAKE_FRAG', $test; |
612 | disttest : distdir |
613 | %s |
614 | |
615 | MAKE_FRAG |
616 | |
479d2113 |
617 | |
479d2113 |
618 | } |
619 | |
479d2113 |
620 | |
7292dc67 |
621 | =head3 dynamic (o) |
622 | |
623 | Defines the dynamic target. |
479d2113 |
624 | |
625 | =cut |
626 | |
7292dc67 |
627 | sub dynamic { |
628 | # --- Dynamic Loading Sections --- |
479d2113 |
629 | |
7292dc67 |
630 | my($self) = shift; |
631 | ' |
632 | dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT) |
633 | $(NOECHO) $(NOOP) |
634 | '; |
635 | } |
479d2113 |
636 | |
479d2113 |
637 | |
7292dc67 |
638 | =head3 makemakerdflt_target |
639 | |
640 | my $make_frag = $mm->makemakerdflt_target |
641 | |
642 | Returns a make fragment with the makemakerdeflt_target specified. |
643 | This target is the first target in the Makefile, is the default target |
644 | and simply points off to 'all' just in case any make variant gets |
645 | confused or something gets snuck in before the real 'all' target. |
479d2113 |
646 | |
7292dc67 |
647 | =cut |
648 | |
649 | sub makemakerdflt_target { |
650 | return <<'MAKE_FRAG'; |
651 | makemakerdflt: all |
652 | $(NOECHO) $(NOOP) |
479d2113 |
653 | MAKE_FRAG |
654 | |
655 | } |
656 | |
657 | |
7292dc67 |
658 | =head3 manifypods_target |
479d2113 |
659 | |
7292dc67 |
660 | my $manifypods_target = $self->manifypods_target; |
661 | |
662 | Generates the manifypods target. This target generates man pages from |
663 | all POD files in MAN1PODS and MAN3PODS. |
479d2113 |
664 | |
665 | =cut |
666 | |
7292dc67 |
667 | sub manifypods_target { |
668 | my($self) = shift; |
479d2113 |
669 | |
7292dc67 |
670 | my $man1pods = ''; |
671 | my $man3pods = ''; |
672 | my $dependencies = ''; |
673 | |
674 | # populate manXpods & dependencies: |
675 | foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) { |
676 | $dependencies .= " \\\n\t$name"; |
677 | } |
678 | |
679 | foreach my $name (keys %{$self->{MAN3PODS}}) { |
680 | $dependencies .= " \\\n\t$name" |
681 | } |
682 | |
683 | my $manify = <<END; |
684 | manifypods : pure_all $dependencies |
685 | END |
686 | |
687 | my @man_cmds; |
688 | foreach my $section (qw(1 3)) { |
689 | my $pods = $self->{"MAN${section}PODS"}; |
690 | push @man_cmds, $self->split_command(<<CMD, %$pods); |
691 | \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW) |
692 | CMD |
693 | } |
694 | |
695 | $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds; |
696 | $manify .= join '', map { "$_\n" } @man_cmds; |
479d2113 |
697 | |
7292dc67 |
698 | return $manify; |
479d2113 |
699 | } |
700 | |
701 | |
7292dc67 |
702 | =head3 metafile_target |
479d2113 |
703 | |
704 | my $target = $mm->metafile_target; |
705 | |
706 | Generate the metafile target. |
707 | |
7292dc67 |
708 | Writes the file META.yml YAML encoded meta-data about the module in |
709 | the distdir. The format follows Module::Build's as closely as |
710 | possible. Additionally, we include: |
479d2113 |
711 | |
712 | version_from |
713 | installdirs |
714 | |
715 | =cut |
716 | |
717 | sub metafile_target { |
718 | my $self = shift; |
719 | |
431b0fc4 |
720 | return <<'MAKE_FRAG' if $self->{NO_META}; |
721 | metafile: |
722 | $(NOECHO) $(NOOP) |
723 | MAKE_FRAG |
724 | |
479d2113 |
725 | my $prereq_pm = ''; |
0fdc96ff |
726 | foreach my $mod ( sort { lc $a cmp lc $b } keys %{$self->{PREREQ_PM}} ) { |
727 | my $ver = $self->{PREREQ_PM}{$mod}; |
2977d345 |
728 | $prereq_pm .= sprintf "\n %-30s %s", "$mod:", $ver; |
479d2113 |
729 | } |
a7d1454b |
730 | |
2977d345 |
731 | # Use a list to preserve order. |
732 | my @meta_to_mm = ( |
733 | name => $self->{DISTNAME}, |
734 | version => $self->{VERSION}, |
735 | abstract => $self->{ABSTRACT}, |
736 | license => $self->{LICENSE} || 'unknown', |
737 | generated_by => |
738 | "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION", |
739 | author => $self->{AUTHOR}, |
740 | distribution_type => $self->{PM} ? 'module' : 'script', |
741 | ); |
742 | |
743 | my $meta = "--- #YAML:1.0\n"; |
744 | |
745 | while( @meta_to_mm ) { |
746 | my($key, $val) = splice @meta_to_mm, 0, 2; |
747 | |
748 | $val = '~' unless defined $val; |
749 | |
750 | $meta .= sprintf "%-20s %s\n", "$key:", $val; |
751 | }; |
752 | |
753 | $meta .= <<YAML; |
754 | requires: $prereq_pm |
755 | meta-spec: |
756 | url: <http://module-build.sourceforge.net/META-spec-new.html>; |
757 | version: 1.1 |
479d2113 |
758 | YAML |
759 | |
2977d345 |
760 | $meta .= $self->{EXTRA_META} if $self->{EXTRA_META}; |
761 | |
a7d1454b |
762 | my @write_meta = $self->echo($meta, 'META_new.yml'); |
a7d1454b |
763 | |
7292dc67 |
764 | return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta); |
765 | metafile : create_distdir |
a7d1454b |
766 | $(NOECHO) $(ECHO) Generating META.yml |
479d2113 |
767 | %s |
7292dc67 |
768 | -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml |
479d2113 |
769 | MAKE_FRAG |
770 | |
771 | } |
772 | |
773 | |
7292dc67 |
774 | =head3 distmeta_target |
bb68fe9e |
775 | |
7292dc67 |
776 | my $make_frag = $mm->distmeta_target; |
bb68fe9e |
777 | |
7292dc67 |
778 | Generates the distmeta target to add META.yml to the MANIFEST in the |
779 | distdir. |
bb68fe9e |
780 | |
781 | =cut |
782 | |
7292dc67 |
783 | sub distmeta_target { |
bb68fe9e |
784 | my $self = shift; |
785 | |
7292dc67 |
786 | my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']); |
787 | eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) } |
788 | or print "Could not add META.yml to MANIFEST: $${'@'}\n" |
789 | CODE |
bb68fe9e |
790 | |
7292dc67 |
791 | my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta); |
bb68fe9e |
792 | |
7292dc67 |
793 | return sprintf <<'MAKE', $add_meta_to_distdir; |
794 | distmeta : create_distdir metafile |
795 | $(NOECHO) %s |
796 | |
797 | MAKE |
bb68fe9e |
798 | |
7292dc67 |
799 | } |
bb68fe9e |
800 | |
479d2113 |
801 | |
7292dc67 |
802 | =head3 realclean (o) |
479d2113 |
803 | |
7292dc67 |
804 | Defines the realclean target. |
479d2113 |
805 | |
806 | =cut |
807 | |
7292dc67 |
808 | sub realclean { |
809 | my($self, %attribs) = @_; |
479d2113 |
810 | |
7292dc67 |
811 | my @dirs = qw($(DISTVNAME)); |
812 | my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD)); |
431b0fc4 |
813 | |
76ca89ed |
814 | # Special exception for the perl core where INST_* is not in blib. |
815 | # This cleans up the files built from the ext/ directory (all XS). |
816 | if( $self->{PERL_CORE} ) { |
7292dc67 |
817 | push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR)); |
76ca89ed |
818 | push @files, values %{$self->{PM}}; |
7292dc67 |
819 | } |
479d2113 |
820 | |
7292dc67 |
821 | if( $self->has_link_code ){ |
822 | push @files, qw($(OBJECT)); |
823 | } |
824 | |
825 | if( $attribs{FILES} ) { |
826 | if( ref $attribs{FILES} ) { |
827 | push @dirs, @{ $attribs{FILES} }; |
828 | } |
829 | else { |
830 | push @dirs, split /\s+/, $attribs{FILES}; |
831 | } |
832 | } |
833 | |
834 | # Occasionally files are repeated several times from different sources |
835 | { my(%f) = map { ($_ => 1) } @files; @files = keys %f; } |
836 | { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; } |
837 | |
838 | my $rm_cmd = join "\n\t", map { "$_" } |
839 | $self->split_command('- $(RM_F)', @files); |
840 | my $rmf_cmd = join "\n\t", map { "$_" } |
841 | $self->split_command('- $(RM_RF)', @dirs); |
842 | |
843 | my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd; |
844 | # Delete temporary files (via clean) and also delete dist files |
845 | realclean purge :: clean realclean_subdirs |
846 | %s |
847 | %s |
848 | MAKE |
849 | |
850 | $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP}; |
479d2113 |
851 | |
7292dc67 |
852 | return $m; |
479d2113 |
853 | } |
854 | |
855 | |
7292dc67 |
856 | =head3 realclean_subdirs_target |
bb68fe9e |
857 | |
7292dc67 |
858 | my $make_frag = $MM->realclean_subdirs_target; |
bb68fe9e |
859 | |
7292dc67 |
860 | Returns the realclean_subdirs target. This is used by the realclean |
861 | target to call realclean on any subdirectories which contain Makefiles. |
bb68fe9e |
862 | |
863 | =cut |
864 | |
7292dc67 |
865 | sub realclean_subdirs_target { |
bb68fe9e |
866 | my $self = shift; |
867 | |
7292dc67 |
868 | return <<'NOOP_FRAG' unless @{$self->{DIR}}; |
869 | realclean_subdirs : |
bb68fe9e |
870 | $(NOECHO) $(NOOP) |
7292dc67 |
871 | NOOP_FRAG |
bb68fe9e |
872 | |
7292dc67 |
873 | my $rclean = "realclean_subdirs :\n"; |
874 | |
875 | foreach my $dir (@{$self->{DIR}}) { |
876 | foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) { |
877 | my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2); |
878 | chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s'; |
bb68fe9e |
879 | CODE |
880 | |
7292dc67 |
881 | $rclean .= sprintf <<'RCLEAN', $subrclean; |
882 | - %s |
883 | RCLEAN |
bb68fe9e |
884 | |
7292dc67 |
885 | } |
886 | } |
bb68fe9e |
887 | |
7292dc67 |
888 | return $rclean; |
889 | } |
bb68fe9e |
890 | |
479d2113 |
891 | |
7292dc67 |
892 | =head3 signature_target |
479d2113 |
893 | |
7292dc67 |
894 | my $target = $mm->signature_target; |
479d2113 |
895 | |
7292dc67 |
896 | Generate the signature target. |
479d2113 |
897 | |
7292dc67 |
898 | Writes the file SIGNATURE with "cpansign -s". |
479d2113 |
899 | |
7292dc67 |
900 | =cut |
479d2113 |
901 | |
7292dc67 |
902 | sub signature_target { |
903 | my $self = shift; |
479d2113 |
904 | |
7292dc67 |
905 | return <<'MAKE_FRAG'; |
906 | signature : |
907 | cpansign -s |
908 | MAKE_FRAG |
479d2113 |
909 | |
7292dc67 |
910 | } |
479d2113 |
911 | |
7292dc67 |
912 | |
913 | =head3 distsignature_target |
914 | |
915 | my $make_frag = $mm->distsignature_target; |
916 | |
917 | Generates the distsignature target to add SIGNATURE to the MANIFEST in the |
918 | distdir. |
919 | |
920 | =cut |
921 | |
922 | sub distsignature_target { |
923 | my $self = shift; |
924 | |
925 | my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']); |
926 | eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } |
927 | or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n" |
479d2113 |
928 | CODE |
929 | |
7292dc67 |
930 | my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s'); |
479d2113 |
931 | |
7292dc67 |
932 | # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not |
933 | # exist |
934 | my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE'); |
935 | my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign ); |
479d2113 |
936 | |
7292dc67 |
937 | return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist |
938 | distsignature : create_distdir |
939 | $(NOECHO) %s |
940 | $(NOECHO) %s |
941 | %s |
479d2113 |
942 | |
7292dc67 |
943 | MAKE |
479d2113 |
944 | |
7292dc67 |
945 | } |
479d2113 |
946 | |
947 | |
7292dc67 |
948 | =head3 special_targets |
479d2113 |
949 | |
7292dc67 |
950 | my $make_frag = $mm->special_targets |
479d2113 |
951 | |
7292dc67 |
952 | Returns a make fragment containing any targets which have special |
953 | meaning to make. For example, .SUFFIXES and .PHONY. |
479d2113 |
954 | |
7292dc67 |
955 | =cut |
479d2113 |
956 | |
7292dc67 |
957 | sub special_targets { |
958 | my $make_frag = <<'MAKE_FRAG'; |
959 | .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT) |
479d2113 |
960 | |
7292dc67 |
961 | .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir |
479d2113 |
962 | |
7292dc67 |
963 | MAKE_FRAG |
479d2113 |
964 | |
7292dc67 |
965 | $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT}; |
966 | .NO_CONFIG_REC: Makefile |
479d2113 |
967 | |
7292dc67 |
968 | MAKE_FRAG |
479d2113 |
969 | |
7292dc67 |
970 | return $make_frag; |
971 | } |
479d2113 |
972 | |
479d2113 |
973 | |
479d2113 |
974 | |
479d2113 |
975 | |
7292dc67 |
976 | =head2 Init methods |
977 | |
978 | Methods which help initialize the MakeMaker object and macros. |
979 | |
980 | |
2977d345 |
981 | =head3 init_ABSTRACT |
982 | |
983 | $mm->init_ABSTRACT |
984 | |
985 | =cut |
986 | |
987 | sub init_ABSTRACT { |
988 | my $self = shift; |
989 | |
990 | if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) { |
991 | warn "Both ABSTRACT_FROM and ABSTRACT are set. ". |
992 | "Ignoring ABSTRACT_FROM.\n"; |
993 | return; |
994 | } |
995 | |
996 | if ($self->{ABSTRACT_FROM}){ |
997 | $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or |
998 | carp "WARNING: Setting ABSTRACT via file ". |
999 | "'$self->{ABSTRACT_FROM}' failed\n"; |
1000 | } |
1001 | } |
1002 | |
7292dc67 |
1003 | =head3 init_INST |
1004 | |
1005 | $mm->init_INST; |
1006 | |
1007 | Called by init_main. Sets up all INST_* variables except those related |
1008 | to XS code. Those are handled in init_xs. |
1009 | |
1010 | =cut |
1011 | |
1012 | sub init_INST { |
1013 | my($self) = shift; |
1014 | |
1015 | $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch"); |
1016 | $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin'); |
1017 | |
1018 | # INST_LIB typically pre-set if building an extension after |
1019 | # perl has been built and installed. Setting INST_LIB allows |
1020 | # you to build directly into, say $Config{privlibexp}. |
1021 | unless ($self->{INST_LIB}){ |
1022 | if ($self->{PERL_CORE}) { |
1023 | if (defined $Cross::platform) { |
1024 | $self->{INST_LIB} = $self->{INST_ARCHLIB} = |
1025 | $self->catdir($self->{PERL_LIB},"..","xlib", |
1026 | $Cross::platform); |
1027 | } |
1028 | else { |
1029 | $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB}; |
1030 | } |
1031 | } else { |
1032 | $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib"); |
1033 | } |
1034 | } |
1035 | |
1036 | my @parentdir = split(/::/, $self->{PARENT_NAME}); |
1037 | $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir); |
1038 | $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir); |
1039 | $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto', |
1040 | '$(FULLEXT)'); |
1041 | $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto', |
1042 | '$(FULLEXT)'); |
1043 | |
1044 | $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script'); |
1045 | |
1046 | $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1'); |
1047 | $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3'); |
1048 | |
1049 | return 1; |
1050 | } |
1051 | |
1052 | |
1053 | =head3 init_INSTALL |
1054 | |
1055 | $mm->init_INSTALL; |
1056 | |
1057 | Called by init_main. Sets up all INSTALL_* variables (except |
1058 | INSTALLDIRS) and *PREFIX. |
1059 | |
1060 | =cut |
1061 | |
1062 | sub init_INSTALL { |
1063 | my($self) = shift; |
1064 | |
2977d345 |
1065 | if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) { |
1066 | die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n"; |
7292dc67 |
1067 | } |
1068 | |
2977d345 |
1069 | if( $self->{ARGS}{INSTALL_BASE} ) { |
1070 | $self->init_INSTALL_from_INSTALL_BASE; |
7292dc67 |
1071 | } |
1072 | else { |
1073 | $self->init_INSTALL_from_PREFIX; |
1074 | } |
1075 | } |
1076 | |
1077 | |
1078 | =head3 init_INSTALL_from_PREFIX |
1079 | |
1080 | $mm->init_INSTALL_from_PREFIX; |
1081 | |
1082 | =cut |
1083 | |
1084 | sub init_INSTALL_from_PREFIX { |
1085 | my $self = shift; |
1086 | |
1087 | $self->init_lib2arch; |
1088 | |
1089 | # There are often no Config.pm defaults for these new man variables so |
1090 | # we fall back to the old behavior which is to use installman*dir |
1091 | foreach my $num (1, 3) { |
1092 | my $k = 'installsiteman'.$num.'dir'; |
1093 | |
1094 | $self->{uc $k} ||= uc "\$(installman${num}dir)" |
1095 | unless $Config{$k}; |
1096 | } |
1097 | |
1098 | foreach my $num (1, 3) { |
1099 | my $k = 'installvendorman'.$num.'dir'; |
1100 | |
1101 | unless( $Config{$k} ) { |
1102 | $self->{uc $k} ||= $Config{usevendorprefix} |
1103 | ? uc "\$(installman${num}dir)" |
1104 | : ''; |
1105 | } |
1106 | } |
1107 | |
1108 | $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)' |
1109 | unless $Config{installsitebin}; |
002b9267 |
1110 | $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)' |
1111 | unless $Config{installsitescript}; |
7292dc67 |
1112 | |
1113 | unless( $Config{installvendorbin} ) { |
1114 | $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} |
1115 | ? $Config{installbin} |
1116 | : ''; |
1117 | } |
002b9267 |
1118 | unless( $Config{installvendorscript} ) { |
1119 | $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix} |
1120 | ? $Config{installscript} |
1121 | : ''; |
1122 | } |
7292dc67 |
1123 | |
1124 | |
1125 | my $iprefix = $Config{installprefixexp} || $Config{installprefix} || |
1126 | $Config{prefixexp} || $Config{prefix} || ''; |
1127 | my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : ''; |
1128 | my $sprefix = $Config{siteprefixexp} || ''; |
1129 | |
1130 | # 5.005_03 doesn't have a siteprefix. |
1131 | $sprefix = $iprefix unless $sprefix; |
1132 | |
1133 | |
1134 | $self->{PREFIX} ||= ''; |
1135 | |
1136 | if( $self->{PREFIX} ) { |
1137 | @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} = |
1138 | ('$(PREFIX)') x 3; |
1139 | } |
1140 | else { |
1141 | $self->{PERLPREFIX} ||= $iprefix; |
1142 | $self->{SITEPREFIX} ||= $sprefix; |
1143 | $self->{VENDORPREFIX} ||= $vprefix; |
1144 | |
1145 | # Lots of MM extension authors like to use $(PREFIX) so we |
1146 | # put something sensible in there no matter what. |
1147 | $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)'; |
1148 | } |
1149 | |
1150 | my $arch = $Config{archname}; |
1151 | my $version = $Config{version}; |
1152 | |
1153 | # default style |
1154 | my $libstyle = $Config{installstyle} || 'lib/perl5'; |
1155 | my $manstyle = ''; |
1156 | |
1157 | if( $self->{LIBSTYLE} ) { |
1158 | $libstyle = $self->{LIBSTYLE}; |
1159 | $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : ''; |
1160 | } |
1161 | |
1162 | # Some systems, like VOS, set installman*dir to '' if they can't |
1163 | # read man pages. |
1164 | for my $num (1, 3) { |
1165 | $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none' |
1166 | unless $Config{'installman'.$num.'dir'}; |
1167 | } |
1168 | |
1169 | my %bin_layouts = |
1170 | ( |
1171 | bin => { s => $iprefix, |
1172 | t => 'perl', |
1173 | d => 'bin' }, |
1174 | vendorbin => { s => $vprefix, |
1175 | t => 'vendor', |
1176 | d => 'bin' }, |
1177 | sitebin => { s => $sprefix, |
1178 | t => 'site', |
1179 | d => 'bin' }, |
1180 | script => { s => $iprefix, |
1181 | t => 'perl', |
1182 | d => 'bin' }, |
002b9267 |
1183 | vendorscript=> { s => $vprefix, |
1184 | t => 'vendor', |
1185 | d => 'bin' }, |
1186 | sitescript => { s => $sprefix, |
1187 | t => 'site', |
1188 | d => 'bin' }, |
7292dc67 |
1189 | ); |
1190 | |
1191 | my %man_layouts = |
1192 | ( |
1193 | man1dir => { s => $iprefix, |
1194 | t => 'perl', |
1195 | d => 'man/man1', |
1196 | style => $manstyle, }, |
1197 | siteman1dir => { s => $sprefix, |
1198 | t => 'site', |
1199 | d => 'man/man1', |
1200 | style => $manstyle, }, |
1201 | vendorman1dir => { s => $vprefix, |
1202 | t => 'vendor', |
1203 | d => 'man/man1', |
1204 | style => $manstyle, }, |
1205 | |
1206 | man3dir => { s => $iprefix, |
1207 | t => 'perl', |
1208 | d => 'man/man3', |
1209 | style => $manstyle, }, |
1210 | siteman3dir => { s => $sprefix, |
1211 | t => 'site', |
1212 | d => 'man/man3', |
1213 | style => $manstyle, }, |
1214 | vendorman3dir => { s => $vprefix, |
1215 | t => 'vendor', |
1216 | d => 'man/man3', |
1217 | style => $manstyle, }, |
1218 | ); |
1219 | |
1220 | my %lib_layouts = |
1221 | ( |
1222 | privlib => { s => $iprefix, |
1223 | t => 'perl', |
1224 | d => '', |
1225 | style => $libstyle, }, |
1226 | vendorlib => { s => $vprefix, |
1227 | t => 'vendor', |
1228 | d => '', |
1229 | style => $libstyle, }, |
1230 | sitelib => { s => $sprefix, |
1231 | t => 'site', |
1232 | d => 'site_perl', |
1233 | style => $libstyle, }, |
1234 | |
1235 | archlib => { s => $iprefix, |
1236 | t => 'perl', |
1237 | d => "$version/$arch", |
1238 | style => $libstyle }, |
1239 | vendorarch => { s => $vprefix, |
1240 | t => 'vendor', |
1241 | d => "$version/$arch", |
1242 | style => $libstyle }, |
1243 | sitearch => { s => $sprefix, |
1244 | t => 'site', |
1245 | d => "site_perl/$version/$arch", |
1246 | style => $libstyle }, |
1247 | ); |
1248 | |
1249 | |
1250 | # Special case for LIB. |
1251 | if( $self->{LIB} ) { |
1252 | foreach my $var (keys %lib_layouts) { |
1253 | my $Installvar = uc "install$var"; |
1254 | |
1255 | if( $var =~ /arch/ ) { |
1256 | $self->{$Installvar} ||= |
1257 | $self->catdir($self->{LIB}, $Config{archname}); |
1258 | } |
1259 | else { |
1260 | $self->{$Installvar} ||= $self->{LIB}; |
1261 | } |
1262 | } |
1263 | } |
1264 | |
1265 | my %type2prefix = ( perl => 'PERLPREFIX', |
1266 | site => 'SITEPREFIX', |
1267 | vendor => 'VENDORPREFIX' |
1268 | ); |
1269 | |
1270 | my %layouts = (%bin_layouts, %man_layouts, %lib_layouts); |
1271 | while( my($var, $layout) = each(%layouts) ) { |
1272 | my($s, $t, $d, $style) = @{$layout}{qw(s t d style)}; |
1273 | my $r = '$('.$type2prefix{$t}.')'; |
1274 | |
1275 | print STDERR "Prefixing $var\n" if $Verbose >= 2; |
1276 | |
1277 | my $installvar = "install$var"; |
1278 | my $Installvar = uc $installvar; |
1279 | next if $self->{$Installvar}; |
1280 | |
1281 | $d = "$style/$d" if $style; |
1282 | $self->prefixify($installvar, $s, $r, $d); |
1283 | |
1284 | print STDERR " $Installvar == $self->{$Installvar}\n" |
1285 | if $Verbose >= 2; |
1286 | } |
1287 | |
1288 | # Generate these if they weren't figured out. |
1289 | $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH}; |
1290 | $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB}; |
1291 | |
1292 | return 1; |
1293 | } |
1294 | |
1295 | |
2977d345 |
1296 | =head3 init_from_INSTALL_BASE |
7292dc67 |
1297 | |
2977d345 |
1298 | $mm->init_from_INSTALL_BASE |
7292dc67 |
1299 | |
1300 | =cut |
1301 | |
1302 | my %map = ( |
1303 | lib => [qw(lib perl5)], |
1304 | arch => [('lib', 'perl5', $Config{archname})], |
1305 | bin => [qw(bin)], |
1306 | man1dir => [qw(man man1)], |
1307 | man3dir => [qw(man man3)] |
1308 | ); |
1309 | $map{script} = $map{bin}; |
1310 | |
2977d345 |
1311 | sub init_INSTALL_from_INSTALL_BASE { |
7292dc67 |
1312 | my $self = shift; |
1313 | |
1314 | @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} = |
2977d345 |
1315 | '$(INSTALL_BASE)'; |
7292dc67 |
1316 | |
1317 | my %install; |
1318 | foreach my $thing (keys %map) { |
1319 | foreach my $dir (('', 'SITE', 'VENDOR')) { |
1320 | my $uc_thing = uc $thing; |
1321 | my $key = "INSTALL".$dir.$uc_thing; |
1322 | |
1323 | $install{$key} ||= |
2977d345 |
1324 | $self->catdir('$(INSTALL_BASE)', @{$map{$thing}}); |
7292dc67 |
1325 | } |
1326 | } |
1327 | |
1328 | # Adjust for variable quirks. |
1329 | $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH}; |
1330 | $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB}; |
7292dc67 |
1331 | |
1332 | foreach my $key (keys %install) { |
1333 | $self->{$key} ||= $install{$key}; |
1334 | } |
1335 | |
1336 | return 1; |
1337 | } |
1338 | |
1339 | |
1340 | =head3 init_VERSION I<Abstract> |
1341 | |
1342 | $mm->init_VERSION |
1343 | |
1344 | Initialize macros representing versions of MakeMaker and other tools |
1345 | |
1346 | MAKEMAKER: path to the MakeMaker module. |
1347 | |
1348 | MM_VERSION: ExtUtils::MakeMaker Version |
1349 | |
1350 | MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards |
1351 | compat) |
1352 | |
1353 | VERSION: version of your module |
1354 | |
1355 | VERSION_MACRO: which macro represents the version (usually 'VERSION') |
1356 | |
1357 | VERSION_SYM: like version but safe for use as an RCS revision number |
1358 | |
1359 | DEFINE_VERSION: -D line to set the module version when compiling |
1360 | |
1361 | XS_VERSION: version in your .xs file. Defaults to $(VERSION) |
1362 | |
1363 | XS_VERSION_MACRO: which macro represents the XS version. |
1364 | |
1365 | XS_DEFINE_VERSION: -D line to set the xs version when compiling. |
1366 | |
1367 | Called by init_main. |
1368 | |
1369 | =cut |
1370 | |
1371 | sub init_VERSION { |
1372 | my($self) = shift; |
1373 | |
1374 | $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename; |
1375 | $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION; |
1376 | $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision; |
1377 | $self->{VERSION_FROM} ||= ''; |
1378 | |
1379 | if ($self->{VERSION_FROM}){ |
1380 | $self->{VERSION} = $self->parse_version($self->{VERSION_FROM}); |
1381 | if( $self->{VERSION} eq 'undef' ) { |
2977d345 |
1382 | carp("WARNING: Setting VERSION via file ". |
1383 | "'$self->{VERSION_FROM}' failed\n"); |
7292dc67 |
1384 | } |
1385 | } |
1386 | |
1387 | # strip blanks |
1388 | if (defined $self->{VERSION}) { |
1389 | $self->{VERSION} =~ s/^\s+//; |
1390 | $self->{VERSION} =~ s/\s+$//; |
1391 | } |
1392 | else { |
1393 | $self->{VERSION} = ''; |
1394 | } |
1395 | |
1396 | |
1397 | $self->{VERSION_MACRO} = 'VERSION'; |
1398 | ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g; |
1399 | $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"'; |
1400 | |
1401 | |
1402 | # Graham Barr and Paul Marquess had some ideas how to ensure |
1403 | # version compatibility between the *.pm file and the |
1404 | # corresponding *.xs file. The bottomline was, that we need an |
1405 | # XS_VERSION macro that defaults to VERSION: |
1406 | $self->{XS_VERSION} ||= $self->{VERSION}; |
1407 | |
1408 | $self->{XS_VERSION_MACRO} = 'XS_VERSION'; |
1409 | $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"'; |
1410 | |
1411 | } |
1412 | |
1413 | |
1414 | =head3 init_others I<Abstract> |
479d2113 |
1415 | |
1416 | $MM->init_others(); |
1417 | |
1418 | Initializes the macro definitions used by tools_other() and places them |
1419 | in the $MM object. |
1420 | |
1421 | If there is no description, its the same as the parameter to |
1422 | WriteMakefile() documented in ExtUtils::MakeMaker. |
1423 | |
1424 | Defines at least these macros. |
1425 | |
1426 | Macro Description |
1427 | |
dedf98bc |
1428 | NOOP Do nothing |
1429 | NOECHO Tell make not to display the command itself |
479d2113 |
1430 | |
1431 | MAKEFILE |
1432 | FIRST_MAKEFILE |
1433 | MAKEFILE_OLD |
1434 | MAKE_APERL_FILE File used by MAKE_APERL |
1435 | |
2977d345 |
1436 | SHELL Program used to run shell commands |
479d2113 |
1437 | |
dedf98bc |
1438 | ECHO Print text adding a newline on the end |
479d2113 |
1439 | RM_F Remove a file |
1440 | RM_RF Remove a directory |
1441 | TOUCH Update a file's timestamp |
1442 | TEST_F Test for a file's existence |
1443 | CP Copy a file |
1444 | MV Move a file |
1445 | CHMOD Change permissions on a |
1446 | file |
1447 | |
1448 | UMASK_NULL Nullify umask |
3c4b39be |
1449 | DEV_NULL Suppress all command output |
479d2113 |
1450 | |
7292dc67 |
1451 | |
1452 | =head3 init_DIRFILESEP I<Abstract> |
479d2113 |
1453 | |
1454 | $MM->init_DIRFILESEP; |
1455 | my $dirfilesep = $MM->{DIRFILESEP}; |
1456 | |
1457 | Initializes the DIRFILESEP macro which is the seperator between the |
1458 | directory and filename in a filepath. ie. / on Unix, \ on Win32 and |
1459 | nothing on VMS. |
1460 | |
1461 | For example: |
1462 | |
1463 | # instead of $(INST_ARCHAUTODIR)/extralibs.ld |
1464 | $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld |
1465 | |
1466 | Something of a hack but it prevents a lot of code duplication between |
1467 | MM_* variants. |
1468 | |
1469 | Do not use this as a seperator between directories. Some operating |
1470 | systems use different seperators between subdirectories as between |
1471 | directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS). |
1472 | |
7292dc67 |
1473 | =head3 init_linker I<Abstract> |
479d2113 |
1474 | |
1475 | $mm->init_linker; |
1476 | |
1477 | Initialize macros which have to do with linking. |
1478 | |
1479 | PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic |
1480 | extensions. |
1481 | |
1482 | PERL_ARCHIVE_AFTER: path to a library which should be put on the |
1483 | linker command line I<after> the external libraries to be linked to |
1484 | dynamic extensions. This may be needed if the linker is one-pass, and |
1485 | Perl includes some overrides for C RTL functions, such as malloc(). |
1486 | |
1487 | EXPORT_LIST: name of a file that is passed to linker to define symbols |
1488 | to be exported. |
1489 | |
1490 | Some OSes do not need these in which case leave it blank. |
1491 | |
1492 | |
7292dc67 |
1493 | =head3 init_platform |
479d2113 |
1494 | |
1495 | $mm->init_platform |
1496 | |
1497 | Initialize any macros which are for platform specific use only. |
1498 | |
1499 | A typical one is the version number of your OS specific mocule. |
1500 | (ie. MM_Unix_VERSION or MM_VMS_VERSION). |
1501 | |
7292dc67 |
1502 | =cut |
479d2113 |
1503 | |
7292dc67 |
1504 | sub init_platform { |
1505 | return ''; |
1506 | } |
479d2113 |
1507 | |
7292dc67 |
1508 | |
2977d345 |
1509 | =head3 init_MAKE |
1510 | |
1511 | $mm->init_MAKE |
7292dc67 |
1512 | |
2977d345 |
1513 | Initialize MAKE from either a MAKE environment variable or $Config{make}. |
1514 | |
1515 | =cut |
1516 | |
1517 | sub init_MAKE { |
1518 | my $self = shift; |
1519 | |
1520 | $self->{MAKE} ||= $ENV{MAKE} || $Config{make}; |
1521 | } |
7292dc67 |
1522 | |
1523 | |
1524 | =head2 Tools |
1525 | |
1526 | A grab bag of methods to generate specific macros and commands. |
1527 | |
1528 | |
1529 | |
1530 | =head3 manifypods |
1531 | |
1532 | Defines targets and routines to translate the pods into manpages and |
1533 | put them into the INST_* directories. |
479d2113 |
1534 | |
1535 | =cut |
1536 | |
7292dc67 |
1537 | sub manifypods { |
1538 | my $self = shift; |
1539 | |
1540 | my $POD2MAN_macro = $self->POD2MAN_macro(); |
1541 | my $manifypods_target = $self->manifypods_target(); |
1542 | |
1543 | return <<END_OF_TARGET; |
1544 | |
1545 | $POD2MAN_macro |
1546 | |
1547 | $manifypods_target |
1548 | |
1549 | END_OF_TARGET |
1550 | |
479d2113 |
1551 | } |
1552 | |
7292dc67 |
1553 | |
1554 | =head3 POD2MAN_macro |
1555 | |
1556 | my $pod2man_macro = $self->POD2MAN_macro |
1557 | |
1558 | Returns a definition for the POD2MAN macro. This is a program |
1559 | which emulates the pod2man utility. You can add more switches to the |
1560 | command by simply appending them on the macro. |
1561 | |
1562 | Typical usage: |
1563 | |
1564 | $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ... |
1565 | |
1566 | =cut |
1567 | |
1568 | sub POD2MAN_macro { |
1569 | my $self = shift; |
1570 | |
1571 | # Need the trailing '--' so perl stops gobbling arguments and - happens |
1572 | # to be an alternative end of line seperator on VMS so we quote it |
1573 | return <<'END_OF_DEF'; |
1574 | POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" |
1575 | POD2MAN = $(POD2MAN_EXE) |
1576 | END_OF_DEF |
479d2113 |
1577 | } |
1578 | |
dedf98bc |
1579 | |
7292dc67 |
1580 | =head3 test_via_harness |
dedf98bc |
1581 | |
7292dc67 |
1582 | my $command = $mm->test_via_harness($perl, $tests); |
dedf98bc |
1583 | |
7292dc67 |
1584 | Returns a $command line which runs the given set of $tests with |
1585 | Test::Harness and the given $perl. |
dedf98bc |
1586 | |
7292dc67 |
1587 | Used on the t/*.t files. |
dedf98bc |
1588 | |
7292dc67 |
1589 | =cut |
dedf98bc |
1590 | |
7292dc67 |
1591 | sub test_via_harness { |
1592 | my($self, $perl, $tests) = @_; |
1593 | |
1594 | return qq{\t$perl "-MExtUtils::Command::MM" }. |
1595 | qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n}; |
1596 | } |
1597 | |
1598 | =head3 test_via_script |
1599 | |
1600 | my $command = $mm->test_via_script($perl, $script); |
1601 | |
1602 | Returns a $command line which just runs a single test without |
1603 | Test::Harness. No checks are done on the results, they're just |
1604 | printed. |
dedf98bc |
1605 | |
7292dc67 |
1606 | Used for test.pl, since they don't always follow Test::Harness |
1607 | formatting. |
1608 | |
1609 | =cut |
1610 | |
1611 | sub test_via_script { |
1612 | my($self, $perl, $script) = @_; |
1613 | return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n}; |
1614 | } |
1615 | |
1616 | |
1617 | =head3 tool_autosplit |
1618 | |
1619 | Defines a simple perl call that runs autosplit. May be deprecated by |
1620 | pm_to_blib soon. |
1621 | |
1622 | =cut |
1623 | |
1624 | sub tool_autosplit { |
1625 | my($self, %attribs) = @_; |
1626 | |
1627 | my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};' |
1628 | : ''; |
1629 | |
1630 | my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen); |
1631 | use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) |
1632 | PERL_CODE |
1633 | |
1634 | return sprintf <<'MAKE_FRAG', $asplit; |
1635 | # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto |
1636 | AUTOSPLITFILE = %s |
1637 | |
1638 | MAKE_FRAG |
1639 | |
1640 | } |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | =head2 File::Spec wrappers |
1646 | |
1647 | ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here |
1648 | override File::Spec. |
1649 | |
1650 | |
1651 | |
1652 | =head3 catfile |
1653 | |
1654 | File::Spec <= 0.83 has a bug where the file part of catfile is not |
1655 | canonicalized. This override fixes that bug. |
1656 | |
1657 | =cut |
1658 | |
1659 | sub catfile { |
1660 | my $self = shift; |
1661 | return $self->canonpath($self->SUPER::catfile(@_)); |
1662 | } |
1663 | |
1664 | |
1665 | |
1666 | =head2 Misc |
1667 | |
1668 | Methods I can't really figure out where they should go yet. |
1669 | |
1670 | |
1671 | =head3 find_tests |
1672 | |
1673 | my $test = $mm->find_tests; |
1674 | |
1675 | Returns a string suitable for feeding to the shell to return all |
1676 | tests in t/*.t. |
1677 | |
1678 | =cut |
1679 | |
1680 | sub find_tests { |
1681 | my($self) = shift; |
1682 | return -d 't' ? 't/*.t' : ''; |
1683 | } |
1684 | |
1685 | |
1686 | =head3 extra_clean_files |
1687 | |
1688 | my @files_to_clean = $MM->extra_clean_files; |
1689 | |
1690 | Returns a list of OS specific files to be removed in the clean target in |
1691 | addition to the usual set. |
1692 | |
1693 | =cut |
1694 | |
1695 | # An empty method here tickled a perl 5.8.1 bug and would return its object. |
1696 | sub extra_clean_files { |
1697 | return; |
1698 | } |
1699 | |
1700 | |
1701 | =head3 installvars |
1702 | |
1703 | my @installvars = $mm->installvars; |
1704 | |
1705 | A list of all the INSTALL* variables without the INSTALL prefix. Useful |
1706 | for iteration or building related variable sets. |
1707 | |
1708 | =cut |
1709 | |
1710 | sub installvars { |
1711 | return qw(PRIVLIB SITELIB VENDORLIB |
1712 | ARCHLIB SITEARCH VENDORARCH |
1713 | BIN SITEBIN VENDORBIN |
002b9267 |
1714 | SCRIPT SITESCRIPT VENDORSCRIPT |
7292dc67 |
1715 | MAN1DIR SITEMAN1DIR VENDORMAN1DIR |
1716 | MAN3DIR SITEMAN3DIR VENDORMAN3DIR |
1717 | ); |
1718 | } |
1719 | |
1720 | |
1721 | =head3 libscan |
1722 | |
1723 | my $wanted = $self->libscan($path); |
1724 | |
1725 | Takes a path to a file or dir and returns an empty string if we don't |
1726 | want to include this file in the library. Otherwise it returns the |
1727 | the $path unchanged. |
1728 | |
1729 | Mainly used to exclude version control administrative directories from |
1730 | installation. |
1731 | |
1732 | =cut |
1733 | |
1734 | sub libscan { |
1735 | my($self,$path) = @_; |
1736 | my($dirs,$file) = ($self->splitpath($path))[1,2]; |
1737 | return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/, |
1738 | $self->splitdir($dirs), $file; |
1739 | |
1740 | return $path; |
1741 | } |
1742 | |
1743 | |
1744 | =head3 platform_constants |
1745 | |
1746 | my $make_frag = $mm->platform_constants |
1747 | |
1748 | Returns a make fragment defining all the macros initialized in |
1749 | init_platform() rather than put them in constants(). |
1750 | |
1751 | =cut |
1752 | |
1753 | sub platform_constants { |
1754 | return ''; |
1755 | } |
479d2113 |
1756 | |
f6d6199c |
1757 | |
1758 | =head1 AUTHOR |
1759 | |
479d2113 |
1760 | Michael G Schwern <schwern@pobox.com> and the denizens of |
1761 | makemaker@perl.org with code from ExtUtils::MM_Unix and |
1762 | ExtUtils::MM_Win32. |
f6d6199c |
1763 | |
1764 | |
1765 | =cut |
1766 | |
1767 | 1; |