-
Notifications
You must be signed in to change notification settings - Fork 75
/
MM_Any.pm
3099 lines (2193 loc) · 80.8 KB
/
MM_Any.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ExtUtils::MM_Any;
use strict;
our $VERSION = '7.35_06';
$VERSION =~ tr/_//d;
use Carp;
use File::Spec;
use File::Basename;
BEGIN { our @ISA = qw(File::Spec); }
# We need $Verbose
use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562);
use ExtUtils::MakeMaker::Config;
# So we don't have to keep calling the methods over and over again,
# we have these globals to cache the values. Faster and shrtr.
my $Curdir = __PACKAGE__->curdir;
#my $Updir = __PACKAGE__->updir;
my $METASPEC_URL = 'https://metacpan.org/pod/CPAN::Meta::Spec';
my $METASPEC_V = 2;
=head1 NAME
ExtUtils::MM_Any - Platform-agnostic MM methods
=head1 SYNOPSIS
FOR INTERNAL USE ONLY!
package ExtUtils::MM_SomeOS;
# Temporarily, you have to subclass both. Put MM_Any first.
require ExtUtils::MM_Any;
require ExtUtils::MM_Unix;
@ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);
=head1 DESCRIPTION
B<FOR INTERNAL USE ONLY!>
ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
modules. It contains methods which are either inherently
cross-platform or are written in a cross-platform manner.
Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix. This is a
temporary solution.
B<THIS MAY BE TEMPORARY!>
=head1 METHODS
Any methods marked I<Abstract> must be implemented by subclasses.
=head2 Cross-platform helper methods
These are methods which help writing cross-platform code.
=head3 os_flavor I<Abstract>
my @os_flavor = $mm->os_flavor;
@os_flavor is the style of operating system this is, usually
corresponding to the MM_*.pm file we're using.
The first element of @os_flavor is the major family (ie. Unix,
Windows, VMS, OS/2, etc...) and the rest are sub families.
Some examples:
Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x')
Windows ('Win32')
Win98 ('Win32', 'Win9x')
Linux ('Unix', 'Linux')
MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X')
OS/2 ('OS/2')
This is used to write code for styles of operating system.
See os_flavor_is() for use.
=head3 os_flavor_is
my $is_this_flavor = $mm->os_flavor_is($this_flavor);
my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
Checks to see if the current operating system is one of the given flavors.
This is useful for code like:
if( $mm->os_flavor_is('Unix') ) {
$out = `foo 2>&1`;
}
else {
$out = `foo`;
}
=cut
sub os_flavor_is {
my $self = shift;
my %flavors = map { ($_ => 1) } $self->os_flavor;
return (grep { $flavors{$_} } @_) ? 1 : 0;
}
=head3 can_load_xs
my $can_load_xs = $self->can_load_xs;
Returns true if we have the ability to load XS.
This is important because miniperl, used to build XS modules in the
core, can not load XS.
=cut
sub can_load_xs {
return defined &DynaLoader::boot_DynaLoader ? 1 : 0;
}
=head3 can_run
use ExtUtils::MM;
my $runnable = MM->can_run($Config{make});
If called in a scalar context it will return the full path to the binary
you asked for if it was found, or C<undef> if it was not.
If called in a list context, it will return a list of the full paths to instances
of the binary where found in C<PATH>, or an empty list if it was not found.
Copied from L<IPC::Cmd|IPC::Cmd/"$path = can_run( PROGRAM );">, but modified into
a method (and removed C<$INSTANCES> capability).
=cut
sub can_run {
my ($self, $command) = @_;
# a lot of VMS executables have a symbol defined
# check those first
if ( $^O eq 'VMS' ) {
require VMS::DCLsym;
my $syms = VMS::DCLsym->new;
return $command if scalar $syms->getsym( uc $command );
}
my @possibles;
if( File::Spec->file_name_is_absolute($command) ) {
return $self->maybe_command($command);
} else {
for my $dir (
File::Spec->path,
File::Spec->curdir
) {
next if ! $dir || ! -d $dir;
my $abs = File::Spec->catfile($self->os_flavor_is('Win32') ? Win32::GetShortPathName( $dir ) : $dir, $command);
push @possibles, $abs if $abs = $self->maybe_command($abs);
}
}
return @possibles if wantarray;
return shift @possibles;
}
=head3 can_redirect_error
$useredirect = MM->can_redirect_error;
True if on an OS where qx operator (or backticks) can redirect C<STDERR>
onto C<STDOUT>.
=cut
sub can_redirect_error {
my $self = shift;
$self->os_flavor_is('Unix')
or ($self->os_flavor_is('Win32') and !$self->os_flavor_is('Win9x'))
or $self->os_flavor_is('OS/2')
}
=head3 is_make_type
my $is_dmake = $self->is_make_type('dmake');
Returns true if C<<$self->make>> is the given type; possibilities are:
gmake GNU make
dmake
nmake
bsdmake BSD pmake-derived
=cut
my %maketype2true;
# undocumented - so t/cd.t can still do its thing
sub _clear_maketype_cache { %maketype2true = () }
sub is_make_type {
my($self, $type) = @_;
return $maketype2true{$type} if defined $maketype2true{$type};
(undef, undef, my $make_basename) = $self->splitpath($self->make);
return $maketype2true{$type} = 1
if $make_basename =~ /\b$type\b/i; # executable's filename
return $maketype2true{$type} = 0
if $make_basename =~ /\b[gdn]make\b/i; # Never fall through for dmake/nmake/gmake
# now have to run with "-v" and guess
my $redirect = $self->can_redirect_error ? '2>&1' : '';
my $make = $self->make || $self->{MAKE};
my $minus_v = `"$make" -v $redirect`;
return $maketype2true{$type} = 1
if $type eq 'gmake' and $minus_v =~ /GNU make/i;
return $maketype2true{$type} = 1
if $type eq 'bsdmake'
and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im;
$maketype2true{$type} = 0; # it wasn't whatever you asked
}
=head3 can_dep_space
my $can_dep_space = $self->can_dep_space;
Returns true if C<make> can handle (probably by quoting)
dependencies that contain a space. Currently known true for GNU make,
false for BSD pmake derivative.
=cut
my $cached_dep_space;
sub can_dep_space {
my $self = shift;
return $cached_dep_space if defined $cached_dep_space;
return $cached_dep_space = 1 if $self->is_make_type('gmake');
return $cached_dep_space = 0 if $self->is_make_type('dmake'); # only on W32
return $cached_dep_space = 0 if $self->is_make_type('bsdmake');
return $cached_dep_space = 0; # assume no
}
=head3 quote_dep
$text = $mm->quote_dep($text);
Method that protects Makefile single-value constants (mainly filenames),
so that make will still treat them as single values even if they
inconveniently have spaces in. If the make program being used cannot
achieve such protection and the given text would need it, throws an
exception.
=cut
sub quote_dep {
my ($self, $arg) = @_;
die <<EOF if $arg =~ / / and not $self->can_dep_space;
Tried to use make dependency with space for make that can't:
'$arg'
EOF
$arg =~ s/( )/\\$1/g; # how GNU make does it
return $arg;
}
=head3 split_command
my @cmds = $MM->split_command($cmd, @args);
Most OS have a maximum command length they can execute at once. Large
modules can easily generate commands well past that limit. Its
necessary to split long commands up into a series of shorter commands.
C<split_command> will return a series of @cmds each processing part of
the args. Collectively they will process all the arguments. Each
individual line in @cmds will not be longer than the
$self->max_exec_len being careful to take into account macro expansion.
$cmd should include any switches and repeated initial arguments.
If no @args are given, no @cmds will be returned.
Pairs of arguments will always be preserved in a single command, this
is a heuristic for things like pm_to_blib and pod2man which work on
pairs of arguments. This makes things like this safe:
$self->split_command($cmd, %pod2man);
=cut
sub split_command {
my($self, $cmd, @args) = @_;
my @cmds = ();
return(@cmds) unless @args;
# If the command was given as a here-doc, there's probably a trailing
# newline.
chomp $cmd;
# set aside 30% for macro expansion.
my $len_left = int($self->max_exec_len * 0.70);
$len_left -= length $self->_expand_macros($cmd);
do {
my $arg_str = '';
my @next_args;
while( @next_args = splice(@args, 0, 2) ) {
# Two at a time to preserve pairs.
my $next_arg_str = "\t ". join ' ', @next_args, "\n";
if( !length $arg_str ) {
$arg_str .= $next_arg_str
}
elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
unshift @args, @next_args;
last;
}
else {
$arg_str .= $next_arg_str;
}
}
chop $arg_str;
push @cmds, $self->escape_newlines("$cmd \n$arg_str");
} while @args;
return @cmds;
}
sub _expand_macros {
my($self, $cmd) = @_;
$cmd =~ s{\$\((\w+)\)}{
defined $self->{$1} ? $self->{$1} : "\$($1)"
}e;
return $cmd;
}
=head3 make_type
Returns a suitable string describing the type of makefile being written.
=cut
# override if this isn't suitable!
sub make_type { return 'Unix-style'; }
=head3 stashmeta
my @recipelines = $MM->stashmeta($text, $file);
Generates a set of C<@recipelines> which will result in the literal
C<$text> ending up in literal C<$file> when the recipe is executed. Call
it once, with all the text you want in C<$file>. Make macros will not
be expanded, so the locations will be fixed at configure-time, not
at build-time.
=cut
sub stashmeta {
my($self, $text, $file) = @_;
$self->echo($text, $file, { allow_variables => 0, append => 0 });
}
=head3 echo
my @commands = $MM->echo($text);
my @commands = $MM->echo($text, $file);
my @commands = $MM->echo($text, $file, \%opts);
Generates a set of @commands which print the $text to a $file.
If $file is not given, output goes to STDOUT.
If $opts{append} is true the $file will be appended to rather than
overwritten. Default is to overwrite.
If $opts{allow_variables} is true, make variables of the form
C<$(...)> will not be escaped. Other C<$> will. Default is to escape
all C<$>.
Example of use:
my $make = join '', map "\t$_\n", $MM->echo($text, $file);
=cut
sub echo {
my($self, $text, $file, $opts) = @_;
# Compatibility with old options
if( !ref $opts ) {
my $append = $opts;
$opts = { append => $append || 0 };
}
$opts->{allow_variables} = 0 unless defined $opts->{allow_variables};
my $ql_opts = { allow_variables => $opts->{allow_variables} };
my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_, $ql_opts) }
split /\n/, $text;
if( $file ) {
my $redirect = $opts->{append} ? '>>' : '>';
$cmds[0] .= " $redirect $file";
$_ .= " >> $file" foreach @cmds[1..$#cmds];
}
return @cmds;
}
=head3 wraplist
my $args = $mm->wraplist(@list);
Takes an array of items and turns them into a well-formatted list of
arguments. In most cases this is simply something like:
FOO \
BAR \
BAZ
=cut
sub wraplist {
my $self = shift;
return join " \\\n\t", @_;
}
=head3 maketext_filter
my $filter_make_text = $mm->maketext_filter($make_text);
The text of the Makefile is run through this method before writing to
disk. It allows systems a chance to make portability fixes to the
Makefile.
By default it does nothing.
This method is protected and not intended to be called outside of
MakeMaker.
=cut
sub maketext_filter { return $_[1] }
=head3 cd I<Abstract>
my $subdir_cmd = $MM->cd($subdir, @cmds);
This will generate a make fragment which runs the @cmds in the given
$dir. The rough equivalent to this, except cross platform.
cd $subdir && $cmd
Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
not. "../foo" is right out.
The resulting $subdir_cmd has no leading tab nor trailing newline. This
makes it easier to embed in a make string. For example.
my $make = sprintf <<'CODE', $subdir_cmd;
foo :
$(ECHO) what
%s
$(ECHO) mouche
CODE
=head3 oneliner I<Abstract>
my $oneliner = $MM->oneliner($perl_code);
my $oneliner = $MM->oneliner($perl_code, \@switches);
This will generate a perl one-liner safe for the particular platform
you're on based on the given $perl_code and @switches (a -e is
assumed) suitable for using in a make target. It will use the proper
shell quoting and escapes.
$(PERLRUN) will be used as perl.
Any newlines in $perl_code will be escaped. Leading and trailing
newlines will be stripped. Makes this idiom much easier:
my $code = $MM->oneliner(<<'CODE', [...switches...]);
some code here
another line here
CODE
Usage might be something like:
# an echo emulation
$oneliner = $MM->oneliner('print "Foo\n"');
$make = '$oneliner > somefile';
Dollar signs in the $perl_code will be protected from make using the
C<quote_literal> method, unless they are recognised as being a make
variable, C<$(varname)>, in which case they will be left for make
to expand. Remember to quote make macros else it might be used as a
bareword. For example:
# Assign the value of the $(VERSION_FROM) make macro to $vf.
$oneliner = $MM->oneliner('$vf = "$(VERSION_FROM)"');
Its currently very simple and may be expanded sometime in the figure
to include more flexible code and switches.
=head3 quote_literal I<Abstract>
my $safe_text = $MM->quote_literal($text);
my $safe_text = $MM->quote_literal($text, \%options);
This will quote $text so it is interpreted literally in the shell.
For example, on Unix this would escape any single-quotes in $text and
put single-quotes around the whole thing.
If $options{allow_variables} is true it will leave C<'$(FOO)'> make
variables untouched. If false they will be escaped like any other
C<$>. Defaults to true.
=head3 escape_dollarsigns
my $escaped_text = $MM->escape_dollarsigns($text);
Escapes stray C<$> so they are not interpreted as make variables.
It lets by C<$(...)>.
=cut
sub escape_dollarsigns {
my($self, $text) = @_;
# Escape dollar signs which are not starting a variable
$text =~ s{\$ (?!\() }{\$\$}gx;
return $text;
}
=head3 escape_all_dollarsigns
my $escaped_text = $MM->escape_all_dollarsigns($text);
Escapes all C<$> so they are not interpreted as make variables.
=cut
sub escape_all_dollarsigns {
my($self, $text) = @_;
# Escape dollar signs
$text =~ s{\$}{\$\$}gx;
return $text;
}
=head3 escape_newlines I<Abstract>
my $escaped_text = $MM->escape_newlines($text);
Shell escapes newlines in $text.
=head3 max_exec_len I<Abstract>
my $max_exec_len = $MM->max_exec_len;
Calculates the maximum command size the OS can exec. Effectively,
this is the max size of a shell command line.
=for _private
$self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
=head3 make
my $make = $MM->make;
Returns the make variant we're generating the Makefile for. This attempts
to do some normalization on the information from %Config or the user.
=cut
sub make {
my $self = shift;
my $make = lc $self->{MAKE};
# Truncate anything like foomake6 to just foomake.
$make =~ s/^(\w+make).*/$1/;
# Turn gnumake into gmake.
$make =~ s/^gnu/g/;
return $make;
}
=head2 Targets
These are methods which produce make targets.
=head3 all_target
Generate the default target 'all'.
=cut
sub all_target {
my $self = shift;
return <<'MAKE_EXT';
all :: pure_all
$(NOECHO) $(NOOP)
MAKE_EXT
}
=head3 blibdirs_target
my $make_frag = $mm->blibdirs_target;
Creates the blibdirs target which creates all the directories we use
in blib/.
The blibdirs.ts target is deprecated. Depend on blibdirs instead.
=cut
sub _xs_list_basenames {
my ($self) = @_;
map { (my $b = $_) =~ s/\.xs$//; $b } sort keys %{ $self->{XS} };
}
sub blibdirs_target {
my $self = shift;
my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
autodir archautodir
bin script
man1dir man3dir
);
if ($self->{XSMULTI}) {
for my $ext ($self->_xs_list_basenames) {
my ($v, $d, $f) = File::Spec->splitpath($ext);
my @d = File::Spec->splitdir($d);
shift @d if $d[0] eq 'lib';
push @dirs, $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
}
}
my @exists = map { $_.'$(DFSEP).exists' } @dirs;
my $make = sprintf <<'MAKE', join(' ', @exists);
blibdirs : %s
$(NOECHO) $(NOOP)
# Backwards compat with 6.18 through 6.25
blibdirs.ts : blibdirs
$(NOECHO) $(NOOP)
MAKE
$make .= $self->dir_target(@dirs);
return $make;
}
=head3 clean (o)
Defines the clean target.
=cut
sub clean {
# --- Cleanup and Distribution Sections ---
my($self, %attribs) = @_;
my @m;
push(@m, '
# Delete temporary files but do not touch installed files. We don\'t delete
# the Makefile here so a later make realclean still has a makefile to use.
clean :: clean_subdirs
');
my @files = sort values %{$self->{XS}}; # .c files from *.xs files
push @files, map {
my $file = $_;
map { $file.$_ } $self->{OBJ_EXT}, qw(.def _def.old .bs .bso .exp .base);
} $self->_xs_list_basenames;
my @dirs = qw(blib);
# Normally these are all under blib but they might have been
# redefined.
# XXX normally this would be a good idea, but the Perl core sets
# INST_LIB = ../../lib rather than actually installing the files.
# So a "make clean" in an ext/ directory would blow away lib.
# Until the core is adjusted let's leave this out.
# push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
# $(INST_BIN) $(INST_SCRIPT)
# $(INST_MAN1DIR) $(INST_MAN3DIR)
# $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
# $(INST_STATIC) $(INST_DYNAMIC)
# );
if( $attribs{FILES} ) {
# Use @dirs because we don't know what's in here.
push @dirs, ref $attribs{FILES} ?
@{$attribs{FILES}} :
split /\s+/, $attribs{FILES} ;
}
push(@files, qw[$(MAKE_APERL_FILE)
MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations
blibdirs.ts pm_to_blib pm_to_blib.ts
*$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
$(BOOTSTRAP) $(BASEEXT).bso
$(BASEEXT).def lib$(BASEEXT).def
$(BASEEXT).exp $(BASEEXT).x
]);
push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
# core files
if ($^O eq 'vos') {
push(@files, qw[perl*.kp]);
}
else {
push(@files, qw[core core.*perl.*.? *perl.core]);
}
push(@files, map { "core." . "[0-9]"x$_ } (1..5));
# OS specific things to clean up. Use @dirs since we don't know
# what might be in here.
push @dirs, $self->extra_clean_files;
# Occasionally files are repeated several times from different sources
{ my(%f) = map { ($_ => 1) } @files; @files = sort keys %f; }
{ my(%d) = map { ($_ => 1) } @dirs; @dirs = sort keys %d; }
push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
# Leave Makefile.old around for realclean
push @m, <<'MAKE';
$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
- $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
MAKE
push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
join("", @m);
}
=head3 clean_subdirs_target
my $make_frag = $MM->clean_subdirs_target;
Returns the clean_subdirs target. This is used by the clean target to
call clean on any subdirectories which contain Makefiles.
=cut
sub clean_subdirs_target {
my($self) = shift;
# No subdirectories, no cleaning.
return <<'NOOP_FRAG' unless @{$self->{DIR}};
clean_subdirs :
$(NOECHO) $(NOOP)
NOOP_FRAG
my $clean = "clean_subdirs :\n";
for my $dir (@{$self->{DIR}}) {
my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
exit 0 unless chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
CODE
$clean .= "\t$subclean\n";
}
return $clean;
}
=head3 dir_target
my $make_frag = $mm->dir_target(@directories);
Generates targets to create the specified directories and set its
permission to PERM_DIR.
Because depending on a directory to just ensure it exists doesn't work
too well (the modified time changes too often) dir_target() creates a
.exists file in the created directory. It is this you should depend on.
For portability purposes you should use the $(DIRFILESEP) macro rather
than a '/' to separate the directory from the file.
yourdirectory$(DIRFILESEP).exists
=cut
sub dir_target {
my($self, @dirs) = @_;
my $make = '';
foreach my $dir (@dirs) {
$make .= sprintf <<'MAKE', ($dir) x 4;
%s$(DFSEP).exists :: Makefile.PL
$(NOECHO) $(MKPATH) %s
$(NOECHO) $(CHMOD) $(PERM_DIR) %s
$(NOECHO) $(TOUCH) %s$(DFSEP).exists
MAKE
}
return $make;
}
=head3 distdir
Defines the scratch directory target that will hold the distribution
before tar-ing (or shar-ing).
=cut
# For backwards compatibility.
*dist_dir = *distdir;
sub distdir {
my($self) = shift;
my $meta_target = $self->{NO_META} ? '' : 'distmeta';
my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
create_distdir :
$(RM_RF) $(DISTVNAME)
$(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
-e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
distdir : create_distdir %s %s
$(NOECHO) $(NOOP)
MAKE_FRAG
}
=head3 dist_test
Defines a target that produces the distribution in the
scratch directory, and runs 'perl Makefile.PL; make ;make test' in that
subdirectory.
=cut
sub dist_test {
my($self) = shift;
my $mpl_args = join " ", map qq["$_"], @ARGV;
my $test = $self->cd('$(DISTVNAME)',
'$(ABSPERLRUN) Makefile.PL '.$mpl_args,
'$(MAKE) $(PASTHRU)',
'$(MAKE) test $(PASTHRU)'
);
return sprintf <<'MAKE_FRAG', $test;
disttest : distdir
%s
MAKE_FRAG
}
=head3 xs_dlsyms_arg
Returns command-line arg(s) to linker for file listing dlsyms to export.
Defaults to returning empty string, can be overridden by e.g. AIX.
=cut
sub xs_dlsyms_arg {
return '';
}
=head3 xs_dlsyms_ext
Returns file-extension for C<xs_make_dlsyms> method's output file,
including any "." character.
=cut
sub xs_dlsyms_ext {
die "Pure virtual method";
}
=head3 xs_dlsyms_extra
Returns any extra text to be prepended to the C<$extra> argument of
C<xs_make_dlsyms>.
=cut
sub xs_dlsyms_extra {
'';
}
=head3 xs_dlsyms_iterator
Iterates over necessary shared objects, calling C<xs_make_dlsyms> method
for each with appropriate arguments.
=cut
sub xs_dlsyms_iterator {
my ($self, $attribs) = @_;
if ($self->{XSMULTI}) {
my @m;
for my $ext ($self->_xs_list_basenames) {
my @parts = File::Spec->splitdir($ext);
shift @parts if $parts[0] eq 'lib';
my $name = join '::', @parts;
push @m, $self->xs_make_dlsyms(
$attribs,
$ext . $self->xs_dlsyms_ext,
"$ext.xs",
$name,
$parts[-1],
{}, [], {}, [],
$self->xs_dlsyms_extra . q!, 'FILE' => ! . neatvalue($ext),
);
}
return join "\n", @m;
} else {
return $self->xs_make_dlsyms(
$attribs,
$self->{BASEEXT} . $self->xs_dlsyms_ext,
'Makefile.PL',
$self->{NAME},
$self->{DLBASE},
$attribs->{DL_FUNCS} || $self->{DL_FUNCS} || {},
$attribs->{FUNCLIST} || $self->{FUNCLIST} || [],
$attribs->{IMPORTS} || $self->{IMPORTS} || {},
$attribs->{DL_VARS} || $self->{DL_VARS} || [],
$self->xs_dlsyms_extra,
);
}
}
=head3 xs_make_dlsyms
$self->xs_make_dlsyms(
\%attribs, # hashref from %attribs in caller
"$self->{BASEEXT}.def", # output file for Makefile target
'Makefile.PL', # dependency
$self->{NAME}, # shared object's "name"
$self->{DLBASE}, # last ::-separated part of name
$attribs{DL_FUNCS} || $self->{DL_FUNCS} || {}, # various params
$attribs{FUNCLIST} || $self->{FUNCLIST} || [],
$attribs{IMPORTS} || $self->{IMPORTS} || {},
$attribs{DL_VARS} || $self->{DL_VARS} || [],
# optional extra param that will be added as param to Mksymlists