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 Testing the gnu tool chain, i.e. the tools 'gcc', 'g++' and 'gnulink'.
28 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
33 _python_
= TestSCons
._python
_
37 return TestSCons
.dll_
+ s
+ TestSCons
._dll
39 test
= TestSCons
.TestSCons()
41 test
.subdir('gnutools')
43 test
.write(['gnutools','mygcc.py'], """
47 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
48 except getopt.GetoptError:
49 # we may be called with --version, just quit if so
53 for opt, arg in cmd_opts:
54 if opt == '-o': out = arg
55 else: opt_string = opt_string + ' ' + opt + arg
56 with open(out, 'w') as ofp:
57 ofp.write('gcc ' + opt_string + '\\n')
59 with open(a, 'r') as ifp:
64 test
.write(['gnutools','myg++.py'], """
68 cmd_opts, args = getopt.getopt(sys.argv[1:], 'f:s:co:', [])
69 except getopt.GetoptError:
70 # we may be called with --version, just quit if so
74 for opt, arg in cmd_opts:
75 if opt == '-o': out = arg
76 else: opt_string = opt_string + ' ' + opt + arg
77 with open(out, 'w') as ofp:
78 ofp.write('g++ ' + opt_string + '\\n')
80 with open(a, 'r') as ifp:
87 test
.write(['work1', 'cfile1.c'],"""
91 test
.write(['work1', 'cfile2.c'],"""
95 test
.write(['work1', 'cppfile1.cpp'],"""
99 test
.write(['work1', 'cppfile2.cpp'],"""
103 mygcc_py
= test
.workpath('gnutools','mygcc.py')
104 mygxx_py
= test
.workpath('gnutools','myg++.py')
106 test
.write(['work1', 'SConstruct'],"""
107 env = Environment(tools=['gcc','g++','gnulink'],
108 CC=r'%(_python_)s %(mygcc_py)s',
109 CXX=r'%(_python_)s %(mygxx_py)s',
112 env.Program('c-only', Split('cfile1.c cfile2.c'))
113 env.Program('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
114 env.Program('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
116 env.SharedLibrary('c-only', Split('cfile1.c cfile2.c'))
117 env.SharedLibrary('cpp-only', Split('cppfile1.cpp cppfile2.cpp'))
118 env.SharedLibrary('c-and-cpp', Split('cfile1.c cppfile1.cpp'))
121 test
.run(chdir
='work1')
123 def testObject(test
, obj
, expect
):
124 contents
= test
.read(test
.workpath('work1', obj
))
125 line1
= contents
.split(b
'\n')[0]
126 actual
= b
' '.join(line1
.split())
127 if not expect
== actual
:
128 print("%s: %s != %s\n" % (obj
, repr(expect
), repr(actual
)))
131 if sys
.platform
in ('win32', 'cygwin'):
136 testObject(test
, 'cfile1.o', b
'gcc -c')
137 testObject(test
, 'cfile2.o', b
'gcc -c')
138 testObject(test
, 'cppfile1.o', b
'g++ -c')
139 testObject(test
, 'cppfile2.o', b
'g++ -c')
140 testObject(test
, 'cfile1.os', b
'gcc -c' + c_fpic
)
141 testObject(test
, 'cfile2.os', b
'gcc -c' + c_fpic
)
142 testObject(test
, 'cppfile1.os', b
'g++ -c' + c_fpic
)
143 testObject(test
, 'cppfile2.os', b
'g++ -c' + c_fpic
)
144 testObject(test
, 'c-only' + _exe
, b
'gcc')
145 testObject(test
, 'cpp-only' + _exe
, b
'g++')
146 testObject(test
, 'c-and-cpp' + _exe
, b
'g++')
147 testObject(test
, dll('c-only'), b
'gcc -shared')
148 testObject(test
, dll('cpp-only'), b
'g++ -shared')
149 testObject(test
, dll('c-and-cpp'), b
'g++ -shared')
155 # indent-tabs-mode:nil
157 # vim: set expandtab tabstop=4 shiftwidth=4: