buildflags.md: Move toolchain selection documentation from macros file

This commit is contained in:
Florian Weimer 2021-11-15 15:34:15 +01:00
parent ac57cc99aa
commit a9123ea1ac
2 changed files with 27 additions and 23 deletions

View File

@ -75,6 +75,33 @@ It is possible to set RPM macros to change some aspects of the
compiler flags. Changing these flags should be used as a last compiler flags. Changing these flags should be used as a last
recourse if other workarounds are not available. recourse if other workarounds are not available.
### Toolchain selection
The default toolchain uses GCC, and the `%toolchain` macro is defined
as `gcc`.
It is enough to override `toolchain` macro and all relevant macro for C/C++
compilers will be switched. Either in the spec or in the command-line.
%global toolchain clang
or:
rpmbuild -D "toolchain clang" …
Inside a spec file it is also possible to determine which toolchain is in use
by testing the same macro. For example:
%if "%{toolchain}" == "gcc"
BuildRequires: gcc
%endif
or:
%if "%{toolchain}" == "clang"
BuildRequires: clang compiler-rt
%endif
### Lazy binding ### Lazy binding
If your package depends on the semantics of lazy binding (e.g., it has If your package depends on the semantics of lazy binding (e.g., it has

23
macros
View File

@ -37,29 +37,6 @@
%__cpp_clang clang-cpp %__cpp_clang clang-cpp
# Default to the GCC toolchain # Default to the GCC toolchain
#
# It is enough to override `toolchain` macro and all relevant macro for C/C++
# compilers will be switched. Either in the spec or in the command-line.
#
# %global toolchain clang
#
# or:
#
# rpmbuild -D "toolchain clang" …
#
# Inside a spec file it is also possible to determine which toolchain is in use
# by testing the same macro. For example:
#
# %if "%{toolchain}" == "gcc"
# BuildRequires: gcc
# %endif
#
# or:
#
# %if "%{toolchain}" == "clang"
# BuildRequires: clang compiler-rt
# %endif
#
%toolchain gcc %toolchain gcc
%__cc %{expand:%%{__cc_%{toolchain}}} %__cc %{expand:%%{__cc_%{toolchain}}}