2010-08-14 02:50:14 +00:00
|
|
|
# -*-mode: perl-*-
|
|
|
|
|
|
|
|
$description = "Test GNU make's archive management features.";
|
|
|
|
|
|
|
|
$details = "\
|
|
|
|
This only works on systems that support it.";
|
|
|
|
|
|
|
|
# If this instance of make doesn't support archives, skip it
|
|
|
|
exists $FEATURES{archives} or return -1;
|
|
|
|
|
2017-04-17 19:37:57 +00:00
|
|
|
# In theory archive support exists on Windows but it doesn't use ar;
|
|
|
|
# someone will need to port this test.
|
|
|
|
$port_type eq 'W32' and return -1;
|
|
|
|
|
2010-08-14 02:50:14 +00:00
|
|
|
# Create some .o files to work with
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($osname eq 'VMS') {
|
|
|
|
# VMS AR needs real object files at this time.
|
|
|
|
foreach $afile ('a1', 'a2', 'a3') {
|
|
|
|
# Use non-standard extension to prevent implicit rules from recreating
|
|
|
|
# objects when the test tampers with the timestamp.
|
|
|
|
1 while unlink "$afile.c1";
|
|
|
|
1 while unlink "$afile.o";
|
|
|
|
open (MYFILE, ">$afile.c1");
|
|
|
|
print MYFILE "int $afile(void) {return 1;}\n";
|
|
|
|
close MYFILE;
|
|
|
|
system("cc $afile.c1 /object=$afile.o");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
utouch(-60, qw(a1.o a2.o a3.o));
|
|
|
|
}
|
2010-08-14 02:50:14 +00:00
|
|
|
|
2019-10-05 18:26:52 +00:00
|
|
|
# Fallback if configure did not find AR
|
|
|
|
my $ar = get_config('AR') || 'ar';
|
2014-09-12 03:39:34 +00:00
|
|
|
|
2016-02-29 01:11:45 +00:00
|
|
|
my $redir = '2>&1';
|
|
|
|
$redir = '' if $osname eq 'VMS';
|
|
|
|
|
|
|
|
my $arflags = 'rv';
|
|
|
|
my $arvar = "AR=$ar";
|
|
|
|
|
|
|
|
# Newer versions of binutils can be built with --enable-deterministic-archives
|
|
|
|
# which forces all timestamps (among other things) to always be 0, defeating
|
|
|
|
# GNU make's archive support. See if ar supports the U option to disable it.
|
|
|
|
unlink('libxx.a');
|
|
|
|
$_ = `$ar U$arflags libxx.a a1.o $redir`;
|
|
|
|
if ($? == 0) {
|
|
|
|
$arflags = 'Urv';
|
|
|
|
$arvar = "$arvar ARFLAGS=$arflags";
|
|
|
|
}
|
2014-09-12 03:39:34 +00:00
|
|
|
|
2013-09-21 22:47:26 +00:00
|
|
|
# Some versions of ar print different things on creation. Find out.
|
2016-02-29 01:11:45 +00:00
|
|
|
unlink('libxx.a');
|
|
|
|
my $created = `$ar $arflags libxx.a a1.o $redir`;
|
2019-09-03 04:26:05 +00:00
|
|
|
$created =~ s/a1\.o/#OBJECT#/g;
|
2013-09-22 15:28:46 +00:00
|
|
|
|
|
|
|
# Some versions of ar print different things on add. Find out.
|
2016-02-29 01:11:45 +00:00
|
|
|
my $add = `$ar $arflags libxx.a a2.o $redir`;
|
2013-09-22 15:28:46 +00:00
|
|
|
$add =~ s/a2\.o/#OBJECT#/g;
|
|
|
|
|
|
|
|
# Some versions of ar print different things on replacement. Find out.
|
2016-02-29 01:11:45 +00:00
|
|
|
my $repl = `$ar $arflags libxx.a a2.o $redir`;
|
2013-09-22 15:28:46 +00:00
|
|
|
$repl =~ s/a2\.o/#OBJECT#/g;
|
|
|
|
|
2013-09-21 22:47:26 +00:00
|
|
|
unlink('libxx.a');
|
|
|
|
|
2010-08-14 02:50:14 +00:00
|
|
|
# Very simple
|
2019-09-03 04:26:05 +00:00
|
|
|
($_ = $created) =~ s/#OBJECT#/a1.o/g;
|
|
|
|
my $answer = "$ar $arflags libxx.a a1.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a1.o';
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test('all: libxx.a(a1.o)', $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
|
|
|
# Multiple .o's. Add a new one to the existing library
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ = $add) =~ s/#OBJECT#/a2.o/g;
|
2014-09-12 03:39:34 +00:00
|
|
|
|
2016-02-29 01:11:45 +00:00
|
|
|
$answer = "$ar $arflags libxx.a a2.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a2.o';
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test('all: libxx.a(a1.o a2.o)', $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
|
|
|
# Touch one of the .o's so it's rebuilt
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
# utouch is not changing what VMS library compare is testing for.
|
|
|
|
# So do a real change by regenerating the file.
|
|
|
|
1 while unlink('a1.o');
|
|
|
|
# Later time stamp than last insertion.
|
|
|
|
sleep(2);
|
|
|
|
system('cc a1.c1 /object=a1.o');
|
|
|
|
# Next insertion will have a later timestamp.
|
|
|
|
sleep(2);
|
|
|
|
} else {
|
|
|
|
utouch(-40, 'a1.o');
|
|
|
|
}
|
|
|
|
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ = $repl) =~ s/#OBJECT#/a1.o/g;
|
2016-02-29 01:11:45 +00:00
|
|
|
$answer = "$ar $arflags libxx.a a1.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a1.o';
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test(undef, $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
|
|
|
# Use wildcards
|
2014-09-12 03:39:34 +00:00
|
|
|
$answer = "#MAKE#: Nothing to be done for 'all'.\n";
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test('all: libxx.a(*.o)', $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
|
|
|
# Touch one of the .o's so it's rebuilt
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
# utouch is not changing what VMS library compare is testing for.
|
|
|
|
# So do a real change by regenerating the file.
|
|
|
|
1 while unlink('a1.o');
|
|
|
|
# Make timestamp later than last insertion.
|
|
|
|
sleep(2);
|
|
|
|
system('cc a1.c1 /object=a1.o');
|
|
|
|
} else {
|
|
|
|
utouch(-30, 'a1.o');
|
|
|
|
}
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ = $repl) =~ s/#OBJECT#/a1.o/g;
|
2016-02-29 01:11:45 +00:00
|
|
|
$answer = "$ar $arflags libxx.a a1.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a1.o';
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test(undef, $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
|
|
|
# Use both wildcards and simple names
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
# utouch is not changing what VMS library compare is testing for.
|
|
|
|
# So do a real change by regenerating the file.
|
|
|
|
1 while unlink('a2.o');
|
|
|
|
sleep(2);
|
|
|
|
system('cc a2.c1 /object=a2.o');
|
|
|
|
} else {
|
|
|
|
utouch(-50, 'a2.o');
|
|
|
|
}
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ = $add) =~ s/#OBJECT#/a3.o/g;
|
2016-02-29 01:11:45 +00:00
|
|
|
$_ .= "$ar $arflags libxx.a a2.o\n";
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ .= $repl) =~ s/#OBJECT#/a2.o/g;
|
2016-02-29 01:11:45 +00:00
|
|
|
$answer = "$ar $arflags libxx.a a3.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a3.o';
|
|
|
|
}
|
|
|
|
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test('all: libxx.a(a3.o *.o)', $arvar, $answer);
|
2010-08-14 02:50:14 +00:00
|
|
|
|
2011-06-12 16:22:04 +00:00
|
|
|
# Check whitespace handling
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
# utouch is not changing what VMS library compare is testing for.
|
|
|
|
# So do a real change by regenerating the file.
|
|
|
|
1 while unlink('a2.o');
|
|
|
|
sleep(2);
|
|
|
|
system('cc a2.c1 /object=a2.o');
|
|
|
|
} else {
|
|
|
|
utouch(-40, 'a2.o');
|
|
|
|
}
|
2013-09-22 15:28:46 +00:00
|
|
|
($_ = $repl) =~ s/#OBJECT#/a2.o/g;
|
2016-02-29 01:11:45 +00:00
|
|
|
$answer = "$ar $arflags libxx.a a2.o\n$_";
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$answer = 'library /replace libxx.a a2.o';
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test('all: libxx.a( a3.o *.o )', $arvar, $answer);
|
2011-06-12 16:22:04 +00:00
|
|
|
|
2014-09-12 03:39:34 +00:00
|
|
|
rmfiles(qw(a1.c1 a2.c1 a3.c1 a1.o a2.o a3.o libxx.a));
|
2010-08-14 02:50:14 +00:00
|
|
|
|
2013-01-13 17:40:13 +00:00
|
|
|
# Check non-archive targets
|
|
|
|
# See Savannah bug #37878
|
2014-09-12 03:39:34 +00:00
|
|
|
$mk_string = q!
|
2013-01-13 17:40:13 +00:00
|
|
|
all: foo(bar).baz
|
|
|
|
foo(bar).baz: ; @echo '$@'
|
2014-09-12 03:39:34 +00:00
|
|
|
!;
|
|
|
|
|
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$mk_string =~ s/echo/write sys\$\$output/;
|
|
|
|
$mk_string =~ s/\'/\"/g;
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test($mk_string, $arvar, "foo(bar).baz\n");
|
2013-01-13 17:40:13 +00:00
|
|
|
|
2013-05-26 20:53:17 +00:00
|
|
|
# Check renaming of archive targets.
|
|
|
|
# See Savannah bug #38442
|
|
|
|
|
|
|
|
mkdir('artest', 0777);
|
|
|
|
touch('foo.vhd');
|
2014-09-12 03:39:34 +00:00
|
|
|
$mk_string = q!
|
2013-05-26 20:53:17 +00:00
|
|
|
DIR = artest
|
|
|
|
vpath % $(DIR)
|
|
|
|
default: lib(foo)
|
|
|
|
(%): %.vhd ; @cd $(DIR) && touch $(*F) && $(AR) $(ARFLAGS) $@ $(*F) >/dev/null 2>&1 && rm $(*F)
|
|
|
|
.PHONY: default
|
2014-09-12 03:39:34 +00:00
|
|
|
!;
|
|
|
|
if ($port_type eq 'VMS-DCL') {
|
|
|
|
$mk_string =~ s#= artest#= sys\$\$disk:\[.artest\]#;
|
|
|
|
$mk_string =~ s#lib\(foo\)#lib.tlb\(foo\)#;
|
|
|
|
$mk_string =~ s#; \@cd#; pipe SET DEFAULT#;
|
|
|
|
$mk_string =~
|
|
|
|
s#touch \$\(\*F\)#touch \$\(\*F\) && library/create/text sys\$\$disk:\$\@#;
|
|
|
|
$mk_string =~
|
|
|
|
s#library#if f\$\$search(\"\$\@\") \.eqs\. \"\" then library#;
|
|
|
|
# VMS needs special handling for null extension
|
|
|
|
$mk_string =~ s#\@ \$\(\*F\)#\@ \$\(\*F\)\.#;
|
|
|
|
$mk_string =~ s#>/dev/null 2>&1 ##;
|
|
|
|
}
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test($mk_string, $arvar, "");
|
2013-05-26 20:53:17 +00:00
|
|
|
|
2016-02-29 01:11:45 +00:00
|
|
|
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n");
|
2013-05-26 20:53:17 +00:00
|
|
|
|
|
|
|
unlink('foo.vhd');
|
2014-09-12 03:39:34 +00:00
|
|
|
if ($osname eq 'VMS') {
|
2019-09-15 19:30:34 +00:00
|
|
|
remove_directory_tree("$cwdpath/artest");
|
2014-09-12 03:39:34 +00:00
|
|
|
} else {
|
|
|
|
remove_directory_tree('artest');
|
|
|
|
}
|
2013-05-26 20:53:17 +00:00
|
|
|
|
2018-08-04 19:47:15 +00:00
|
|
|
# Check long names for archive members.
|
|
|
|
# See Savannah bug #54395
|
|
|
|
|
|
|
|
if ($osname ne 'VMS') {
|
|
|
|
my $pre = '1234567890123456';
|
2019-08-25 17:47:13 +00:00
|
|
|
my $lib = 'libxx.a';
|
|
|
|
my $cr = $created;
|
2019-09-03 04:26:05 +00:00
|
|
|
$cr =~ s/#OBJECT#/${pre}a/g;
|
|
|
|
my $ad = $add;
|
|
|
|
$ad =~ s/#OBJECT#/${pre}b/g;
|
2018-08-04 19:47:15 +00:00
|
|
|
|
|
|
|
run_make_test(qq!
|
|
|
|
# Both member names > 16 characters long
|
|
|
|
default: $lib(${pre}a) $lib(${pre}b)
|
|
|
|
|
|
|
|
(%): % ; \$(AR) \$(ARFLAGS) \$@ \$%
|
|
|
|
|
|
|
|
$pre%: ; touch \$\@
|
|
|
|
!,
|
2019-09-03 04:26:05 +00:00
|
|
|
$arvar, "touch ${pre}a\n$ar $arflags $lib ${pre}a\n${cr}touch ${pre}b\n$ar $arflags $lib ${pre}b\n${ad}rm ${pre}a ${pre}b\n");
|
2018-08-04 19:47:15 +00:00
|
|
|
|
|
|
|
# Run it again; nothing should happen
|
|
|
|
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n");
|
|
|
|
|
|
|
|
unlink($lib);
|
|
|
|
}
|
|
|
|
|
2010-08-14 02:50:14 +00:00
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|