5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
37 test = TestSCons.TestSCons()
39 # Some systems apparently need -ldl on the link line, others don't.
40 no_dl_lib = "env.Program(target = 'dlopenprog', source = 'dlopenprog.c')"
41 use_dl_lib = "env.Program(target = 'dlopenprog', source = 'dlopenprog.c', LIBS=['dl'])"
45 'darwin8' : no_dl_lib, # ONLY NEEDED FOR 1.5.2
46 'freebsd4' : no_dl_lib,
47 'linux2' : use_dl_lib,
49 platforms_with_dlopen = dlopen_line.keys()
51 test.write('SConstruct', """
53 # dlopenprog tries to dynamically load foo1 at runtime using dlopen().
54 env.LoadableModule(target = 'foo1', source = 'f1.c')
55 """ + dlopen_line.get(sys.platform, ''))
58 test.write('f1.c', r"""
77 main(int argc, char *argv[])
80 void *foo1_shobj = dlopen("__foo1_name__", RTLD_NOW);
82 printf("Error loading foo1 '__foo1_name__' library at runtime, exiting.\n");
83 printf("%d\n", errno);
87 void (*f1)() = dlsym(foo1_shobj, "f1\0");
89 printf("dlopenprog.c\n");
95 # Darwin dlopen()s a bundle named "foo1",
96 # other systems dlopen() a traditional libfoo1.so file.
97 foo1_name = {'darwin' : 'foo1'}.get(sys.platform[:6], dll_+'foo1'+_dll)
99 test.write('dlopenprog.c',
100 string.replace(dlopenprog, '__foo1_name__', foo1_name))
102 test.run(arguments = '.',
103 stderr=TestSCons.noisy_ar,
104 match=TestSCons.match_re_dotall)
106 if string.find(sys.platform, 'darwin') != -1:
107 test.run(program='/usr/bin/file',
109 match = TestCmd.match_re,
110 stdout="foo1: Mach-O bundle (ppc|i386)\n")
112 if sys.platform in platforms_with_dlopen:
113 os.environ['LD_LIBRARY_PATH'] = test.workpath()
114 test.run(program = test.workpath('dlopenprog'),
115 stdout = "f1.c\ndlopenprog.c\n")