Clone of mesa.
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. """llvm
  2. Tool-specific initialization for LLVM
  3. """
  4. #
  5. # Copyright (c) 2009 VMware, Inc.
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining
  8. # a copy of this software and associated documentation files (the
  9. # "Software"), to deal in the Software without restriction, including
  10. # without limitation the rights to use, copy, modify, merge, publish,
  11. # distribute, sublicense, and/or sell copies of the Software, and to
  12. # permit persons to whom the Software is furnished to do so, subject to
  13. # the following conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included
  16. # in all copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  19. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  20. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. #
  26. import os
  27. import os.path
  28. import sys
  29. import SCons.Errors
  30. import SCons.Util
  31. def generate(env):
  32. try:
  33. llvm_dir = os.environ['LLVM']
  34. except KeyError:
  35. # Do nothing -- use the system headers/libs
  36. llvm_dir = None
  37. else:
  38. if not os.path.isdir(llvm_dir):
  39. raise SCons.Errors.InternalError, "Specified LLVM directory not found"
  40. if env['debug']:
  41. llvm_subdir = 'Debug'
  42. else:
  43. llvm_subdir = 'Release'
  44. llvm_bin_dir = os.path.join(llvm_dir, llvm_subdir, 'bin')
  45. if not os.path.isdir(llvm_bin_dir):
  46. llvm_bin_dir = os.path.join(llvm_dir, 'bin')
  47. if not os.path.isdir(llvm_bin_dir):
  48. raise SCons.Errors.InternalError, "LLVM binary directory not found"
  49. env.PrependENVPath('PATH', llvm_bin_dir)
  50. if env['platform'] == 'windows':
  51. # XXX: There is no llvm-config on Windows, so assume a standard layout
  52. if llvm_dir is not None:
  53. env.Prepend(CPPPATH = [os.path.join(llvm_dir, 'include')])
  54. env.AppendUnique(CPPDEFINES = [
  55. '__STDC_LIMIT_MACROS',
  56. '__STDC_CONSTANT_MACROS',
  57. 'HAVE_STDINT_H',
  58. ])
  59. env.Prepend(LIBPATH = [os.path.join(llvm_dir, 'lib')])
  60. env.Prepend(LIBS = [
  61. 'LLVMX86AsmParser',
  62. 'LLVMX86AsmPrinter',
  63. 'LLVMX86CodeGen',
  64. 'LLVMX86Info',
  65. 'LLVMLinker',
  66. 'LLVMipo',
  67. 'LLVMInterpreter',
  68. 'LLVMInstrumentation',
  69. 'LLVMJIT',
  70. 'LLVMExecutionEngine',
  71. 'LLVMDebugger',
  72. 'LLVMBitWriter',
  73. 'LLVMAsmParser',
  74. 'LLVMArchive',
  75. 'LLVMBitReader',
  76. 'LLVMSelectionDAG',
  77. 'LLVMAsmPrinter',
  78. 'LLVMCodeGen',
  79. 'LLVMScalarOpts',
  80. 'LLVMTransformUtils',
  81. 'LLVMipa',
  82. 'LLVMAnalysis',
  83. 'LLVMTarget',
  84. 'LLVMMC',
  85. 'LLVMCore',
  86. 'LLVMSupport',
  87. 'LLVMSystem',
  88. 'imagehlp',
  89. 'psapi',
  90. ])
  91. if env['msvc']:
  92. # Some of the LLVM C headers use the inline keyword without
  93. # defining it.
  94. env.Append(CPPDEFINES = [('inline', '__inline')])
  95. if env['debug']:
  96. # LLVM libraries are static, build with /MT, and they
  97. # automatically link agains LIBCMT. When we're doing a
  98. # debug build we'll be linking against LIBCMTD, so disable
  99. # that.
  100. env.Append(LINKFLAGS = ['/nodefaultlib:LIBCMT'])
  101. env['LLVM_VERSION'] = '2.6'
  102. return
  103. elif env.Detect('llvm-config'):
  104. version = env.backtick('llvm-config --version').rstrip()
  105. try:
  106. env.ParseConfig('llvm-config --cppflags')
  107. env.ParseConfig('llvm-config --libs jit interpreter nativecodegen bitwriter')
  108. env.ParseConfig('llvm-config --ldflags')
  109. except OSError:
  110. print 'llvm-config version %s failed' % version
  111. else:
  112. if env['platform'] == 'windows':
  113. env.Append(LIBS = ['imagehlp', 'psapi'])
  114. env['LINK'] = env['CXX']
  115. env['LLVM_VERSION'] = version
  116. def exists(env):
  117. return True
  118. # vim:set ts=4 sw=4 et: