| 1 |
# -*-mode: perl-*- |
| 2 |
|
| 3 |
$description = "Test GNU Make's archive management features."; |
| 4 |
|
| 5 |
$details = "\ |
| 6 |
This only works on systems that support it."; |
| 7 |
|
| 8 |
# If this instance of make doesn't support archives, skip it |
| 9 |
exists $FEATURES{archives} or return -1; |
| 10 |
|
| 11 |
# In theory archive support exists on Windows but it doesn't use ar; |
| 12 |
# someone will need to port this test. |
| 13 |
$port_type eq 'W32' and return -1; |
| 14 |
|
| 15 |
# Create some .o files to work with |
| 16 |
if ($osname eq 'VMS') { |
| 17 |
# VMS AR needs real object files at this time. |
| 18 |
foreach $afile ('a1', 'a2', 'a3') { |
| 19 |
# Use non-standard extension to prevent implicit rules from recreating |
| 20 |
# objects when the test tampers with the timestamp. |
| 21 |
1 while unlink "$afile.c1"; |
| 22 |
1 while unlink "$afile.o"; |
| 23 |
create_file("$afile.c1", "int $afile(void) {return 1;}\n"); |
| 24 |
system("cc $afile.c1 /object=$afile.o"); |
| 25 |
} |
| 26 |
} else { |
| 27 |
utouch(-60, qw(a1.o a2.o a3.o)); |
| 28 |
} |
| 29 |
|
| 30 |
# Fallback if configure did not find AR |
| 31 |
my $ar = get_config('AR') || 'ar'; |
| 32 |
|
| 33 |
my $redir = '2>&1'; |
| 34 |
$redir = '' if $osname eq 'VMS'; |
| 35 |
|
| 36 |
# This is the value from src/default.c |
| 37 |
my $arflags = $osname eq 'aix' ? '-Xany -rv' : '-rv'; |
| 38 |
my $arvar = "AR=\"$ar\""; |
| 39 |
|
| 40 |
# Newer versions of binutils can be built with --enable-deterministic-archives |
| 41 |
# which forces all timestamps (among other things) to always be 0, defeating |
| 42 |
# GNU Make's archive support. See if ar supports the U option to disable it. |
| 43 |
unlink('libxx.a'); |
| 44 |
$_ = `$ar ${arflags}U libxx.a a1.o $redir`; |
| 45 |
if ($? == 0) { |
| 46 |
$arflags = "${arflags}U"; |
| 47 |
$arvar = "$arvar ARFLAGS=\"$arflags\""; |
| 48 |
} |
| 49 |
|
| 50 |
# Some versions of ar print different things on creation. Find out. |
| 51 |
unlink('libxx.a'); |
| 52 |
my $created = `$ar $arflags libxx.a a1.o $redir`; |
| 53 |
$created =~ s/a1\.o/#OBJECT#/g; |
| 54 |
|
| 55 |
# Some versions of ar print different things on add. Find out. |
| 56 |
my $add = `$ar $arflags libxx.a a2.o $redir`; |
| 57 |
$add =~ s/a2\.o/#OBJECT#/g; |
| 58 |
|
| 59 |
# Some versions of ar print different things on replacement. Find out. |
| 60 |
my $repl = `$ar $arflags libxx.a a2.o $redir`; |
| 61 |
$repl =~ s/a2\.o/#OBJECT#/g; |
| 62 |
|
| 63 |
unlink('libxx.a'); |
| 64 |
|
| 65 |
# Very simple |
| 66 |
($_ = $created) =~ s/#OBJECT#/a1.o/g; |
| 67 |
my $answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 68 |
if ($port_type eq 'VMS-DCL') { |
| 69 |
$answer = 'library /replace libxx.a a1.o'; |
| 70 |
} |
| 71 |
run_make_test('all: libxx.a(a1.o)', $arvar, $answer); |
| 72 |
|
| 73 |
# Multiple .o's. Add a new one to the existing library |
| 74 |
($_ = $add) =~ s/#OBJECT#/a2.o/g; |
| 75 |
|
| 76 |
$answer = "$ar $arflags libxx.a a2.o\n$_"; |
| 77 |
if ($port_type eq 'VMS-DCL') { |
| 78 |
$answer = 'library /replace libxx.a a2.o'; |
| 79 |
} |
| 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 |
if ($port_type eq 'VMS-DCL') { |
| 84 |
# utouch is not changing what VMS library compare is testing for. |
| 85 |
# So do a real change by regenerating the file. |
| 86 |
1 while unlink('a1.o'); |
| 87 |
# Later time stamp than last insertion. |
| 88 |
sleep(2); |
| 89 |
system('cc a1.c1 /object=a1.o'); |
| 90 |
# Next insertion will have a later timestamp. |
| 91 |
sleep(2); |
| 92 |
} else { |
| 93 |
utouch(-40, 'a1.o'); |
| 94 |
} |
| 95 |
|
| 96 |
($_ = $repl) =~ s/#OBJECT#/a1.o/g; |
| 97 |
$answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 98 |
if ($port_type eq 'VMS-DCL') { |
| 99 |
$answer = 'library /replace libxx.a a1.o'; |
| 100 |
} |
| 101 |
run_make_test(undef, $arvar, $answer); |
| 102 |
|
| 103 |
# Use wildcards |
| 104 |
$answer = "#MAKE#: Nothing to be done for 'all'.\n"; |
| 105 |
run_make_test('all: libxx.a(*.o)', $arvar, $answer); |
| 106 |
|
| 107 |
# Touch one of the .o's so it's rebuilt |
| 108 |
if ($port_type eq 'VMS-DCL') { |
| 109 |
# utouch is not changing what VMS library compare is testing for. |
| 110 |
# So do a real change by regenerating the file. |
| 111 |
1 while unlink('a1.o'); |
| 112 |
# Make timestamp later than last insertion. |
| 113 |
sleep(2); |
| 114 |
system('cc a1.c1 /object=a1.o'); |
| 115 |
} else { |
| 116 |
utouch(-30, 'a1.o'); |
| 117 |
} |
| 118 |
($_ = $repl) =~ s/#OBJECT#/a1.o/g; |
| 119 |
$answer = "$ar $arflags libxx.a a1.o\n$_"; |
| 120 |
if ($port_type eq 'VMS-DCL') { |
| 121 |
$answer = 'library /replace libxx.a a1.o'; |
| 122 |
} |
| 123 |
run_make_test(undef, $arvar, $answer); |
| 124 |
|
| 125 |
# Use both wildcards and simple names |
| 126 |
if ($port_type eq 'VMS-DCL') { |
| 127 |
# utouch is not changing what VMS library compare is testing for. |
| 128 |
# So do a real change by regenerating the file. |
| 129 |
1 while unlink('a2.o'); |
| 130 |
sleep(2); |
| 131 |
system('cc a2.c1 /object=a2.o'); |
| 132 |
} else { |
| 133 |
utouch(-50, 'a2.o'); |
| 134 |
} |
| 135 |
($_ = $add) =~ s/#OBJECT#/a3.o/g; |
| 136 |
$_ .= "$ar $arflags libxx.a a2.o\n"; |
| 137 |
($_ .= $repl) =~ s/#OBJECT#/a2.o/g; |
| 138 |
$answer = "$ar $arflags libxx.a a3.o\n$_"; |
| 139 |
if ($port_type eq 'VMS-DCL') { |
| 140 |
$answer = 'library /replace libxx.a a3.o'; |
| 141 |
} |
| 142 |
|
| 143 |
run_make_test('all: libxx.a(a3.o *.o)', $arvar, $answer); |
| 144 |
|
| 145 |
# Check whitespace handling |
| 146 |
if ($port_type eq 'VMS-DCL') { |
| 147 |
# utouch is not changing what VMS library compare is testing for. |
| 148 |
# So do a real change by regenerating the file. |
| 149 |
1 while unlink('a2.o'); |
| 150 |
sleep(2); |
| 151 |
system('cc a2.c1 /object=a2.o'); |
| 152 |
} else { |
| 153 |
utouch(-40, 'a2.o'); |
| 154 |
} |
| 155 |
($_ = $repl) =~ s/#OBJECT#/a2.o/g; |
| 156 |
$answer = "$ar $arflags libxx.a a2.o\n$_"; |
| 157 |
if ($port_type eq 'VMS-DCL') { |
| 158 |
$answer = 'library /replace libxx.a a2.o'; |
| 159 |
} |
| 160 |
run_make_test('all: libxx.a( a3.o *.o )', $arvar, $answer); |
| 161 |
|
| 162 |
rmfiles(qw(a1.c1 a2.c1 a3.c1 a1.o a2.o a3.o libxx.a)); |
| 163 |
|
| 164 |
# Check non-archive targets |
| 165 |
# See Savannah bug #37878 |
| 166 |
$mk_string = q! |
| 167 |
all: foo(bar).baz |
| 168 |
foo(bar).baz: ; @echo '$@' |
| 169 |
!; |
| 170 |
|
| 171 |
if ($port_type eq 'VMS-DCL') { |
| 172 |
$mk_string =~ s/echo/write sys\$\$output/; |
| 173 |
$mk_string =~ s/\'/\"/g; |
| 174 |
} |
| 175 |
run_make_test($mk_string, $arvar, "foo(bar).baz\n"); |
| 176 |
|
| 177 |
# Check renaming of archive targets. |
| 178 |
# See Savannah bug #38442 |
| 179 |
|
| 180 |
mkdir('artest', 0777); |
| 181 |
touch('foo.vhd'); |
| 182 |
$mk_string = q! |
| 183 |
DIR = artest |
| 184 |
vpath % $(DIR) |
| 185 |
default: lib(foo) |
| 186 |
(%): %.vhd ; @cd $(DIR) && touch $(*F) && $(AR) $(ARFLAGS) $@ $(*F) >/dev/null 2>&1 && rm $(*F) |
| 187 |
.PHONY: default |
| 188 |
!; |
| 189 |
if ($port_type eq 'VMS-DCL') { |
| 190 |
$mk_string =~ s#= artest#= sys\$\$disk:\[.artest\]#; |
| 191 |
$mk_string =~ s#lib\(foo\)#lib.tlb\(foo\)#; |
| 192 |
$mk_string =~ s#; \@cd#; pipe SET DEFAULT#; |
| 193 |
$mk_string =~ |
| 194 |
s#touch \$\(\*F\)#touch \$\(\*F\) && library/create/text sys\$\$disk:\$\@#; |
| 195 |
$mk_string =~ |
| 196 |
s#library#if f\$\$search(\"\$\@\") \.eqs\. \"\" then library#; |
| 197 |
# VMS needs special handling for null extension |
| 198 |
$mk_string =~ s#\@ \$\(\*F\)#\@ \$\(\*F\)\.#; |
| 199 |
$mk_string =~ s#>/dev/null 2>&1 ##; |
| 200 |
} |
| 201 |
run_make_test($mk_string, $arvar, ""); |
| 202 |
|
| 203 |
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); |
| 204 |
|
| 205 |
unlink('foo.vhd'); |
| 206 |
if ($osname eq 'VMS') { |
| 207 |
remove_directory_tree("$cwdpath/artest"); |
| 208 |
} else { |
| 209 |
remove_directory_tree('artest'); |
| 210 |
} |
| 211 |
|
| 212 |
# Check long names for archive members. |
| 213 |
# See Savannah bug #54395 |
| 214 |
|
| 215 |
if ($osname ne 'VMS' && $osname ne 'os390') { |
| 216 |
my $pre = '1234567890123456'; |
| 217 |
my $lib = 'libxx.a'; |
| 218 |
my $cr = $created; |
| 219 |
$cr =~ s/#OBJECT#/${pre}a/g; |
| 220 |
my $ad = $add; |
| 221 |
$ad =~ s/#OBJECT#/${pre}b/g; |
| 222 |
|
| 223 |
run_make_test(qq! |
| 224 |
# Both member names > 16 characters long |
| 225 |
default: $lib(${pre}a) $lib(${pre}b) |
| 226 |
|
| 227 |
(%): % ; \$(AR) \$(ARFLAGS) \$@ \$% |
| 228 |
|
| 229 |
$pre%: ; touch \$\@ |
| 230 |
!, |
| 231 |
$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"); |
| 232 |
|
| 233 |
# Run it again; nothing should happen |
| 234 |
run_make_test(undef, $arvar, "#MAKE#: Nothing to be done for 'default'.\n"); |
| 235 |
|
| 236 |
unlink($lib); |
| 237 |
} |
| 238 |
|
| 239 |
# SV 61436 : Allow redefining archive rules to propagate timestamps |
| 240 |
|
| 241 |
# These don't work right on z/OS for some reason: archives not fully supported? |
| 242 |
|
| 243 |
if ($osname ne 'os390') { |
| 244 |
# Find the output when creating an archive from multiple files |
| 245 |
|
| 246 |
utouch(-10, 'a.o', 'b.o'); |
| 247 |
my $create2 = `$ar $arflags mylib.a a.o b.o $redir`; |
| 248 |
touch('b.o'); |
| 249 |
my $add2 = `$ar $arflags mylib.a b.o $redir`; |
| 250 |
unlink('a.o', 'b.o', 'mylib.a'); |
| 251 |
|
| 252 |
# Some systems complain when compiling empty files |
| 253 |
create_file('a.c', 'int i;'); |
| 254 |
create_file('b.c', 'int j;'); |
| 255 |
utouch(-20, 'a.c', 'b.c'); |
| 256 |
|
| 257 |
my $cc = get_config('CC') || 'cc'; |
| 258 |
my $vars = "CC=\"$cc\" $arvar"; |
| 259 |
|
| 260 |
run_make_test(q! |
| 261 |
mylib.a: mylib.a(a.o b.o) |
| 262 |
(%): % ; |
| 263 |
%.a: ; $(AR) $(ARFLAGS) $@ $? |
| 264 |
%.o : %.c ; @echo Compile $<; $(COMPILE.c) -o $@ $< |
| 265 |
!, |
| 266 |
$vars, "Compile a.c\nCompile b.c\n$ar $arflags mylib.a a.o b.o\n${create2}rm b.o a.o"); |
| 267 |
|
| 268 |
run_make_test(undef, $vars, "#MAKE#: 'mylib.a' is up to date."); |
| 269 |
|
| 270 |
# Now update one of the source files and it should be compiled and archived |
| 271 |
|
| 272 |
sleep(2); |
| 273 |
touch('b.c'); |
| 274 |
|
| 275 |
run_make_test(undef, $vars, "Compile b.c\n$ar $arflags mylib.a b.o\n${add2}rm b.o"); |
| 276 |
|
| 277 |
run_make_test(undef, $vars, "#MAKE#: 'mylib.a' is up to date."); |
| 278 |
|
| 279 |
unlink('a.c', 'b.c', 'a.o', 'b.o', 'mylib.a'); |
| 280 |
} |
| 281 |
|
| 282 |
# This tells the test driver that the perl test script executed properly. |
| 283 |
1; |