Imported Upstream version 4.0
[platform/upstream/make.git] / tests / scripts / features / loadapi
1 #                                                                    -*-perl-*-
2 $description = "Test the shared object load API.";
3
4 $details = "Verify the different aspects of the shared object API.";
5
6 # Don't do anything if this system doesn't support "load"
7 exists $FEATURES{load} or return -1;
8
9 my $sobuild = '$(CC) '.($srcdir? "-I$srcdir":'').' -g -shared -fPIC -o $@ $<';
10
11 # First build a shared object
12 # Provide both a default and non-default load symbol
13
14 unlink(qw(testapi.c testapi.so));
15
16 open(my $F, '> testapi.c') or die "open: testapi.c: $!\n";
17 print $F <<'EOF' ;
18 #include <string.h>
19 #include <stdio.h>
20
21 #include "gnumake.h"
22
23 int plugin_is_GPL_compatible;
24
25 static char *
26 test_eval (const char *buf)
27 {
28     gmk_eval (buf, 0);
29     return NULL;
30 }
31
32 static char *
33 test_expand (const char *val)
34 {
35     return gmk_expand (val);
36 }
37
38 static char *
39 test_noexpand (const char *val)
40 {
41     char *str = gmk_alloc (strlen (val));
42     strcpy (str, val);
43     return str;
44 }
45
46 static char *
47 func_test (const char *funcname, unsigned int argc, char **argv)
48 {
49     char *mem;
50
51     if (strcmp (funcname, "test-expand") == 0)
52         return test_expand (argv[0]);
53
54     if (strcmp (funcname, "test-eval") == 0)
55         return test_eval (argv[0]);
56
57     if (strcmp (funcname, "test-noexpand") == 0)
58         return test_noexpand (argv[0]);
59
60     mem = gmk_alloc (sizeof ("unknown"));
61     strcpy (mem, "unknown");
62     return mem;
63 }
64
65 int
66 testapi_gmk_setup ()
67 {
68     gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT);
69     gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND);
70     gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT);
71     gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0);
72     return 1;
73 }
74 EOF
75 close($F) or die "close: testapi.c: $!\n";
76
77 run_make_test('testapi.so: testapi.c ; @'.$sobuild, '', '');
78
79 # TEST 1
80 # Check the gmk_expand() function
81 run_make_test(q!
82 EXPAND = expansion
83 all: ; @echo $(test-expand $$(EXPAND))
84 load testapi.so
85 !,
86               '', "expansion\n");
87
88 # TEST 2
89 # Check the eval operation.  Prove that the argument is expanded only once
90 run_make_test(q!
91 load testapi.so
92 TEST = bye
93 ASSIGN = VAR = $(TEST) $(shell echo there)
94 $(test-eval $(value ASSIGN))
95 TEST = hi
96 all:;@echo '$(VAR)'
97 !,
98               '', "hi there\n");
99
100 # TEST 2
101 # Check the no-expand capability
102 run_make_test(q!
103 load testapi.so
104 TEST = hi
105 all:;@echo '$(test-noexpand $(TEST))'
106 !,
107               '', "\$(TEST)\n");
108
109 unlink(qw(testapi.c testapi.so)) unless $keep;
110
111 # This tells the test driver that the perl test script executed properly.
112 1;