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.

137 lines
4.5 KiB

6 years ago
  1. """SCons.Tool.javah
  2. Tool-specific initialization for javah.
  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/javah.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  30. import os.path
  31. import SCons.Action
  32. import SCons.Builder
  33. import SCons.Node.FS
  34. import SCons.Tool.javac
  35. import SCons.Util
  36. def emit_java_headers(target, source, env):
  37. """Create and return lists of Java stub header files that will
  38. be created from a set of class files.
  39. """
  40. class_suffix = env.get('JAVACLASSSUFFIX', '.class')
  41. classdir = env.get('JAVACLASSDIR')
  42. if not classdir:
  43. try:
  44. s = source[0]
  45. except IndexError:
  46. classdir = '.'
  47. else:
  48. try:
  49. classdir = s.attributes.java_classdir
  50. except AttributeError:
  51. classdir = '.'
  52. classdir = env.Dir(classdir).rdir()
  53. if str(classdir) == '.':
  54. c_ = None
  55. else:
  56. c_ = str(classdir) + os.sep
  57. slist = []
  58. for src in source:
  59. try:
  60. classname = src.attributes.java_classname
  61. except AttributeError:
  62. classname = str(src)
  63. if c_ and classname[:len(c_)] == c_:
  64. classname = classname[len(c_):]
  65. if class_suffix and classname[-len(class_suffix):] == class_suffix:
  66. classname = classname[:-len(class_suffix)]
  67. classname = SCons.Tool.javac.classname(classname)
  68. s = src.rfile()
  69. s.attributes.java_classname = classname
  70. slist.append(s)
  71. s = source[0].rfile()
  72. if not hasattr(s.attributes, 'java_classdir'):
  73. s.attributes.java_classdir = classdir
  74. if target[0].__class__ is SCons.Node.FS.File:
  75. tlist = target
  76. else:
  77. if not isinstance(target[0], SCons.Node.FS.Dir):
  78. target[0].__class__ = SCons.Node.FS.Dir
  79. target[0]._morph()
  80. tlist = []
  81. for s in source:
  82. fname = s.attributes.java_classname.replace('.', '_') + '.h'
  83. t = target[0].File(fname)
  84. t.attributes.java_lookupdir = target[0]
  85. tlist.append(t)
  86. return tlist, source
  87. def JavaHOutFlagGenerator(target, source, env, for_signature):
  88. try:
  89. t = target[0]
  90. except (AttributeError, IndexError, TypeError):
  91. t = target
  92. try:
  93. return '-d ' + str(t.attributes.java_lookupdir)
  94. except AttributeError:
  95. return '-o ' + str(t)
  96. def getJavaHClassPath(env,target, source, for_signature):
  97. path = "${SOURCE.attributes.java_classdir}"
  98. if 'JAVACLASSPATH' in env and env['JAVACLASSPATH']:
  99. path = SCons.Util.AppendPath(path, env['JAVACLASSPATH'])
  100. return "-classpath %s" % (path)
  101. def generate(env):
  102. """Add Builders and construction variables for javah to an Environment."""
  103. java_javah = SCons.Tool.CreateJavaHBuilder(env)
  104. java_javah.emitter = emit_java_headers
  105. env['_JAVAHOUTFLAG'] = JavaHOutFlagGenerator
  106. env['JAVAH'] = 'javah'
  107. env['JAVAHFLAGS'] = SCons.Util.CLVar('')
  108. env['_JAVAHCLASSPATH'] = getJavaHClassPath
  109. env['JAVAHCOM'] = '$JAVAH $JAVAHFLAGS $_JAVAHOUTFLAG $_JAVAHCLASSPATH ${SOURCES.attributes.java_classname}'
  110. env['JAVACLASSSUFFIX'] = '.class'
  111. def exists(env):
  112. return env.Detect('javah')
  113. # Local Variables:
  114. # tab-width:4
  115. # indent-tabs-mode:nil
  116. # End:
  117. # vim: set expandtab tabstop=4 shiftwidth=4: