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__"
28 Testing the gnu tool chain, i.e. the tools 'gcc', 'g++' and 'gnulink'.
35 _python_ = TestSCons._python_
39 return TestSCons.dll_ + s + TestSCons._dll
41 test = TestSCons.TestSCons()
43 test.subdir('gnutools')
45 test.write(['gnutools','mygcc.py'], """
48 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
51 for opt, arg in cmd_opts:
52 if opt == '-o': output = open(arg, 'wb')
53 else: opt_string = opt_string + ' ' + opt + arg
54 output.write('gcc ' + opt_string + '\\n')
56 contents = open(a, 'rb').read()
57 output.write(contents)
62 test.write(['gnutools','myg++.py'], """
65 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
68 for opt, arg in cmd_opts:
69 if opt == '-o': output = open(arg, 'wb')
70 else: opt_string = opt_string + ' ' + opt + arg
71 output.write('g++ ' + opt_string + '\\n')
73 contents = open(a, 'rb').read()
74 output.write(contents)
81 test.write(['work1', 'cfile1.c'],"""
85 test.write(['work1', 'cfile2.c'],"""
89 test.write(['work1', 'cppfile1.cpp'],"""
93 test.write(['work1', 'cppfile2.cpp'],"""
97 mygcc_py = test.workpath('gnutools','mygcc.py')
98 mygxx_py = test.workpath('gnutools','myg++.py')
100 test.write(['work1', 'SConstruct'],"""
101 env = Environment(tools=['gcc','g++','gnulink'],
102 CC=r'%(_python_)s %(mygcc_py)s',
103 CXX=r'%(_python_)s %(mygxx_py)s',
106 env.Program('c-only', Split('cfile1.c cfile2.c'))
107 env.Program('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
108 env.Program('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
110 env.SharedLibrary('c-only', Split('cfile1.c cfile2.c'))
111 env.SharedLibrary('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
112 env.SharedLibrary('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
115 test.run(chdir='work1')
117 def testObject(test, obj, expect):
118 contents = test.read(test.workpath('work1', obj))
119 line1 = string.split(contents,'\n')[0]
120 actual = string.join(string.split(line1))
121 if not expect == actual:
122 print "%s: %s != %s\n" % (obj, repr(expect), repr(actual))
125 if sys.platform in ('win32', 'cygwin'):
130 testObject(test, 'cfile1.o', 'gcc -c')
131 testObject(test, 'cfile2.o', 'gcc -c')
132 testObject(test, 'cppfile1.o', 'g++ -c')
133 testObject(test, 'cppfile2.o', 'g++ -c')
134 testObject(test, 'cfile1.os', 'gcc -c' + c_fpic)
135 testObject(test, 'cfile2.os', 'gcc -c' + c_fpic)
136 testObject(test, 'cppfile1.os', 'g++ -c' + c_fpic)
137 testObject(test, 'cppfile2.os', 'g++ -c' + c_fpic)
138 testObject(test, 'c-only' + _exe, 'gcc')
139 testObject(test, 'cpp-only' + _exe, 'g++')
140 testObject(test, 'c-and-cpp' + _exe, 'g++')
141 testObject(test, dll('c-only'), 'gcc -shared')
142 testObject(test, dll('cpp-only'), 'g++ -shared')
143 testObject(test, dll('c-and-cpp'), 'g++ -shared')