diff --git a/clang/docs/ClangCommandLineReference.rst b/clang/docs/ClangCommandLineReference.rst --- a/clang/docs/ClangCommandLineReference.rst +++ b/clang/docs/ClangCommandLineReference.rst @@ -18,9 +18,9 @@ .. program:: clang -.. option:: -B, --prefix , --prefix= +.. option:: -B, --prefix , --prefix= -Add to search path for binaries and object files used implicitly +Search $prefix/$triple-$file and $prefix$file for executables, libraries, includes, and data files used by the compiler. If $prefix is a directory, the directory is used to search for GCC installation on targets which commonly use GCC. The directory usually contains 'include' and 'lib'. Note: sysroot is also used to search for GCC installation and the largest version wins. Specify --gcc-toolchain to suppress sysroot. If $prefix is not a directory, the GCC installation detection is skipped but $prefix can still be used to find executables, typically for -nostdinc -nostdlib compiles .. option:: -F @@ -256,7 +256,7 @@ .. option:: --gcc-toolchain=, -gcc-toolchain -Use the gcc toolchain at the given directory +Search for GCC installation in the specified directory, similar to -B. The directory usually contains 'lib' and 'include'. If specified, sysroot is skipped for GCC detection. Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation .. option:: -gcodeview diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -599,8 +599,20 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>, Flags<[NoXarchOption, CoreOption]>; def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>, Group; -def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"">, - HelpText<"Add to search path for binaries and object files used implicitly">; +def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"">, + HelpText<"Search $prefix/$triple-$file and $prefix$file for executables, libraries, " + "includes, and data files used by the compiler. If $prefix is a directory, the " + "directory is used to search for GCC installation on targets which commonly use GCC. " + "The directory usually contains 'include' and 'lib'. Note: sysroot is also used to " + "search for GCC installation and the largest version wins. Specify --gcc-toolchain " + "to suppress sysroot. If $prefix is not a directory, the GCC installation detection " + "is skipped but $prefix can still be used to find executables, typically for -nostdinc " + "-nostdlib compiles">; +def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, + HelpText<"Search for GCC installation in the specified directory, similar to -B. " + "The directory usually contains 'lib' and 'include'. If specified, sysroot is skipped " + "for GCC detection. Note: executables (e.g. ld) used by the compiler are not overridden " + "by the selected GCC installation">; def CC : Flag<["-"], "CC">, Flags<[CC1Option]>, Group, HelpText<"Include comments from within macros in preprocessed output">, MarshallingInfoFlag>; @@ -3666,8 +3678,6 @@ MarshallingInfoFlag>; def mcpu_EQ_QUESTION : Flag<["-"], "mcpu=?">, Alias; def mtune_EQ_QUESTION : Flag<["-"], "mtune=?">, Alias; -def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>, - HelpText<"Use the gcc toolchain at the given directory">; def time : Flag<["-"], "time">, HelpText<"Time individual commands">; def traditional_cpp : Flag<["-", "--"], "traditional-cpp">, Flags<[CC1Option]>, diff --git a/clang/test/Driver/gcc-toolchain.cpp b/clang/test/Driver/gcc-toolchain.cpp --- a/clang/test/Driver/gcc-toolchain.cpp +++ b/clang/test/Driver/gcc-toolchain.cpp @@ -29,3 +29,23 @@ // CHECK: "{{[^"]*}}/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5{{/|\\\\}}crtbegin.o" // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5" // CHECK: "-L[[TOOLCHAIN]]/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/../../../.." +// +// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \ +// RUN: --target=x86_64-linux-gnu -stdlib=libstdc++ \ +// RUN: --gcc-toolchain=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \ +// RUN: --sysroot= | FileCheck %s --check-prefix=UBUNTU13 + +/// If both --prefix and --gcc-toolchain are specified, the GCC installation with a larger version wins. +// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \ +// RUN: --target=i386-unknown-linux -stdlib=libstdc++ \ +// RUN: --prefix=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \ +// RUN: --gcc-toolchain=%S/Inputs/ubuntu_11.04_multiarch_tree/usr \ +// RUN: --sysroot= | FileCheck %s --check-prefix=UBUNTU13 + +// RUN: %clangxx -no-canonical-prefixes %s -### -o %t 2>&1 \ +// RUN: --target=i386-unknown-linux -stdlib=libstdc++ \ +// RUN: --prefix=%S/Inputs/ubuntu_11.04_multiarch_tree/usr \ +// RUN: --gcc-toolchain=%S/Inputs/ubuntu_13.04_multiarch_tree/usr \ +// RUN: --sysroot= | FileCheck %s --check-prefix=UBUNTU13 + +// UBUNTU13: {{.*}}/ubuntu_13.04_multiarch_tree/usr/lib/gcc/x86_64-linux-gnu/4.7