You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.7 KiB

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