On 19/03/16 04:35, Que Quotion wrote:
This orignates from a utility I put together: https://bbs.archlinux.org/viewtopic.php?pid=1451263#p1451263
The script streamlines enabling some build options that makepkg does not yet offer, such as link-time optimization and profile-guided optimization.
The above script works, but has limitations in that it is a wrapper script. I propose adding these as build options in makepkg itself. Most packages compile safely with both or either option and the benefits are enormous (especially with PGO).
Here are the changes I propose to makepkg, for which I am open to suggestions and hope someone other than myself will test:
--- /usr/bin/makepkg 2016-02-26 14:07:15.000000000 +0900 +++ ./makepkg.qq 2016-03-19 03:13:09.535977092 +0900 @@ -48,7 +48,7 @@
LIBRARY=${LIBRARY:-'/usr/share/makepkg'}
-build_options=('ccache' 'distcc' 'buildflags' 'makeflags') +build_options=('ccache' 'distcc' 'buildflags' 'makeflags' 'pgo' 'lto') splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends' 'optdepends' 'provides' 'conflicts' 'replaces' 'backup' 'options' 'install' 'changelog') @@ -866,6 +866,32 @@ export DISTCC_HOSTS fi
+ + # Use lto if it is requested (check buildenv and PKGBUILD opts) + 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+=" $CFLAGS -fuse-linker-plugin" + LTOPLUGIN="$(gcc -print-search-dirs | grep install | awk '{print $2 "liblto_plugin.so"}')" + ARFLAGS+=" --plugin $LTOPLUGIN" + RANLIBFLAGS+=" --plugin $LTOPLUGIN" + NMFLAGS+=" --plugin $LTOPLUGIN" + fi +
What is the advantage to all this beyond people adding "-flto" to their CFLAGS if they want LTO? All modern builds should handle the rest by themselves.
+ # Generate or utilize pgo if it is requested (check buildenv and PKGBUILD opts) + if check_buildoption "pgo" "y"; then + if [ ! -d "$PROFDEST/$pkgbase.gen" ]; then + mkdir "$PROFDEST/$pkgbase.gen" + CFLAGS+="-fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen" + CXXFLAGS+="-fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen" + LDFLAGS+="-lgcov" + elif [ ! -d "$PROFDEST/$pkgbase.used" ]; then + mv "$PROFDEST/$pkgbase.gen" "$PROFDEST/$pkgbase.used" + CFLAGS+="-fprofile-correction -fprofile-use -fprofile-dir=$PROFDEST/$pkgbase.used" + CXXFLAGS+="-fprofile-correction -fprofile-use -fprofile-dir=$PROFDEST/$pkgbase.used" + fi + fi +
I'm guessing this is untested... Anyway, I don't think PGO has a place in makepkg itself and should stay in a wrapper script. A