diff --git a/alloy.py b/alloy.py index 7f2dee07..13d38660 100755 --- a/alloy.py +++ b/alloy.py @@ -1,6 +1,6 @@ #!/usr/bin/python # -# Copyright (c) 2013, Intel Corporation +# Copyright (c) 2013-2014, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -93,7 +93,7 @@ def try_do_LLVM(text, command, from_validation): error("can't " + text, 1) print_debug("DONE.\n", from_validation, alloy_build) -def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, from_validation, force, make): +def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, from_validation, force, make, gcc_toolchain_path): print_debug("Building LLVM. Version: " + version_LLVM + ". ", from_validation, alloy_build) if revision != "": print_debug("Revision: " + revision + ".\n", from_validation, alloy_build) @@ -138,6 +138,21 @@ def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, common.remove_if_exists(LLVM_SRC) common.remove_if_exists(LLVM_BUILD) common.remove_if_exists(LLVM_BIN) + + # Starting with MacOS 10.9 Maverics, we depend on XCode being installed, as it contains C and C++ library headers. + # sysroot trick below helps finding C headers. For C++ we just check out libc++ sources. + mac_system_root = "" + if current_OS == "MacOS" and int(current_OS_version.split(".")[0]) >= 13: + search_path = string.split(os.environ["PATH"], os.pathsep) + found_xcrun = False + for path in search_path: + if os.path.exists(os.path.join(path, "xcrun")): + found_xcrun = True + if found_xcrun: + mac_system_root = " --with-default-sysroot=`xcrun --show-sdk-path`" + else: + error("Can't find XCode (xcrun tool) - it's required on MacOS 10.9 and newer", 1) + if selfbuild: common.remove_if_exists(LLVM_BUILD_selfbuild) common.remove_if_exists(LLVM_BIN_selfbuild) @@ -210,7 +225,10 @@ def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, os.chdir(LLVM_BUILD_selfbuild) try_do_LLVM("configure release version for selfbuild ", "../" + LLVM_SRC + "/configure --prefix=" + llvm_home + "/" + - LLVM_BIN_selfbuild + " --enable-optimized", + LLVM_BIN_selfbuild + " --enable-optimized" + + " --enable-targets=x86,x86_64" + + ((" --with-gcc-toolchain=" + gcc_toolchain_path) if gcc_toolchain_path != "" else "") + + mac_system_root, from_validation) try_do_LLVM("build release version for selfbuild ", make, from_validation) @@ -225,7 +243,10 @@ def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, if current_OS != "Windows": try_do_LLVM("configure release version ", "../" + LLVM_SRC + "/configure --prefix=" + llvm_home + "/" + - LLVM_BIN + " --enable-optimized" + selfbuild_compiler, + LLVM_BIN + " --enable-optimized" + selfbuild_compiler + + " --enable-targets=x86,x86_64" + + ((" --with-gcc-toolchain=" + gcc_toolchain_path) if gcc_toolchain_path != "" else "") + + mac_system_root, from_validation) else: try_do_LLVM("configure release version ", @@ -235,7 +256,10 @@ def build_LLVM(version_LLVM, revision, folder, tarball, debug, selfbuild, extra, else: try_do_LLVM("configure debug version ", "../" + LLVM_SRC + "/configure --prefix=" + llvm_home + "/" + LLVM_BIN + - " --enable-debug-runtime --enable-debug-symbols --enable-keep-symbols" + selfbuild_compiler, + " --enable-debug-runtime --enable-debug-symbols --enable-keep-symbols" + selfbuild_compiler + + " --enable-targets=x86,x86_64" + + ((" --with-gcc-toolchain=" + gcc_toolchain_path) if gcc_toolchain_path != "" else "") + + mac_system_root, from_validation) # building llvm if current_OS != "Windows": @@ -553,7 +577,7 @@ def validation_run(only, only_targets, reference_branch, number, notify, update, knc_archs = ["x86-64"] need_LLVM = check_LLVM(LLVM) for i in range(0,len(need_LLVM)): - build_LLVM(need_LLVM[i], "", "", "", False, False, False, True, False, make) + build_LLVM(need_LLVM[i], "", "", "", False, False, False, True, False, make, options.gcc_toolchain_path) # begin validation run for stabitily common.remove_if_exists(stability.in_file) R = [[[],[]],[[],[]],[[],[]],[[],[]]] @@ -636,7 +660,7 @@ def validation_run(only, only_targets, reference_branch, number, notify, update, # prepare newest LLVM need_LLVM = check_LLVM([newest_LLVM]) if len(need_LLVM) != 0: - build_LLVM(need_LLVM[0], "", "", "", False, False, False, True, False, make) + build_LLVM(need_LLVM[0], "", "", "", False, False, False, True, False, make, options.gcc_toolchain_path) if perf_llvm == False: # prepare reference point. build both test and reference compilers try_do_LLVM("apply git", "git branch", True) @@ -780,7 +804,7 @@ def Main(): start_time = time.time() if options.build_llvm: build_LLVM(options.version, options.revision, options.folder, options.tarball, - options.debug, options.selfbuild, options.extra, False, options.force, make) + options.debug, options.selfbuild, options.extra, False, options.force, make, options.gcc_toolchain_path) if options.validation_run: validation_run(options.only, options.only_targets, options.branch, options.number_for_performance, options.notify, options.update, int(options.speed), @@ -860,6 +884,10 @@ if __name__ == '__main__': "These options must be used with -b option.") llvm_group.add_option('--version', dest='version', help='version of llvm to build: 3.2 3.3 3.4 3.5 trunk. Default: trunk', default="trunk") + llvm_group.add_option('--with-gcc-toolchain', dest='gcc_toolchain_path', + help='GCC install dir to use when building clang. It is important to set when ' + + 'you have alternative gcc installation. Note that otherwise gcc from standard ' + + 'location will be used, not from your PATH', default="") llvm_group.add_option('--revision', dest='revision', help='revision of llvm to build in format r172870', default="") llvm_group.add_option('--debug', dest='debug',