InBetweenNames / gentooLTO

A Gentoo Portage configuration for building with -O3, Graphite, and LTO optimizations
GNU General Public License v2.0
570 stars 96 forks source link

Augment workarounds with USE-flag oriented exceptions #78

Open InBetweenNames opened 6 years ago

InBetweenNames commented 6 years ago

Certain workarounds are only necessary in the presence of particular USE flags (see #75). It would be nice to be able to specify workarounds that apply only in these cases, for example:

media-libs/mesa[nouveau] *FLAGS-=-flto*
*/ffmpeg[cpu_flags_x86_sse4_1] *FLAGS-=-flto*

This would require some patches to make it work. One approach that works right away without any patching at all is:

media-libs/mesa "has video_cards_nouveau ${IUSE//+} && use video_cards_nouveau && FlagSubAllFlags -flto*"

(courtesy of @pchome)

As contributors of this repo, I'd like to ask you what the best approach for doing this would be. I'll leave this thread open for any discussion or ideas on this.

pchome commented 6 years ago

The simpliest way is to add /etc/portage/bashrc.d/0000-lto-overlay-helpers.sh:

#!/bin/bash

# Helpers
# for LTO overlay [https://github.com/InBetweenNames/gentooLTO]
# and package.cflags [https://github.com/vaeth/portage-bashrc-mv]

# based on eutils.eclass:use_if_iuse()
lto_use_if_iuse() {
        [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()"
        local flag=${1}
        local liuse=( ${IUSE} )

        has "${flag}" "${liuse[@]#[+-]}" || return 1
        use $1
}

no_lto_if_use() {
        lto_use_if_iuse $1 && FlagSubAllFlags -flto*
}

no_graphite_if_use() {
        lto_use_if_iuse $1 && FlagSubAllFlags ${GRAPHITE}
}

drop_flag_if_use() {
        [[ ${#} -eq 2 ]] || die "Invalid args to ${FUNCNAME}()"
        lto_use_if_iuse $1 && FlagSubAllFlags $2
}

...

and then media-libs/mesa "no_lto_if_use video_cards_nouveau" or media-libs/mesa "drop_flag_if_use video_cards_nouveau -flto*"

pchome commented 6 years ago

Also you can simplify all this common *FLAGS-=-SGALF* with

...
noLTO() {
        FlagSubAllFlags -flto*
}

noGRAPHITE() {
        FlagSubAllFlags ${GRAPHITE}
}

fatLTO() {
        FlagAddAllFlags -ffat-lto-objects
}
...

package/name noLTO; noGRAPHITE; package/name fatLTO;

for example