Merged revisions 2867-2879 via svnmerge from
[scons.git] / test / Fortran / SHF77.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 _obj   = TestSCons._shobj
34 obj_   = TestSCons.shobj_
35
36 test = TestSCons.TestSCons()
37
38
39
40 test.write('myfortran.py', r"""
41 import getopt
42 import sys
43 comment = '#' + sys.argv[1]
44 opts, args = getopt.getopt(sys.argv[2:], 'cf:o:K:')
45 for opt, arg in opts:
46     if opt == '-o': out = arg
47 infile = open(args[0], 'rb')
48 outfile = open(out, 'wb')
49 for l in infile.readlines():
50     if l[:len(comment)] != comment:
51         outfile.write(l)
52 sys.exit(0)
53 """)
54
55
56
57 test.write('SConstruct', """
58 env = Environment(SHF77 = r'%(_python_)s myfortran.py g77',
59                   SHFORTRAN = r'%(_python_)s myfortran.py fortran')
60 env.SharedObject(target = 'test01', source = 'test01.f')
61 env.SharedObject(target = 'test02', source = 'test02.F')
62 env.SharedObject(target = 'test03', source = 'test03.for')
63 env.SharedObject(target = 'test04', source = 'test04.FOR')
64 env.SharedObject(target = 'test05', source = 'test05.ftn')
65 env.SharedObject(target = 'test06', source = 'test06.FTN')
66 env.SharedObject(target = 'test07', source = 'test07.fpp')
67 env.SharedObject(target = 'test08', source = 'test08.FPP')
68 env.SharedObject(target = 'test09', source = 'test09.f77')
69 env.SharedObject(target = 'test10', source = 'test10.F77')
70 """ % locals())
71
72 test.write('test01.f',   "This is a .f file.\n#fortran\n")
73 test.write('test02.F',   "This is a .F file.\n#fortran\n")
74 test.write('test03.for', "This is a .for file.\n#fortran\n")
75 test.write('test04.FOR', "This is a .FOR file.\n#fortran\n")
76 test.write('test05.ftn', "This is a .ftn file.\n#fortran\n")
77 test.write('test06.FTN', "This is a .FTN file.\n#fortran\n")
78 test.write('test07.fpp', "This is a .fpp file.\n#fortran\n")
79 test.write('test08.FPP', "This is a .FPP file.\n#fortran\n")
80 test.write('test09.f77', "This is a .f77 file.\n#g77\n")
81 test.write('test10.F77', "This is a .F77 file.\n#g77\n")
82
83 test.run(arguments = '.', stderr = None)
84
85 test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n")
86 test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n")
87 test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n")
88 test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n")
89 test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n")
90 test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n")
91 test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n")
92 test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n")
93 test.must_match(obj_ + 'test09' + _obj, "This is a .f77 file.\n")
94
95 fc  = 'f77'
96 f77 = test.detect_tool(fc)
97
98 if f77:
99
100     test.write("wrapper.py",
101 """import os
102 import string
103 import sys
104 open('%s', 'wb').write("wrapper.py\\n")
105 os.system(string.join(sys.argv[1:], " "))
106 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
107
108     test.write('SConstruct', """
109 foo = Environment(SHF77 = '%(fc)s')
110 shf77 = foo.Dictionary('SHF77')
111 bar = foo.Clone(SHF77 = r'%(_python_)s wrapper.py ' + shf77, tools = ['default', 'f77'], F77FILESUFFIXES = ['.f'])
112 foo.SharedObject(target = 'foo/foo', source = 'foo.f')
113 bar.SharedObject(target = 'bar/bar', source = 'bar.f')
114 """ % locals())
115
116     test.write('foo.f', r"""
117       PROGRAM FOO
118       PRINT *,'foo.f'
119       STOP
120       END
121 """)
122
123     test.write('bar.f', r"""
124       PROGRAM BAR
125       PRINT *,'bar.f'
126       STOP
127       END
128 """)
129
130
131     test.run(arguments = 'foo', stderr = None)
132
133     test.must_not_exist('wrapper.out')
134
135     import sys
136     if sys.platform[:5] == 'sunos':
137         test.run(arguments = 'bar', stderr = None)
138     else:
139         test.run(arguments = 'bar')
140
141     test.must_match('wrapper.out', "wrapper.py\n")
142
143 test.pass_test()