| 1 |
# -*-mode: perl-*- |
| 2 |
|
| 3 |
$description = "Test GNU make's archive management features."; |
| 4 |
|
| 5 |
# Rocky: skip for now |
| 6 |
$details = "\ |
| 7 |
FIXME: reinstate. Determinism in Linux kernels changes this."; |
| 8 |
return -1; |
| 9 |
|
| 10 |
$details = "\ |
| 11 |
This only works on systems that support it."; |
| 12 |
|
| 13 |
# If this instance of make doesn't support archives, skip it |
| 14 |
exists $FEATURES{archives} or return -1; |
| 15 |
|
| 16 |
# In theory archive support exists on Windows but it doesn't use ar; |
| 17 |
# someone will need to port this test. |
| 18 |
$port_type eq 'W32' and return -1; |
| 19 |
|
| 20 |
# Create some .o files to work with |
| 21 |
if ($osname eq 'VMS') { |
| 22 |
# VMS AR needs real object files at this time. |
| 23 |
foreach $afile ('a1', 'a2', 'a3') { |
| 24 |
# Use non-standard extension to prevent implicit rules from recreating |
| 25 |
# objects when the test tampers with the timestamp. |
| 26 |
1 while unlink "$afile.c1"; |
| 27 |
1 while unlink "$afile.o"; |
| 28 |
open (MYFILE, ">$afile.c1"); |
| 29 |
print MYFILE "int $afile(void) {return 1;}\n"; |
| 30 |
close MYFILE; |
| 31 |
system("cc $afile.c1 /object=$afile.o"); |
| 32 |
} |
| 33 |
} else { |
| 34 |
utouch(-60, qw(a1.o a2.o a3.o)); |
| 35 |
} |
| 36 |
|
| 37 |
# Fallback if configure did not find AR |
| 38 |
my $ar = get_config('AR') || 'ar'; |
| 39 |
|
| 40 |
my $redir = '2>&1'; |
| 41 |
$redir = '' if $osname eq 'VMS'; |
| 42 |
|
| 43 |
my $arflags = 'rv'; |
| 44 |
my $arvar = "AR=$ar"; |
| 45 |
|
| 46 |
# Newer versions of binutils can be built with --enable-deterministic-archives |
| 47 |
# which forces all timestamps (among other things) to always be 0, defeating |
| 48 |
# GNU make's archive support. See if ar supports the U option to disable it. |
| 49 |
unlink('libxx.a'); |
| 50 |
$_ = `$ar U$arflags libxx.a a1.o $redir`; |
| 51 |
if ($? == 0) { |
| 52 |
$arflags = 'Urv'; |
| 53 |
$arvar = "$arvar ARFLAGS=$arflags"; |
| 54 |
} |
| 55 |
|
| 56 |
# Some versions of ar print different things on creation. Find out. |
| 57 |
unlink('libxx.a'); |
| 58 |
my $created = `$ar $arflags libxx.a a1.o $redir`; |
| 59 |
$created =~ s/a1\.o/#OBJECT#/g; |
| 60 |
|
| 61 |
# Some versions of ar print different things on add. Find out. |
| 62 |
my $add = `$ar $arflags libxx.a a2.o $redir`; |
| 63 |
$add =~ s/a2\.o/#OBJECT#/g; |
| 64 |
|
| 65 |
# Some versions of ar print different things on replacement. Find out. |
| 66 |
my $repl = `$ar $arflags libxx.a a2.o $redir`; |
| 67 |
$repl =~ s/a2\.o/#OBJECT#/g; |
| 68 |
|
| 69 |
unlink('libxx.a'); |
| 70 |
|
| 71 |
# Very simple |
| 72 |
($_ = $created) =~ s/#OBJECT#/a1.o/g; |
| 73 |
my $answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 74 |
run_make_test('all: libxx.a(a1.o)', $arvar, $answer); |
| 75 |
|
| 76 |
# Multiple .o's. Add a new one to the existing library |
| 77 |
($_ = $add) =~ s/#OBJECT#/a2.o/g; |
| 78 |
|
| 79 |
$answer = "$ar $arflags libxx.a a2.o\n$_"; |
| 80 |
run_make_test('all: libxx.a(a1.o a2.o)', $arvar, $answer); |
| 81 |
|
| 82 |
# Touch one of the .o's so it's rebuilt |
| 83 |
utouch(-40, 'a1.o'); |
| 84 |
|
| 85 |
($_ = $repl) =~ s/#OBJECT#/a1.o/g; |
| 86 |
$answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 87 |
run_make_test(undef, $arvar, $answer); |
| 88 |
|
| 89 |
# Use wildcards |
| 90 |
$answer = "#MAKE#: Nothing to be done for 'all'.\n"; |
| 91 |
run_make_test('all: libxx.a(*.o)', $arvar, $answer); |
| 92 |
|
| 93 |
# Touch one of the .o's so it's rebuilt |
| 94 |
utouch(-30, 'a1.o'); |
| 95 |
|
| 96 |
($_ = $repl) =~ s/#OBJECT#/a1.o/g; |
| 97 |
$answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 98 |
run_make_test(undef, $arvar, $answer); |
| 99 |
|
| 100 |
# Use both wildcards and simple names |
| 101 |
utouch(-50, 'a2.o'); |
| 102 |
|
| 103 |
($_ = $add) =~ s/#OBJECT#/a3.o/g; |
| 104 |
$_ .= "$ar $arflags libxx.a a2.o\n"; |
| 105 |
($_ .= $repl) =~ s/#OBJECT#/a2.o/g; |
| 106 |
$answer = "$ar $arflags libxx.a a3.o\n$_"; |
| 107 |
|
| 108 |
run_make_test('all: libxx.a(a3.o *.o)', $arvar, $answer); |
| 109 |
|
| 110 |
# Check whitespace handling |
| 111 |
utouch(-40, 'a2.o'); |
| 112 |
|
| 113 |
($_ = $repl) =~ s/#OBJECT#/a2.o/g; |
| 114 |
$answer = "$ar $arflags libxx.a a2.o\n$_"; |
| 115 |
run_make_test('all: libxx.a( a3.o *.o )', $arvar, $answer); |
| 116 |
|
| 117 |
rmfiles(qw(a1.c1 a2.c1 a3.c1 a1.o a2.o a3.o libxx.a)); |
| 118 |
|
| 119 |
# Check non-archive targets |
| 120 |
# See Savannah bug #37878 |
| 121 |
$mk_string = q! |
| 122 |
all: foo(bar).baz |
| 123 |
foo(bar).baz: ; @echo '$@' |
| 124 |
!; |
| 125 |
|
| 126 |
run_make_test($mk_string, $arvar, "foo(bar).baz\n"); |
| 127 |
|
| 128 |
# Check renaming of archive targets. |
| 129 |
# See Savannah bug #38442 |
| 130 |
|
| 131 |
mkdir('artest', 0777); |
| 132 |
touch('foo.vhd'); |
| 133 |
$mk_string = q! |
| 134 |
DIR = artest |
| 135 |
vpath % $(DIR) |
| 136 |
default: lib(foo) |
| 137 |
(%): %.vhd ; @cd $(DIR) && touch $(*F) && $(AR) $(ARFLAGS) $@ $(*F) >/dev/null 2>&1 && rm $(*F) |
| 138 |
.PHONY: default |
| 139 |
!; |
| 140 |
run_make_test($mk_string, $arvar, ""); |
| 141 |
|
| 142 |
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); |
| 143 |
|
| 144 |
unlink('foo.vhd'); |
| 145 |
if ($osname eq 'VMS') { |
| 146 |
remove_directory_tree("$cwdpath/artest"); |
| 147 |
} else { |
| 148 |
remove_directory_tree('artest'); |
| 149 |
} |
| 150 |
|
| 151 |
# Check long names for archive members. |
| 152 |
# See Savannah bug #54395 |
| 153 |
|
| 154 |
if ($osname ne 'VMS') { |
| 155 |
my $pre = '1234567890123456'; |
| 156 |
my $lib = 'libxx.a'; |
| 157 |
my $cr = $created; |
| 158 |
$cr =~ s/#OBJECT#/${pre}a/g; |
| 159 |
my $ad = $add; |
| 160 |
$ad =~ s/#OBJECT#/${pre}b/g; |
| 161 |
|
| 162 |
run_make_test(qq! |
| 163 |
# Both member names > 16 characters long |
| 164 |
default: $lib(${pre}a) $lib(${pre}b) |
| 165 |
|
| 166 |
(%): % ; \$(AR) \$(ARFLAGS) \$@ \$% |
| 167 |
|
| 168 |
$pre%: ; touch \$\@ |
| 169 |
!, |
| 170 |
$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"); |
| 171 |
|
| 172 |
# Run it again; nothing should happen |
| 173 |
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); |
| 174 |
|
| 175 |
unlink($lib); |
| 176 |
} |
| 177 |
|
| 178 |
# This tells the test driver that the perl test script executed properly. |
| 179 |
1; |