Implement new "load" directive.
[make.git] / tests / scripts / features / load
blob8117bbd940335e0ecafac38d889b3bc439cd60d7
1 #                                                                    -*-perl-*-
2 $description = "Test the load operator.";
4 $details = "Test dynamic loading of modules.";
6 # Don't do anything if this system doesn't support "load"
7 exists $FEATURES{load} or return -1;
9 # First build a shared object
10 # Provide both a default and non-default load symbol
12 unlink(qw(testload.c testload.so));
14 open(my $F, '> testload.c') or die "open: testload.c: $!\n";
15 print $F <<'EOF' ;
16 #include <string.h>
17 #include <stdio.h>
19 void define_new_function (void *, const char *, int, int, int,
20                           char *(*)(char *, char **, const char *));
22 char *variable_buffer_output (char *, const char *, unsigned int);
24 static char *
25 func_test(char *o, char **argv, const char *funcname)
27     return variable_buffer_output (o, funcname, strlen (funcname));
30 int
31 testload_gmake_setup ()
33     define_new_function (0, "func-a", 1, 1, 1, func_test);
34     return 1;
37 int
38 explicit_setup ()
40     define_new_function (0, "func-b", 1, 1, 1, func_test);
41     return 1;
43 EOF
44 close($F) or die "close: testload.c: $!\n";
46 run_make_test('testload.so: testload.c ; @$(CC) -g -shared -fPIC -o $@ $<',
47               '', '');
49 # TEST 1
50 run_make_test(q!
51 all: ; @echo $(func-a foo) $(func-b bar)
52 load ./testload.so
54               '', "func-a\n");
56 # TEST 2
57 # Load a different function
58 run_make_test(q!
59 all: ; @echo $(func-a foo) $(func-b bar)
60 load ./testload.so(explicit_setup)
62               '', "func-b\n");
64 # TEST 3
65 # Verify the .LOADED variable
66 run_make_test(q!
67 all: ; @echo $(filter ./testload.so,$(.LOADED)) $(func-a foo) $(func-b bar)
68 load ./testload.so(explicit_setup)
70               '', "./testload.so func-b\n");
72 # TEST 4
73 # Check multiple loads
74 run_make_test(q!
75 all: ; @echo $(filter ./testload.so,$(.LOADED)) $(func-a foo) $(func-b bar)
76 load ./testload.so
77 load ./testload.so(explicit_setup)
79               '', "./testload.so func-a\n");
81 unlink(qw(testload.c testload.so)) unless $keep;
83 # This tells the test driver that the perl test script executed properly.