#!/usr/bin/bash # # lto.sh - Compile with link-time optimization # [[ -n "$LIBMAKEPKG_BUILDENV_LTO_SH" ]] && return LIBMAKEPKG_BUILDENV_LTO_SH=1 LIBRARY=${LIBRARY:-'@libmakepkgdir@'} source "$LIBRARY/util/option.sh" build_options+=('lto' 'lto-thin') buildenv_functions+=('buildenv_lto') buildenv_lto() { 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" NMFLAGS+=" --plugin $LTOPLUGIN" fi }