From f26a1cab799e6a0cbb36c1db00eed095f83c4cf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Fri, 7 Feb 2020 11:01:38 +0100 Subject: [PATCH] Extract detecting CC/CXX into helper script so we can use it from mono.proj (#31854) * Fix typo in gen-buildsys.sh compier -> compiler * Extract detecting CC/CXX into helper script so we can use it from mono.proj * Rename detect-compiler.sh to init-compiler.sh --- eng/native/gen-buildsys.sh | 86 +----------------------------------- eng/native/init-compiler.sh | 105 ++++++++++++++++++++++++++++++++++++++++++++ src/mono/mono.proj | 4 +- 3 files changed, 109 insertions(+), 86 deletions(-) create mode 100755 eng/native/init-compiler.sh diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index ae2e0eb..4171d13 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -25,98 +25,16 @@ fi tryrun_dir="$2" build_arch="$4" compiler="$5" -cxxCompiler="$compiler++" majorVersion="$6" minorVersion="$7" -if [[ "$compiler" == "gcc" ]]; then cxxCompiler="g++"; fi - -check_version_exists() { - desired_version=-1 - - # Set up the environment to be used for building with the desired compiler. - if command -v "$compiler-$1.$2" > /dev/null; then - desired_version="-$1.$2" - elif command -v "$compier$1$2" > /dev/null; then - desired_version="$1$2" - elif command -v "$compiler-$1$2" > /dev/null; then - desired_version="-$1$2" - fi - - echo "$desired_version" -} - -if [[ -z "$CLR_CC" ]]; then - - # Set default versions - if [[ -z "$majorVersion" ]]; then - # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. - if [[ "$compiler" == "clang" ]]; then versions=( 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) - elif [[ "$compiler" == "gcc" ]]; then versions=( 9 8 7 6 5 4.9 ); fi - - for version in "${versions[@]}"; do - parts=(${version//./ }) - desired_version="$(check_version_exists "${parts[0]}" "${parts[1]}")" - if [[ "$desired_version" != "-1" ]]; then majorVersion="${parts[0]}"; break; fi - done - - if [[ -z "$majorVersion" ]]; then - if command -v "$compiler" > /dev/null; then - if [[ "$(uname)" != "Darwin" ]]; then - echo "WARN: Specific version of $compiler not found, falling back to use the one in PATH." - fi - CC="$(command -v "$compiler")" - CXX="$(command -v "$cxxCompiler")" - else - echo "ERROR: No usable version of $compiler found." - exit 1 - fi - else - if [[ "$compiler" == "clang" && "$majorVersion" -lt 5 ]]; then - if [[ "$build_arch" == "arm" || "$build_arch" == "armel" ]]; then - if command -v "$compiler" > /dev/null; then - echo "WARN: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH." - CC="$(command -v "$compiler")" - CXX="$(command -v "$cxxCompiler")" - else - echo "ERROR: Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH." - exit 1 - fi - fi - fi - fi - else - desired_version="$(check_version_exists "$majorVersion" "$minorVersion")" - if [[ "$desired_version" == "-1" ]]; then - echo "ERROR: Could not find specific version of $compiler: $majorVersion $minorVersion." - exit 1 - fi - fi - - if [[ -z "$CC" ]]; then - CC="$(command -v "$compiler$desired_version")" - CXX="$(command -v "$cxxCompiler$desired_version")" - if [[ -z "$CXX" ]]; then CXX="$(command -v "$cxxCompiler")"; fi - fi -else - if [[ ! -f "$CLR_CC" ]]; then - echo "ERROR: CLR_CC is set but path '$CLR_CC' does not exist" - exit 1 - fi - CC="$CLR_CC" - CXX="$CLR_CXX" -fi - -if [[ -z "$CC" ]]; then - echo "ERROR: Unable to find $compiler." - exit 1 -fi +source "$scriptroot/init-compiler.sh" "$build_arch" "$compiler" "$majorVersion" "$minorVersion" CCC_CC="$CC" CCC_CXX="$CXX" SCAN_BUILD_COMMAND="$(command -v "scan-build$desired_version")" -export CC CCC_CC CXX CCC_CXX SCAN_BUILD_COMMAND +export CCC_CC CCC_CXX SCAN_BUILD_COMMAND buildtype=DEBUG code_coverage=OFF diff --git a/eng/native/init-compiler.sh b/eng/native/init-compiler.sh new file mode 100755 index 0000000..72aa558 --- /dev/null +++ b/eng/native/init-compiler.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash +# +# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables +# + +if [[ "$#" -lt 2 ]]; then + echo "Usage..." + echo "detect-compiler.sh " + echo "Specify the target architecture." + echo "Specify the name of compiler (clang or gcc)." + echo "Specify the major version of compiler." + echo "Specify the minor version of compiler." + exit 1 +fi + +build_arch="$1" +compiler="$2" +cxxCompiler="$compiler++" +majorVersion="$3" +minorVersion="$4" + +if [[ "$compiler" == "gcc" ]]; then cxxCompiler="g++"; fi + +check_version_exists() { + desired_version=-1 + + # Set up the environment to be used for building with the desired compiler. + if command -v "$compiler-$1.$2" > /dev/null; then + desired_version="-$1.$2" + elif command -v "$compiler$1$2" > /dev/null; then + desired_version="$1$2" + elif command -v "$compiler-$1$2" > /dev/null; then + desired_version="-$1$2" + fi + + echo "$desired_version" +} + +if [[ -z "$CLR_CC" ]]; then + + # Set default versions + if [[ -z "$majorVersion" ]]; then + # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. + if [[ "$compiler" == "clang" ]]; then versions=( 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) + elif [[ "$compiler" == "gcc" ]]; then versions=( 9 8 7 6 5 4.9 ); fi + + for version in "${versions[@]}"; do + parts=(${version//./ }) + desired_version="$(check_version_exists "${parts[0]}" "${parts[1]}")" + if [[ "$desired_version" != "-1" ]]; then majorVersion="${parts[0]}"; break; fi + done + + if [[ -z "$majorVersion" ]]; then + if command -v "$compiler" > /dev/null; then + if [[ "$(uname)" != "Darwin" ]]; then + echo "WARN: Specific version of $compiler not found, falling back to use the one in PATH." + fi + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" + else + echo "ERROR: No usable version of $compiler found." + exit 1 + fi + else + if [[ "$compiler" == "clang" && "$majorVersion" -lt 5 ]]; then + if [[ "$build_arch" == "arm" || "$build_arch" == "armel" ]]; then + if command -v "$compiler" > /dev/null; then + echo "WARN: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH." + CC="$(command -v "$compiler")" + CXX="$(command -v "$cxxCompiler")" + else + echo "ERROR: Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH." + exit 1 + fi + fi + fi + fi + else + desired_version="$(check_version_exists "$majorVersion" "$minorVersion")" + if [[ "$desired_version" == "-1" ]]; then + echo "ERROR: Could not find specific version of $compiler: $majorVersion $minorVersion." + exit 1 + fi + fi + + if [[ -z "$CC" ]]; then + CC="$(command -v "$compiler$desired_version")" + CXX="$(command -v "$cxxCompiler$desired_version")" + if [[ -z "$CXX" ]]; then CXX="$(command -v "$cxxCompiler")"; fi + fi +else + if [[ ! -f "$CLR_CC" ]]; then + echo "ERROR: CLR_CC is set but path '$CLR_CC' does not exist" + exit 1 + fi + CC="$CLR_CC" + CXX="$CLR_CXX" +fi + +if [[ -z "$CC" ]]; then + echo "ERROR: Unable to find $compiler." + exit 1 +fi + +export CC CXX diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 32b1c10..16e1006 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -33,13 +33,13 @@ <_MonoConfigureParams Condition="$(MonoEnableLLVM) == true">$(_MonoConfigureParams) --enable--llvm - <_MonoConfigureParams>$(_MonoConfigureParams) --with-core=only CC=clang CXX=clang++ CFLAGS="$(_MonoExtraCFLAGS)" CXXFLAGS="$(_MonoExtraCXXFLAGS)" + <_MonoConfigureParams>$(_MonoConfigureParams) --enable-maintainer-mode --enable-compile-warnings --with-core=only CFLAGS="$(_MonoExtraCFLAGS)" CXXFLAGS="$(_MonoExtraCXXFLAGS)" - + -- 2.7.4