Skip to content

Commit c06ae49

Browse files
committed
Test, fix override of subdir top_targets to "all : static"
1 parent 3d7a8af commit c06ae49

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

lib/ExtUtils/MM_Unix.pm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,14 @@ sub xs_make_dynamic_lib {
992992
my ($self, $attribs, $from, $to, $todir, $ldfrom, $exportlist) = @_;
993993
$exportlist = '' if $exportlist ne '$(EXPORT_LIST)';
994994
my $armaybe = $self->_xs_armaybe($attribs);
995-
my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)'."\n", $to, $from, $todir, $exportlist;
995+
# if there are subdirs and MYEXTLIB looks relative ie in a subdir and
996+
# looks like a static library, heuristic to ensure MYEXTLIB gets built
997+
my $subdirs_static = '';
998+
$subdirs_static = 'subdirs_static'
999+
if $self->{MYEXTLIB} &&
1000+
(File::Spec->rel2abs($self->{MYEXTLIB}) ne $self->{MYEXTLIB}) &&
1001+
$self->{MYEXTLIB} =~ /\Q$self->{LIB_EXT}\E|\$\(LIB_EXT\)\z/;
1002+
my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) %s'."\n", $to, $from, $todir, $exportlist, $subdirs_static;
9961003
if ($armaybe ne ':'){
9971004
$ldfrom = 'tmp$(LIB_EXT)';
9981005
push(@m,' $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
@@ -3579,11 +3586,12 @@ sub subdirs {
35793586
#### print "Including $dir subdirectory\n";
35803587
}
35813588
if (@m){
3582-
unshift(@m, "
3589+
unshift @m, <<'EOF';
3590+
35833591
# The default clean, realclean and test targets in this Makefile
35843592
# have automatically been given entries for each subdir.
35853593
3586-
");
3594+
EOF
35873595
} else {
35883596
push(@m, "\n# none")
35893597
}

t/lib/MakeMaker/Test/Setup/XS.pm

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,61 @@ $label2files{staticmulti} = +{
194194
),
195195
};
196196

197+
# mimic scheme in Archive::Unzip::Burst:
198+
# MYEXTLIB is res/lib*.a
199+
# top-level postamble deps res/unzip/Makefile off MYEXTLIB and builds res/unzip/*.o
200+
# res/M.PL overrides top_targets with:
201+
# "all : static"
202+
# "static : lib*.a"
203+
# "lib*.a : unzip/*.o -> ar makes lib*.a"
204+
# this scheme depends on top level subdirs (specifically res's "static")
205+
# being built before it tries its MYEXTLIB target
206+
$label2files{subdirsoverride} = +{
207+
%{ $label2files{'basic'} }, # make copy
208+
209+
'Makefile.PL' => sprintf(
210+
$MAKEFILEPL, 'Test', 'Test.pm', qq{'$typemap'},
211+
q{DEFINE => '-DINVAR=input', MYEXTLIB => 'Other/libover$(LIB_EXT)'},
212+
) . <<'EOF',
213+
package MY;
214+
sub postamble {
215+
my ($self) = @_;
216+
sprintf <<'MAKEFRAG', $self->cd($self->catdir(qw(Other sub)), '$(MAKE)');
217+
$(MYEXTLIB) :
218+
%s
219+
MAKEFRAG
220+
}
221+
EOF
222+
223+
'Other/Makefile.PL' => sprintf($MAKEFILEPL, 'Other', '../Test.pm', qq{}, '') . <<'EOF',
224+
package MY;
225+
sub top_targets {
226+
<<'MAKEFRAG';
227+
all :: static
228+
static :: libover$(LIB_EXT)
229+
libover$(LIB_EXT) : sub/notmuch$(OBJ_EXT)
230+
$(AR) cr "$@" "$<"
231+
$(RANLIB) "$@"
232+
MAKEFRAG
233+
}
234+
EOF
235+
236+
'Other/sub/Makefile.PL' => sprintf(
237+
$MAKEFILEPL, 'Third', '../../Test.pm', qq{}, 'OBJECT => q{$(O_FILES)}'
238+
) . <<'EOF',
239+
package MY;
240+
sub top_targets {
241+
<<'MAKEFRAG';
242+
all :: $(O_FILES)
243+
MAKEFRAG
244+
}
245+
EOF
246+
247+
'Other/sub/notmuch.c' => '',
248+
249+
};
250+
virtual_rename('subdirsoverride', 'lib/XS/Test.pm', 'Test.pm');
251+
197252
sub virtual_rename {
198253
my ($label, $oldfile, $newfile) = @_;
199254
$label2files{$label}->{$newfile} = delete $label2files{$label}->{$oldfile};
@@ -234,6 +289,7 @@ sub list_dynamic {
234289
[ 'multi', '', '' ],
235290
[ 'staticmulti', ' LINKTYPE=dynamic', ' LINKTYPE=dynamic' ],
236291
[ 'staticmulti', ' dynamic', '_dynamic' ],
292+
[ 'subdirsoverride', '', '' ],
237293
);
238294
}
239295

0 commit comments

Comments
 (0)