Put the Copyright years in by script, not by hand.
[scons.git] / test / 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 if sys.platform == 'win32':
35     _obj = '.obj'
36 else:
37     _obj = '.os'
38
39 test = TestSCons.TestSCons()
40
41
42
43 test.write('myg77.py', r"""
44 import getopt
45 import sys
46 opts, args = getopt.getopt(sys.argv[1:], 'co:x')
47 optstring = ''
48 for opt, arg in opts:
49     if opt == '-o': out = arg
50     else: optstring = optstring + ' ' + opt
51 infile = open(args[0], 'rb')
52 outfile = open(out, 'wb')
53 outfile.write(optstring + "\n")
54 for l in infile.readlines():
55     if l[:4] != '#g77':
56         outfile.write(l)
57 sys.exit(0)
58 """)
59
60
61
62 test.write('SConstruct', """
63 env = Environment(LINK = r'%s mylink.py',
64                   SHF77 = r'%s myg77.py', SHF77FLAGS = '-x')
65 env.SharedObject(target = 'test1', source = 'test1.f')
66 env.SharedObject(target = 'test2', source = 'test2.for')
67 env.SharedObject(target = 'test3', source = 'test3.FOR')
68 env.SharedObject(target = 'test4', source = 'test4.F')
69 env.SharedObject(target = 'test5', source = 'test5.fpp')
70 env.SharedObject(target = 'test6', source = 'test6.FPP')
71 """ % (python, python))
72
73 test.write('test1.f', r"""This is a .f file.
74 #g77
75 """)
76
77 test.write('test2.for', r"""This is a .for file.
78 #g77
79 """)
80
81 test.write('test3.FOR', r"""This is a .FOR file.
82 #g77
83 """)
84
85 test.write('test4.F', r"""This is a .F file.
86 #g77
87 """)
88
89 test.write('test5.fpp', r"""This is a .fpp file.
90 #g77
91 """)
92
93 test.write('test6.FPP', r"""This is a .FPP file.
94 #g77
95 """)
96
97 test.run(arguments = '.', stderr = None)
98
99 test.fail_test(test.read('test1' + _obj) != " -x -c\nThis is a .f file.\n")
100
101 test.fail_test(test.read('test2' + _obj) != " -x -c\nThis is a .for file.\n")
102
103 test.fail_test(test.read('test3' + _obj) != " -x -c\nThis is a .FOR file.\n")
104
105 test.fail_test(test.read('test4' + _obj) != " -x -c\nThis is a .F file.\n")
106
107 test.fail_test(test.read('test5' + _obj) != " -x -c\nThis is a .fpp file.\n")
108
109 test.fail_test(test.read('test6' + _obj) != " -x -c\nThis is a .FPP file.\n")
110
111
112
113 g77 = test.where_is('g77')
114
115 if g77:
116
117     test.write("wrapper.py",
118 """import os
119 import string
120 import sys
121 open('%s', 'wb').write("wrapper.py\\n")
122 os.system(string.join(sys.argv[1:], " "))
123 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
124
125     test.write('SConstruct', """
126 foo = Environment(LIBS = 'g2c')
127 shf77 = foo.Dictionary('SHF77')
128 bar = foo.Copy(SHF77 = r'%s wrapper.py ' + shf77, SHF77FLAGS = '-Ix')
129 foo.SharedLibrary(target = 'foo/foo', source = 'foo.f')
130 bar.SharedLibrary(target = 'bar/bar', source = 'bar.f')
131 """ % python)
132
133     test.write('foo.f', r"""
134       PROGRAM FOO
135       PRINT *,'foo.f'
136       STOP
137       END
138 """)
139
140     test.write('bar.f', r"""
141       PROGRAM BAR
142       PRINT *,'bar.f'
143       STOP
144       END
145 """)
146
147
148     test.run(arguments = 'foo', stderr = None)
149
150     test.fail_test(os.path.exists(test.workpath('wrapper.out')))
151
152     test.run(arguments = 'bar')
153
154     test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
155
156 test.pass_test()