summarylogtreecommitdiffstats
path: root/lto.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'lto.sh.in')
-rw-r--r--lto.sh.in25
1 files changed, 20 insertions, 5 deletions
diff --git a/lto.sh.in b/lto.sh.in
index f22af90129b2..1bff9ebd50a2 100644
--- a/lto.sh.in
+++ b/lto.sh.in
@@ -10,14 +10,29 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/option.sh"
-build_options+=('lto')
+build_options+=('lto' 'lto-thin')
buildenv_functions+=('buildenv_lto')
buildenv_lto() {
- if check_buildoption "lto" "y" && [[ -f "$(gcc -print-search-dirs | grep install | awk '{print $2 "liblto_plugin.so"}')" ]]; then
- CFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN)"
- CXXFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN)"
- LDFLAGS+=" -fuse-linker-plugin"
+ if [ check_buildoption "lto" "y" || check_buildoption "lto-thin" "y" ] && \
+ [[ -f "$(gcc -print-search-dirs | grep install | awk '{print $2 "liblto_plugin.so"}')" ]]; then
+ [[ "$CC" == "clang" ]] && \
+ CFLAGS+=" -flto" || \
+ CFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN) -flto-partition=none -fno-fat-lto-objects"
+ [[ "$CXX" == "clang++" ]] && \
+ CXXFLAGS+=" -flto" || \
+ CXXFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN) -flto-partition=none -fno-fat-lto-objects"
+
+ if check_buildoption "lto-thin" "y"; then
+ [[ "$CC" == "clang" ]] && \
+ CFLAGS="${CFLAGS// -flto / -flto=thin }" || \
+ CFLAGS="${CFLAGS// -flto-partition=none / }"
+ [[ "$CXX" == "clang++" ]] && \
+ CXXFLAGS="${CXXFLAGS// -flto / -flto=thin }" || \
+ CXXFLAGS="${CXXFLAGS// -flto-partition=none / }"
+ fi
+
+ LDFLAGS+=" -fuse-linker-plugin $CFLAGS $CXXFLAGS"
LTOPLUGIN="$(gcc -print-search-dirs | grep install | awk '{print $2 "liblto_plugin.so"}')"
ARFLAGS+=" --plugin $LTOPLUGIN"
RANLIBFLAGS+=" --plugin $LTOPLUGIN"