4570ebce4872281922c3ac80e5a31bf360873d4e
[scons.git] / test / Fortran / SHF77FLAGS.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 os
28 import string
29 import sys
30 import TestSCons
31
32 _python_ = TestSCons._python_
33
34 _obj = TestSCons._shobj
35 obj_ = TestSCons.shobj_
36
37 test = TestSCons.TestSCons()
38
39
40
41 test.write('myg77.py', r"""
42 import getopt
43 import sys
44 opts, args = getopt.getopt(sys.argv[1:], 'cf:o:x')
45 optstring = ''
46 for opt, arg in opts:
47     if opt == '-o': out = arg
48     elif opt != '-f': optstring = optstring + ' ' + opt
49 infile = open(args[0], 'rb')
50 outfile = open(out, 'wb')
51 outfile.write(optstring + "\n")
52 for l in infile.readlines():
53     if l[:4] != '#g77':
54         outfile.write(l)
55 sys.exit(0)
56 """)
57
58
59
60 test.write('SConstruct', """
61 env = Environment(SHF77 = r'%(_python_)s myg77.py')
62 env.Append(SHF77FLAGS = '-x')
63 env.SharedObject(target = 'test09', source = 'test09.f77')
64 env.SharedObject(target = 'test10', source = 'test10.F77')
65 """ % locals())
66
67 test.write('test09.f77', "This is a .f77 file.\n#g77\n")
68 test.write('test10.F77', "This is a .F77 file.\n#g77\n")
69
70 test.run(arguments = '.', stderr = None)
71
72 test.must_match(obj_ + 'test09' + _obj, " -c -x\nThis is a .f77 file.\n")
73 test.must_match(obj_ + 'test10' + _obj, " -c -x\nThis is a .F77 file.\n")
74
75
76 fc = 'f77'
77 g77 = test.detect_tool(fc)
78
79 if g77:
80
81     test.write("wrapper.py",
82 """import os
83 import string
84 import sys
85 open('%s', 'wb').write("wrapper.py\\n")
86 os.system(string.join(sys.argv[1:], " "))
87 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
88
89     test.write('SConstruct', """
90 foo = Environment(SHF77 = '%(fc)s')
91 shf77 = foo.Dictionary('SHF77')
92 bar = foo.Clone(SHF77 = r'%(_python_)s wrapper.py ' + shf77,
93                 tools = ["default", 'f77'], F77FILESUFFIXES = [".f"])
94 bar.Append(SHF77FLAGS = '-Ix')
95 foo.SharedLibrary(target = 'foo/foo', source = 'foo.f')
96 bar.SharedLibrary(target = 'bar/bar', source = 'bar.f')
97 """ % locals())
98
99     test.write('foo.f', r"""
100       PROGRAM FOO
101       PRINT *,'foo.f'
102       STOP
103       END
104 """)
105
106     test.write('bar.f', r"""
107       PROGRAM BAR
108       PRINT *,'bar.f'
109       STOP
110       END
111 """)
112
113
114     test.run(arguments = 'foo', stderr = None)
115
116     test.must_not_exist('wrapper.out')
117
118     import sys
119     if sys.platform[:5] == 'sunos':
120         test.run(arguments = 'bar', stderr = None)
121     else:
122         test.run(arguments = 'bar')
123
124     test.must_match('wrapper.out', "wrapper.py\n")
125
126 test.pass_test()