Revert revision 4742. How hard is it to understand "No bugfixes in 2.0"?
[scons.git] / test / CXX / CXXFLAGS.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 """
28 Verify that $CXXFLAGS settings are used to build both static
29 and shared object files.
30 """
31
32 import os
33 import sys
34
35 import TestSCons
36
37 _obj = TestSCons._obj
38
39 if os.name == 'posix':
40     os.environ['LD_LIBRARY_PATH'] = '.'
41 if sys.platform.find('irix') > -1:
42     os.environ['LD_LIBRARYN32_PATH'] = '.'
43
44 test = TestSCons.TestSCons()
45
46 e = test.Environment()
47
48 test.write('SConstruct', """
49 foo = Environment(WINDOWS_INSERT_DEF=1)
50 foo.Append(CXXFLAGS = '-DFOO') 
51 bar = Environment(WINDOWS_INSERT_DEF=1)
52 bar.Append(CXXFLAGS = '-DBAR') 
53 foo_obj = foo.SharedObject(target = 'fooshared%(_obj)s', source = 'doIt.cpp')
54 bar_obj = bar.SharedObject(target = 'barshared%(_obj)s', source = 'doIt.cpp')
55 foo.SharedLibrary(target = 'foo', source = foo_obj)
56 bar.SharedLibrary(target = 'bar', source = bar_obj)
57
58 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
59 foo_obj = fooMain.Object(target='foomain', source='main.c')
60 fooMain.Program(target='fooprog', source=foo_obj)
61
62 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
63 bar_obj = barMain.Object(target='barmain', source='main.c')
64 barMain.Program(target='barprog', source=bar_obj)
65
66 foo_obj = foo.Object(target = 'foostatic', source = 'prog.cpp')
67 bar_obj = bar.Object(target = 'barstatic', source = 'prog.cpp')
68 foo.Program(target = 'foo', source = foo_obj)
69 bar.Program(target = 'bar', source = bar_obj)
70 """ % locals())
71
72 test.write('foo.def', r"""
73 LIBRARY        "foo"
74 DESCRIPTION    "Foo Shared Library"
75
76 EXPORTS
77    doIt
78 """)
79
80 test.write('bar.def', r"""
81 LIBRARY        "bar"
82 DESCRIPTION    "Bar Shared Library"
83
84 EXPORTS
85    doIt
86 """)
87
88 test.write('doIt.cpp', r"""
89 #include <stdio.h>
90
91 extern "C" void
92 doIt()
93 {
94 #ifdef FOO
95         printf("doIt.cpp:  FOO\n");
96 #endif
97 #ifdef BAR
98         printf("doIt.cpp:  BAR\n");
99 #endif
100 }
101 """)
102
103 test.write('main.c', r"""
104
105 void doIt();
106
107 int
108 main(int argc, char* argv[])
109 {
110     doIt();
111     return 0;
112 }
113 """)
114
115 test.write('prog.cpp', r"""
116 #include <stdio.h>
117 #include <stdlib.h>
118
119 int
120 main(int argc, char *argv[])
121 {
122         argv[argc++] = (char *)"--";
123 #ifdef FOO
124         printf("prog.c:  FOO\n");
125 #endif
126 #ifdef BAR
127         printf("prog.c:  BAR\n");
128 #endif
129         exit (0);
130 }
131 """)
132
133 test.run(arguments = '.')
134
135 test.run(program = test.workpath('fooprog'), stdout = "doIt.cpp:  FOO\n")
136 test.run(program = test.workpath('barprog'), stdout = "doIt.cpp:  BAR\n")
137 test.run(program = test.workpath('foo'), stdout = "prog.c:  FOO\n")
138 test.run(program = test.workpath('bar'), stdout = "prog.c:  BAR\n")
139
140
141
142 test.write('SConstruct', """
143 bar = Environment(WINDOWS_INSERT_DEF=1)
144 bar.Append(CXXFLAGS = '-DBAR') 
145 foo_obj = bar.SharedObject(target = 'foo%(_obj)s', source = 'doIt.cpp')
146 bar_obj = bar.SharedObject(target = 'bar%(_obj)s', source = 'doIt.cpp')
147 bar.SharedLibrary(target = 'foo', source = foo_obj)
148 bar.SharedLibrary(target = 'bar', source = bar_obj)
149
150 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
151 foo_obj = barMain.Object(target='foomain', source='main.c')
152 bar_obj = barMain.Object(target='barmain', source='main.c')
153 barMain.Program(target='barprog', source=foo_obj)
154 barMain.Program(target='fooprog', source=bar_obj)
155 """ % locals())
156
157 test.run(arguments = '.')
158
159 test.run(program = test.workpath('fooprog'), stdout = "doIt.cpp:  BAR\n")
160 test.run(program = test.workpath('barprog'), stdout = "doIt.cpp:  BAR\n")
161
162
163
164 test.pass_test()
165
166 # Local Variables:
167 # tab-width:4
168 # indent-tabs-mode:nil
169 # End:
170 # vim: set expandtab tabstop=4 shiftwidth=4: