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__"
36 test = TestSCons.TestSCons()
38 # Some systems apparently need -ldl on the link line, others don't.
39 no_dl_lib = "env.Program(target = 'dlopenprog', source = 'dlopenprog.c')"
40 use_dl_lib = "env.Program(target = 'dlopenprog', source = 'dlopenprog.c', LIBS=['dl'])"
44 'darwin8' : no_dl_lib, # ONLY NEEDED FOR 1.5.2
45 'freebsd4' : no_dl_lib,
46 'linux2' : use_dl_lib,
48 platforms_with_dlopen = dlopen_line.keys()
50 test.write('SConstruct', """
52 # dlopenprog tries to dynamically load foo1 at runtime using dlopen().
53 env.LoadableModule(target = 'foo1', source = 'f1.c')
54 """ + dlopen_line.get(sys.platform, ''))
57 test.write('f1.c', r"""
76 main(int argc, char *argv[])
79 void *foo1_shobj = dlopen("__foo1_name__", RTLD_NOW);
81 printf("Error loading foo1 '__foo1_name__' library at runtime, exiting.\n");
82 printf("%d\n", errno);
86 void (*f1)() = dlsym(foo1_shobj, "f1\0");
88 printf("dlopenprog.c\n");
94 # Darwin dlopen()s a bundle named "foo1",
95 # other systems dlopen() a traditional libfoo1.so file.
96 foo1_name = {'darwin' : 'foo1'}.get(sys.platform[:6], dll_+'foo1'+_dll)
98 test.write('dlopenprog.c',
99 dlopenprog.replace('__foo1_name__', foo1_name))
101 test.run(arguments = '.',
102 stderr=TestSCons.noisy_ar,
103 match=TestSCons.match_re_dotall)
105 # TODO: Add new Intel-based Macs? Why are we only picking on Macs?
106 #if sys.platform.find('darwin') != -1:
107 # test.run(program='/usr/bin/file',
108 # arguments = "foo1",
109 # match = TestCmd.match_re,
110 # stdout="foo1: Mach-O bundle (ppc|i386)\n")
111 # My laptop prints "foo1: Mach-O 64-bit bundle x86_64"
113 if sys.platform in platforms_with_dlopen:
114 os.environ['LD_LIBRARY_PATH'] = test.workpath()
115 test.run(program = test.workpath('dlopenprog'),
116 stdout = "f1.c\ndlopenprog.c\n")
124 # indent-tabs-mode:nil
126 # vim: set expandtab tabstop=4 shiftwidth=4: