Merged revisions 1667-1674 via svnmerge from
[scons.git] / test / CC / SHCCFLAGS.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import sys
28 import TestSCons
29 import os
30 import string
31     
32 test = TestSCons.TestSCons()
33
34 e = test.Environment()
35 fooflags = e['SHCCFLAGS'] + ' -DFOO'
36 barflags = e['SHCCFLAGS'] + ' -DBAR'
37
38 if os.name == 'posix':
39     os.environ['LD_LIBRARY_PATH'] = '.'
40 if string.find(sys.platform, 'irix') > -1:
41     os.environ['LD_LIBRARYN32_PATH'] = '.'
42
43 test.write('SConstruct', """
44 foo = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
45 bar = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
46
47 foo_obj = foo.SharedObject(target = 'foo', source = 'prog.c')
48 foo.SharedLibrary(target = 'foo', source = foo_obj)
49
50 bar_obj = bar.SharedObject(target = 'bar', source = 'prog.c')
51 bar.SharedLibrary(target = 'bar', source = bar_obj)
52
53 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
54 foomain_obj = fooMain.Object(target='foomain', source='main.c')
55 fooMain.Program(target='fooprog', source=foomain_obj)
56
57 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
58 barmain_obj = barMain.Object(target='barmain', source='main.c')
59 barMain.Program(target='barprog', source=barmain_obj)
60 """ % (fooflags, barflags))
61
62 test.write('foo.def', r"""
63 LIBRARY        "foo"
64 DESCRIPTION    "Foo Shared Library"
65
66 EXPORTS
67    doIt
68 """)
69
70 test.write('bar.def', r"""
71 LIBRARY        "bar"
72 DESCRIPTION    "Bar Shared Library"
73
74 EXPORTS
75    doIt
76 """)
77
78 test.write('prog.c', r"""
79 #include <stdio.h>
80
81 void
82 doIt()
83 {
84 #ifdef FOO
85         printf("prog.c:  FOO\n");
86 #endif
87 #ifdef BAR
88         printf("prog.c:  BAR\n");
89 #endif
90 }
91 """)
92
93 test.write('main.c', r"""
94
95 void doIt();
96
97 int
98 main(int argc, char* argv[])
99 {
100     doIt();
101     return 0;
102 }
103 """)
104
105 test.run(arguments = '.')
106
107 test.run(program = test.workpath('fooprog'), stdout = "prog.c:  FOO\n")
108 test.run(program = test.workpath('barprog'), stdout = "prog.c:  BAR\n")
109
110 test.write('SConstruct', """
111 bar = Environment(SHCCFLAGS = '%s', WINDOWS_INSERT_DEF=1)
112
113 foo_obj = bar.SharedObject(target = 'foo', source = 'prog.c')
114 bar.SharedLibrary(target = 'foo', source = foo_obj)
115
116 bar_obj = bar.SharedObject(target = 'bar', source = 'prog.c')
117 bar.SharedLibrary(target = 'bar', source = bar_obj)
118
119 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
120 foomain_obj = barMain.Object(target='foomain', source='main.c')
121 barmain_obj = barMain.Object(target='barmain', source='main.c')
122 barMain.Program(target='barprog', source=foomain_obj)
123 barMain.Program(target='fooprog', source=barmain_obj)
124 """ % (barflags))
125
126 test.run(arguments = '.')
127
128 test.run(program = test.workpath('fooprog'), stdout = "prog.c:  BAR\n")
129 test.run(program = test.workpath('barprog'), stdout = "prog.c:  BAR\n")
130
131 test.pass_test()