#!/hint/bash
# SPDX-FileCopyrightText: 2025 Eli Schwartz <eschwartz@gentoo.org>
# SPDX-License-Identifier: GPL-2.0-or-later

static_lto() {
    local line text missinglibs=()
    while read -r -d '' line; do
        text=$(objdump -h "${line}" | grep .gnu.lto_.opts)
        [[ ${text} ]] && missinglibs+=("${line}")
    done < <(find "${ED}" -iname '*.a' -print0)

    if [[ ${#missinglibs[@]} -gt 0 ]]; then
        eqawarn "QA Notice: unstripped LTO libs"
        eqatag -v static-lto "${missinglibs[@]/#${ED}/}"
    fi
}

static_lto
: # guarantee successful exit
