Added fix for TeX includes with same name as subdirs.
[scons.git] / test / CPPFLAGS.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
29 import TestSCons
30
31 _python_ = TestSCons._python_
32 _exe   = TestSCons._exe
33 _obj   = TestSCons._obj
34 _shobj = TestSCons._shobj
35
36 test = TestSCons.TestSCons()
37
38 # Writing this to accomodate both our in-line tool chain and the
39 # MSVC command lines is too hard, and will be completely unnecessary
40 # some day when we separate our tests.  Punt for now.
41 if sys.platform == 'win32':
42     test.skip_test('Skipping on win32.\n')
43
44
45
46 if sys.platform == 'win32':
47
48     test.write('mylink.py', r"""
49 import sys
50 args = sys.argv[1:]
51 while args:
52     a = args[0]
53     if a[0] != '/':
54         break
55     args.pop(0)
56     if a[:5] == '/OUT:': out = a[5:]
57 infile = open(args[0], 'rb')
58 outfile = open(out, 'wb')
59 for l in infile.readlines():
60     if l[:5] != '#link':
61         outfile.write(l)
62 sys.exit(0)
63 """)
64
65 else:
66
67     test.write('mylink.py', r"""
68 import getopt
69 import sys
70 opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
71 for opt, arg in opts:
72     if opt == '-o': out = arg
73 outfile = open(out, 'wb')
74 for f in args:
75     infile = open(f, 'rb')
76     for l in infile.readlines():
77         if l[:5] != '#link':
78             outfile.write(l)
79 sys.exit(0)
80 """)
81
82 test.write('mygcc.py', r"""
83 import getopt
84 import os
85 import sys
86 compiler = sys.argv[1]
87 clen = len(compiler) + 1
88 opts, args = getopt.getopt(sys.argv[2:], 'co:xf:')
89 for opt, arg in opts:
90     if opt == '-o': out = arg
91     elif opt == '-x': open('mygcc.out', 'ab').write(compiler + "\n")
92 infile = open(args[0], 'rb')
93 outfile = open(out, 'wb')
94 for l in infile.readlines():
95     if l[:clen] != '#' + compiler:
96         outfile.write(l)
97 sys.exit(0)
98 """)
99
100 test.write('SConstruct', """
101 env = Environment(CPPFLAGS = '-x',
102                   LINK = r'%(_python_)s mylink.py',
103                   LINKFLAGS = [],
104                   CC = r'%(_python_)s mygcc.py cc',
105                   CXX = r'%(_python_)s mygcc.py c++',
106                   CXXFLAGS = [],
107                   FORTRAN = r'%(_python_)s mygcc.py g77')
108 env.Program(target = 'foo', source = Split('test1.c test2.cpp test3.F'))
109 """ % locals())
110
111 test.write('test1.c', r"""test1.c
112 #cc
113 #link
114 """)
115
116 test.write('test2.cpp', r"""test2.cpp
117 #c++
118 #link
119 """)
120
121 test.write('test3.F', r"""test3.F
122 #g77
123 #link
124 """)
125
126 test.run(arguments = '.', stderr=None)
127
128 test.must_match('test1' + _obj, "test1.c\n#link\n")
129 test.must_match('test2' + _obj, "test2.cpp\n#link\n")
130 test.must_match('test3' + _obj, "test3.F\n#link\n")
131 test.must_match('foo' + _exe,   "test1.c\ntest2.cpp\ntest3.F\n")
132 if TestSCons.case_sensitive_suffixes('.F', '.f'):
133     test.must_match('mygcc.out', "cc\nc++\ng77\n")
134 else:
135     test.must_match('mygcc.out', "cc\nc++\n")   
136
137 test.write('SConstruct', """
138 env = Environment(CPPFLAGS = '-x',
139                   SHLINK = r'%(_python_)s mylink.py',
140                   SHLINKFLAGS = [],
141                   CC = r'%(_python_)s mygcc.py cc',
142                   CXX = r'%(_python_)s mygcc.py c++',
143                   CXXFLAGS = [],
144                   FORTRAN = r'%(_python_)s mygcc.py g77')
145 env.SharedLibrary(target = File('foo.bar'),
146                   source = Split('test1.c test2.cpp test3.F'))
147 """ % locals())
148
149 test.write('test1.c', r"""test1.c
150 #cc
151 #link
152 """)
153
154 test.write('test2.cpp', r"""test2.cpp
155 #c++
156 #link
157 """)
158
159 test.write('test3.F', r"""test3.F
160 #g77
161 #link
162 """)
163
164 test.unlink('mygcc.out')
165 test.unlink('test1' + _obj)
166 test.unlink('test2' + _obj)
167 test.unlink('test3' + _obj)
168
169 test.run(arguments = '.', stderr = None)
170
171 test.must_match('test1' + _shobj, "test1.c\n#link\n")
172 test.must_match('test2' + _shobj, "test2.cpp\n#link\n")
173 test.must_match('test3' + _shobj, "test3.F\n#link\n")
174 test.must_match('foo.bar',        "test1.c\ntest2.cpp\ntest3.F\n")
175 if TestSCons.case_sensitive_suffixes('.F', '.f'):
176     test.must_match('mygcc.out', "cc\nc++\ng77\n")
177 else:
178     test.must_match('mygcc.out', "cc\nc++\n")   
179
180 test.pass_test()
181
182 # Local Variables:
183 # tab-width:4
184 # indent-tabs-mode:nil
185 # End:
186 # vim: set expandtab tabstop=4 shiftwidth=4: