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.

115 lines
4.3 KiB

6 years ago
  1. """SCons.Tool.PharLapCommon
  2. This module contains common code used by all Tools for the
  3. Phar Lap ETS tool chain. Right now, this is linkloc and
  4. 386asm.
  5. """
  6. #
  7. # Copyright (c) 2001 - 2017 The SCons Foundation
  8. #
  9. # Permission is hereby granted, free of charge, to any person obtaining
  10. # a copy of this software and associated documentation files (the
  11. # "Software"), to deal in the Software without restriction, including
  12. # without limitation the rights to use, copy, modify, merge, publish,
  13. # distribute, sublicense, and/or sell copies of the Software, and to
  14. # permit persons to whom the Software is furnished to do so, subject to
  15. # the following conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be included
  18. # in all copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  21. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  22. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. #
  28. __revision__ = "src/engine/SCons/Tool/PharLapCommon.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  29. import os
  30. import os.path
  31. import SCons.Errors
  32. import SCons.Util
  33. import re
  34. def getPharLapPath():
  35. """Reads the registry to find the installed path of the Phar Lap ETS
  36. development kit.
  37. Raises UserError if no installed version of Phar Lap can
  38. be found."""
  39. if not SCons.Util.can_read_reg:
  40. raise SCons.Errors.InternalError("No Windows registry module was found")
  41. try:
  42. k=SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
  43. 'SOFTWARE\\Pharlap\\ETS')
  44. val, type = SCons.Util.RegQueryValueEx(k, 'BaseDir')
  45. # The following is a hack...there is (not surprisingly)
  46. # an odd issue in the Phar Lap plug in that inserts
  47. # a bunch of junk data after the phar lap path in the
  48. # registry. We must trim it.
  49. idx=val.find('\0')
  50. if idx >= 0:
  51. val = val[:idx]
  52. return os.path.normpath(val)
  53. except SCons.Util.RegError:
  54. raise SCons.Errors.UserError("Cannot find Phar Lap ETS path in the registry. Is it installed properly?")
  55. REGEX_ETS_VER = re.compile(r'#define\s+ETS_VER\s+([0-9]+)')
  56. def getPharLapVersion():
  57. """Returns the version of the installed ETS Tool Suite as a
  58. decimal number. This version comes from the ETS_VER #define in
  59. the embkern.h header. For example, '#define ETS_VER 1010' (which
  60. is what Phar Lap 10.1 defines) would cause this method to return
  61. 1010. Phar Lap 9.1 does not have such a #define, but this method
  62. will return 910 as a default.
  63. Raises UserError if no installed version of Phar Lap can
  64. be found."""
  65. include_path = os.path.join(getPharLapPath(), os.path.normpath("include/embkern.h"))
  66. if not os.path.exists(include_path):
  67. raise SCons.Errors.UserError("Cannot find embkern.h in ETS include directory.\nIs Phar Lap ETS installed properly?")
  68. mo = REGEX_ETS_VER.search(open(include_path, 'r').read())
  69. if mo:
  70. return int(mo.group(1))
  71. # Default return for Phar Lap 9.1
  72. return 910
  73. def addPharLapPaths(env):
  74. """This function adds the path to the Phar Lap binaries, includes,
  75. and libraries, if they are not already there."""
  76. ph_path = getPharLapPath()
  77. try:
  78. env_dict = env['ENV']
  79. except KeyError:
  80. env_dict = {}
  81. env['ENV'] = env_dict
  82. SCons.Util.AddPathIfNotExists(env_dict, 'PATH',
  83. os.path.join(ph_path, 'bin'))
  84. SCons.Util.AddPathIfNotExists(env_dict, 'INCLUDE',
  85. os.path.join(ph_path, 'include'))
  86. SCons.Util.AddPathIfNotExists(env_dict, 'LIB',
  87. os.path.join(ph_path, 'lib'))
  88. SCons.Util.AddPathIfNotExists(env_dict, 'LIB',
  89. os.path.join(ph_path, os.path.normpath('lib/vclib')))
  90. env['PHARLAP_PATH'] = getPharLapPath()
  91. env['PHARLAP_VERSION'] = str(getPharLapVersion())
  92. # Local Variables:
  93. # tab-width:4
  94. # indent-tabs-mode:nil
  95. # End:
  96. # vim: set expandtab tabstop=4 shiftwidth=4: