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