Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / SCons / Tool / suncxx.py
blobac0b0c75f66c47f0d154b7c9fe5c3902b89c6810
1 """SCons.Tool.sunc++
3 Tool-specific initialization for C++ on SunOS / Solaris.
5 There normally shouldn't be any need to import this module directly.
6 It will usually be imported through the generic SCons.Tool.Tool()
7 selection method.
9 """
12 # __COPYRIGHT__
14 # Permission is hereby granted, free of charge, to any person obtaining
15 # a copy of this software and associated documentation files (the
16 # "Software"), to deal in the Software without restriction, including
17 # without limitation the rights to use, copy, modify, merge, publish,
18 # distribute, sublicense, and/or sell copies of the Software, and to
19 # permit persons to whom the Software is furnished to do so, subject to
20 # the following conditions:
22 # The above copyright notice and this permission notice shall be included
23 # in all copies or substantial portions of the Software.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
36 import SCons
38 import os
39 import re
40 import subprocess
42 import SCons.Tool.cxx
43 cplusplus = SCons.Tool.cxx
44 # cplusplus = __import__('c++', globals(), locals(), [])
46 package_info = {}
49 def get_package_info(package_name, pkginfo, pkgchk):
50 try:
51 return package_info[package_name]
52 except KeyError:
53 version = None
54 pathname = None
55 from subprocess import DEVNULL
57 try:
58 with open('/var/sadm/install/contents', encoding='UTF-8') as f:
59 sadm_contents = f.read()
60 except OSError:
61 pass
62 else:
63 sadm_re = re.compile(r'^(\S*/bin/CC)(=\S*)? %s$' % package_name, re.M)
64 sadm_match = sadm_re.search(sadm_contents)
65 if sadm_match:
66 pathname = os.path.dirname(sadm_match.group(1))
68 try:
69 p = subprocess.Popen([pkginfo, '-l', package_name],
70 universal_newlines=True,
71 stdout=subprocess.PIPE,
72 stderr=DEVNULL)
73 except OSError:
74 pass
75 else:
76 pkginfo_contents = p.communicate()[0]
77 version_re = re.compile(r'^ *VERSION:\s*(.*)$', re.M)
78 version_match = version_re.search(pkginfo_contents)
79 if version_match:
80 version = version_match.group(1)
82 if pathname is None:
83 try:
84 p = subprocess.Popen([pkgchk, '-l', package_name],
85 universal_newlines=True,
86 stdout=subprocess.PIPE,
87 stderr=DEVNULL)
88 except OSError:
89 pass
90 else:
91 pkgchk_contents = p.communicate()[0]
92 pathname_re = re.compile(r'^Pathname:\s*(.*/bin/CC)$', re.M)
93 pathname_match = pathname_re.search(pkgchk_contents)
94 if pathname_match:
95 pathname = os.path.dirname(pathname_match.group(1))
97 package_info[package_name] = (pathname, version)
98 return package_info[package_name]
101 # use the package installer tool "pkg" to figure out where cppc and what
102 # version of it is installed
103 def get_cppc(env):
104 cxx = env.subst('$CXX')
105 if cxx:
106 cppcPath = os.path.dirname(cxx)
107 else:
108 cppcPath = None
110 cppcVersion = None
112 pkginfo = env.subst('$PKGINFO')
113 pkgchk = env.subst('$PKGCHK')
115 for package in ['SPROcpl']:
116 path, version = get_package_info(package, pkginfo, pkgchk)
117 if path and version:
118 cppcPath, cppcVersion = path, version
119 break
121 return (cppcPath, 'CC', 'CC', cppcVersion)
124 def generate(env) -> None:
125 """Add Builders and construction variables for SunPRO C++."""
126 path, cxx, shcxx, version = get_cppc(env)
127 if path:
128 cxx = os.path.join(path, cxx)
129 shcxx = os.path.join(path, shcxx)
131 cplusplus.generate(env)
133 env['CXX'] = cxx
134 env['SHCXX'] = shcxx
135 env['CXXVERSION'] = version
136 env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS -KPIC')
137 env['SHOBJPREFIX'] = 'so_'
138 env['SHOBJSUFFIX'] = '.o'
141 def exists(env):
142 path, cxx, shcxx, version = get_cppc(env)
143 if path and cxx:
144 cppc = os.path.join(path, cxx)
145 if os.path.exists(cppc):
146 return cppc
147 return None
149 # Local Variables:
150 # tab-width:4
151 # indent-tabs-mode:nil
152 # End:
153 # vim: set expandtab tabstop=4 shiftwidth=4: