| 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 | # Create some .o files to work with
|
|---|
| 12 | if ($osname eq 'VMS') {
|
|---|
| 13 | use Cwd;
|
|---|
| 14 | my $pwd = getcwd;
|
|---|
| 15 | # VMS AR needs real object files at this time.
|
|---|
| 16 | foreach $afile ('a1', 'a2', 'a3') {
|
|---|
| 17 | # Use non-standard extension to prevent implicit rules from recreating
|
|---|
| 18 | # objects when the test tampers with the timestamp.
|
|---|
| 19 | 1 while unlink "$afile.c1";
|
|---|
| 20 | 1 while unlink "$afile.o";
|
|---|
| 21 | open (MYFILE, ">$afile.c1");
|
|---|
| 22 | print MYFILE "int $afile(void) {return 1;}\n";
|
|---|
| 23 | close MYFILE;
|
|---|
| 24 | system("cc $afile.c1 /object=$afile.o");
|
|---|
| 25 | }
|
|---|
| 26 | } else {
|
|---|
| 27 | utouch(-60, qw(a1.o a2.o a3.o));
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | my $ar = $CONFIG_FLAGS{AR};
|
|---|
| 31 |
|
|---|
| 32 | # Fallback if configure did not find AR, such as VMS
|
|---|
| 33 | # which does not run configure.
|
|---|
| 34 | $ar = 'ar' if $ar eq '';
|
|---|
| 35 |
|
|---|
| 36 | my $redir = '2>&1';
|
|---|
| 37 | $redir = '' if $osname eq 'VMS';
|
|---|
| 38 |
|
|---|
| 39 | my $arflags = 'rv';
|
|---|
| 40 | my $arvar = "AR=$ar";
|
|---|
| 41 |
|
|---|
| 42 | # Newer versions of binutils can be built with --enable-deterministic-archives
|
|---|
| 43 | # which forces all timestamps (among other things) to always be 0, defeating
|
|---|
| 44 | # GNU make's archive support. See if ar supports the U option to disable it.
|
|---|
| 45 | unlink('libxx.a');
|
|---|
| 46 | $_ = `$ar U$arflags libxx.a a1.o $redir`;
|
|---|
| 47 | if ($? == 0) {
|
|---|
| 48 | $arflags = 'Urv';
|
|---|
| 49 | $arvar = "$arvar ARFLAGS=$arflags";
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | # Some versions of ar print different things on creation. Find out.
|
|---|
| 53 | unlink('libxx.a');
|
|---|
| 54 | my $created = `$ar $arflags libxx.a a1.o $redir`;
|
|---|
| 55 |
|
|---|
| 56 | # Some versions of ar print different things on add. Find out.
|
|---|
| 57 | my $add = `$ar $arflags libxx.a a2.o $redir`;
|
|---|
| 58 | $add =~ s/a2\.o/#OBJECT#/g;
|
|---|
| 59 |
|
|---|
| 60 | # Some versions of ar print different things on replacement. Find out.
|
|---|
| 61 | my $repl = `$ar $arflags libxx.a a2.o $redir`;
|
|---|
| 62 | $repl =~ s/a2\.o/#OBJECT#/g;
|
|---|
| 63 |
|
|---|
| 64 | unlink('libxx.a');
|
|---|
| 65 |
|
|---|
| 66 | # Very simple
|
|---|
| 67 | my $answer = "$ar $arflags libxx.a a1.o\n$created";
|
|---|
| 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("$pwd/artest");
|
|---|
| 208 | } else {
|
|---|
| 209 | remove_directory_tree('artest');
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | # This tells the test driver that the perl test script executed properly.
|
|---|
| 213 | 1;
|
|---|