Imported Upstream version 4.0
[platform/upstream/make.git] / tests / scripts / features / archives
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 utouch(-60, qw(a1.o a2.o a3.o));
13
14 # Some versions of ar print different things on creation.  Find out.
15 my $created = `ar rv libxx.a a1.o 2>&1`;
16
17 # Some versions of ar print different things on add.  Find out.
18 my $add = `ar rv libxx.a a2.o 2>&1`;
19 $add =~ s/a2\.o/#OBJECT#/g;
20
21 # Some versions of ar print different things on replacement.  Find out.
22 my $repl = `ar rv libxx.a a2.o 2>&1`;
23 $repl =~ s/a2\.o/#OBJECT#/g;
24
25 unlink('libxx.a');
26
27 # Very simple
28 run_make_test('all: libxx.a(a1.o)',
29               '', "ar rv libxx.a a1.o\n$created");
30
31 # Multiple .o's.  Add a new one to the existing library
32 ($_ = $add) =~ s/#OBJECT#/a2.o/g;
33 run_make_test('all: libxx.a(a1.o a2.o)',
34               '', "ar rv libxx.a a2.o\n$_");
35
36 # Touch one of the .o's so it's rebuilt
37 utouch(-40, 'a1.o');
38 ($_ = $repl) =~ s/#OBJECT#/a1.o/g;
39 run_make_test(undef, '', "ar rv libxx.a a1.o\n$_");
40
41 # Use wildcards
42 run_make_test('all: libxx.a(*.o)',
43               '', "#MAKE#: Nothing to be done for 'all'.\n");
44
45 # Touch one of the .o's so it's rebuilt
46 utouch(-30, 'a1.o');
47 ($_ = $repl) =~ s/#OBJECT#/a1.o/g;
48 run_make_test(undef, '', "ar rv libxx.a a1.o\n$_");
49
50 # Use both wildcards and simple names
51 utouch(-50, 'a2.o');
52 ($_ = $add) =~ s/#OBJECT#/a3.o/g;
53 $_ .= "ar rv libxx.a a2.o\n";
54 ($_ .= $repl) =~ s/#OBJECT#/a2.o/g;
55 run_make_test('all: libxx.a(a3.o *.o)', '',
56               "ar rv libxx.a a3.o\n$_");
57
58 # Check whitespace handling
59 utouch(-40, 'a2.o');
60 ($_ = $repl) =~ s/#OBJECT#/a2.o/g;
61 run_make_test('all: libxx.a(  a3.o    *.o     )', '',
62               "ar rv libxx.a a2.o\n$_");
63
64 rmfiles(qw(a1.o a2.o a3.o libxx.a));
65
66 # Check non-archive targets
67 # See Savannah bug #37878
68 run_make_test(q!
69 all: foo(bar).baz
70 foo(bar).baz: ; @echo '$@'
71 !,
72               '', "foo(bar).baz\n");
73
74 # Check renaming of archive targets.
75 # See Savannah bug #38442
76
77 mkdir('artest', 0777);
78 touch('foo.vhd');
79
80 run_make_test(q!
81 DIR = artest
82 vpath % $(DIR)
83 default: lib(foo)
84 (%): %.vhd ; @cd $(DIR) && touch $(*F) && $(AR) $(ARFLAGS) $@ $(*F) >/dev/null 2>&1 && rm $(*F)
85 .PHONY: default
86 !,
87               '', "");
88
89 run_make_test(undef, '', "#MAKE#: Nothing to be done for 'default'.\n");
90
91 unlink('foo.vhd');
92 remove_directory_tree('artest');
93
94 # This tells the test driver that the perl test script executed properly.
95 1;