2014-10-16 22:48:02 +00:00
|
|
|
import os
|
|
|
|
import pipes
|
|
|
|
import shlex
|
2014-10-16 23:43:20 +00:00
|
|
|
import sys
|
2014-10-16 22:48:02 +00:00
|
|
|
|
|
|
|
if not 'go' in config.root.llvm_bindings:
|
|
|
|
config.unsupported = True
|
|
|
|
|
2014-10-16 23:43:20 +00:00
|
|
|
def find_executable(executable, path=None):
|
|
|
|
if path is None:
|
|
|
|
path = os.environ['PATH']
|
|
|
|
paths = path.split(os.pathsep)
|
|
|
|
base, ext = os.path.splitext(executable)
|
|
|
|
|
|
|
|
if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
|
|
|
|
executable = executable + '.exe'
|
|
|
|
|
|
|
|
if not os.path.isfile(executable):
|
|
|
|
for p in paths:
|
|
|
|
f = os.path.join(p, executable)
|
|
|
|
if os.path.isfile(f):
|
|
|
|
return f
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return executable
|
|
|
|
|
2014-10-16 22:48:02 +00:00
|
|
|
# Resolve certain symlinks in the first word of compiler.
|
|
|
|
#
|
|
|
|
# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the
|
|
|
|
# substring 'clang' to determine if the compiler is Clang. This won't work if
|
|
|
|
# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin.
|
2014-10-17 18:32:36 +00:00
|
|
|
#
|
|
|
|
# Go tools also have problems with ccache, so we disable it.
|
2014-10-16 22:48:02 +00:00
|
|
|
def fixup_compiler_path(compiler):
|
|
|
|
args = shlex.split(compiler)
|
2014-10-17 18:32:36 +00:00
|
|
|
if args[0].endswith('ccache'):
|
|
|
|
args = args[1:]
|
|
|
|
|
2014-10-16 23:43:20 +00:00
|
|
|
path = find_executable(args[0])
|
2014-10-16 22:48:02 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
if path.endswith('/cc') and os.readlink(path) == 'clang':
|
|
|
|
args[0] = path[:len(path)-2] + 'clang'
|
2014-10-17 17:46:46 +00:00
|
|
|
except (AttributeError, OSError):
|
2014-10-17 16:07:43 +00:00
|
|
|
pass
|
2014-10-16 22:48:02 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
if path.endswith('/c++') and os.readlink(path) == 'clang++':
|
|
|
|
args[0] = path[:len(path)-3] + 'clang++'
|
2014-10-17 17:46:46 +00:00
|
|
|
except (AttributeError, OSError):
|
2014-10-17 16:07:43 +00:00
|
|
|
pass
|
2014-10-16 22:48:02 +00:00
|
|
|
|
|
|
|
return ' '.join([pipes.quote(arg) for arg in args])
|
|
|
|
|
|
|
|
config.environment['CC'] = fixup_compiler_path(config.host_cc)
|
|
|
|
config.environment['CXX'] = fixup_compiler_path(config.host_cxx)
|
2014-10-21 00:36:28 +00:00
|
|
|
config.environment['CGO_LDFLAGS'] = config.host_ldflags
|