3 Tool-specific initialization for LLVM
8 # Copyright (c) 2009 VMware, Inc.
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:
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
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.
34 import distutils
.version
42 llvm_dir
= os
.environ
['LLVM']
44 # Do nothing -- use the system headers/libs
47 if not os
.path
.isdir(llvm_dir
):
48 raise SCons
.Errors
.InternalError
, "Specified LLVM directory not found"
53 llvm_subdir
= 'Release'
55 llvm_bin_dir
= os
.path
.join(llvm_dir
, llvm_subdir
, 'bin')
56 if not os
.path
.isdir(llvm_bin_dir
):
57 llvm_bin_dir
= os
.path
.join(llvm_dir
, 'bin')
58 if not os
.path
.isdir(llvm_bin_dir
):
59 raise SCons
.Errors
.InternalError
, "LLVM binary directory not found"
61 env
.PrependENVPath('PATH', llvm_bin_dir
)
63 if env
['platform'] == 'windows':
64 # XXX: There is no llvm-config on Windows, so assume a standard layout
68 # Try to determine the LLVM version from llvm/Config/config.h
69 llvm_config
= os
.path
.join(llvm_dir
, 'include/llvm/Config/config.h')
70 if not os
.path
.exists(llvm_config
):
71 print 'scons: could not find %s' % llvm_config
73 llvm_version_re
= re
.compile(r
'^#define PACKAGE_VERSION "([^"]*)"')
75 for line
in open(llvm_config
, 'rt'):
76 mo
= llvm_version_re
.match(line
)
78 llvm_version
= mo
.group(1)
79 llvm_version
= distutils
.version
.LooseVersion(llvm_version
)
81 if llvm_version
is None:
82 print 'scons: could not determine the LLVM version from %s' % llvm_config
85 if llvm_version
>= distutils
.version
.LooseVersion('2.7'):
86 print 'scons: Ignoring unsupported LLVM version %s' % llvm_version
87 print 'scons: See http://www.llvm.org/bugs/show_bug.cgi?id=6429'
90 env
.Prepend(CPPPATH
= [os
.path
.join(llvm_dir
, 'include')])
91 env
.AppendUnique(CPPDEFINES
= [
92 '__STDC_LIMIT_MACROS',
93 '__STDC_CONSTANT_MACROS',
96 env
.Prepend(LIBPATH
= [os
.path
.join(llvm_dir
, 'lib')])
97 if llvm_version
>= distutils
.version
.LooseVersion('2.7'):
100 'LLVMLinker', 'LLVMipo', 'LLVMInterpreter',
101 'LLVMInstrumentation', 'LLVMJIT', 'LLVMExecutionEngine',
102 'LLVMBitWriter', 'LLVMX86Disassembler', 'LLVMX86AsmParser',
103 'LLVMMCParser', 'LLVMX86AsmPrinter', 'LLVMX86CodeGen',
104 'LLVMSelectionDAG', 'LLVMX86Info', 'LLVMAsmPrinter',
105 'LLVMCodeGen', 'LLVMScalarOpts', 'LLVMInstCombine',
106 'LLVMTransformUtils', 'LLVMipa', 'LLVMAsmParser',
107 'LLVMArchive', 'LLVMBitReader', 'LLVMAnalysis', 'LLVMTarget',
108 'LLVMMC', 'LLVMCore', 'LLVMSupport', 'LLVMSystem',
113 'LLVMX86AsmParser', 'LLVMX86AsmPrinter', 'LLVMX86CodeGen',
114 'LLVMX86Info', 'LLVMLinker', 'LLVMipo', 'LLVMInterpreter',
115 'LLVMInstrumentation', 'LLVMJIT', 'LLVMExecutionEngine',
116 'LLVMDebugger', 'LLVMBitWriter', 'LLVMAsmParser',
117 'LLVMArchive', 'LLVMBitReader', 'LLVMSelectionDAG',
118 'LLVMAsmPrinter', 'LLVMCodeGen', 'LLVMScalarOpts',
119 'LLVMTransformUtils', 'LLVMipa', 'LLVMAnalysis',
120 'LLVMTarget', 'LLVMMC', 'LLVMCore', 'LLVMSupport',
128 # Some of the LLVM C headers use the inline keyword without
130 env
.Append(CPPDEFINES
= [('inline', '__inline')])
132 # LLVM libraries are static, build with /MT, and they
133 # automatically link agains LIBCMT. When we're doing a
134 # debug build we'll be linking against LIBCMTD, so disable
136 env
.Append(LINKFLAGS
= ['/nodefaultlib:LIBCMT'])
137 elif env
.Detect('llvm-config'):
138 llvm_version
= env
.backtick('llvm-config --version').rstrip()
139 llvm_version
= distutils
.version
.LooseVersion(llvm_version
)
141 if llvm_version
>= distutils
.version
.LooseVersion('2.7'):
142 print 'scons: Ignoring unsupported LLVM version %s' % llvm_version
143 print 'scons: See http://www.llvm.org/bugs/show_bug.cgi?id=6429'
147 env
.ParseConfig('llvm-config --cppflags')
148 env
.ParseConfig('llvm-config --libs jit interpreter nativecodegen bitwriter')
149 env
.ParseConfig('llvm-config --ldflags')
151 print 'llvm-config version %s failed' % llvm_version
153 env
['LINK'] = env
['CXX']
157 assert llvm_version
is not None
159 print 'scons: Found LLVM version %s' % llvm_version
160 env
['LLVM_VERSION'] = llvm_version
162 # Define HAVE_LLVM macro with the major/minor version number (e.g., 0x0206 for 2.6)
163 llvm_version_major
= int(llvm_version
.version
[0])
164 llvm_version_minor
= int(llvm_version
.version
[1])
165 llvm_version_hex
= '0x%02x%02x' % (llvm_version_major
, llvm_version_minor
)
166 env
.Prepend(CPPDEFINES
= [('HAVE_LLVM', llvm_version_hex
)])
171 # vim:set ts=4 sw=4 et: