diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-06-06 15:37:50 +0000 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-06-06 15:37:50 +0000 |
commit | e58e845b6bae7c01096b75539fede9492458c2a5 (patch) | |
tree | a9d076494d2aa0aaab3adf28c670bdca171a4f1e /eclass/eutils.eclass | |
parent | Version bump. The new version introduces equations for heat capacity & speed ... (diff) | |
download | historical-e58e845b6bae7c01096b75539fede9492458c2a5.tar.gz historical-e58e845b6bae7c01096b75539fede9492458c2a5.tar.bz2 historical-e58e845b6bae7c01096b75539fede9492458c2a5.zip |
Introduce prune_libtool_files() for .la file removal. Based on one used by autotools-utils.
Diffstat (limited to 'eclass/eutils.eclass')
-rw-r--r-- | eclass/eutils.eclass | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass index 2c645c7290d2..b6dd9a5798f5 100644 --- a/eclass/eutils.eclass +++ b/eclass/eutils.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.394 2012/06/05 17:40:12 hasufell Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.395 2012/06/06 15:37:50 mgorny Exp $ # @ECLASS: eutils.eclass # @MAINTAINER: @@ -18,7 +18,7 @@ if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" -inherit multilib user +inherit multilib toolchain-funcs user DESCRIPTION="Based on the ${ECLASS} eclass" @@ -1399,6 +1399,100 @@ makeopts_jobs() { echo ${jobs:-1} } +# @FUNCTION: prune_libtool_files +# @USAGE: [--all] +# @DESCRIPTION: +# Locate unnecessary libtool files (.la) and libtool static archives +# (.a) and remove them from installation image. +# +# By default, .la files are removed whenever the static linkage can +# either be performed using pkg-config or doesn't introduce additional +# flags. +# +# If '--all' argument is passed, all .la files are removed. This is +# usually useful when the package installs plugins and does not use .la +# files for loading them. +# +# The .a files are only removed whenever corresponding .la files state +# that they should not be linked to, i.e. whenever these files +# correspond to plugins. +# +# Note: if your package installs any .pc files, this function implicitly +# calls pkg-config. You should add it to your DEPEND in that case. +prune_libtool_files() { + debug-print-function ${FUNCNAME} "$@" + + local removing_all opt + for opt; do + case "${opt}" in + --all) + removing_all=1 + ;; + *) + die "Invalid argument to ${FUNCNAME}(): ${opt}" + esac + done + + # Create a list of all .pc-covered libs. + local pc_libs=() + if [[ ! ${removing_all} ]]; then + local f + local tf=${T}/prune-lt-files.pc + local pkgconf=$(tc-getPKG_CONFIG) + + while IFS= read -r -d '' f; do # for all .pc files + local arg + + sed -e '/^Requires:/d' "${f}" > "${tf}" + for arg in $("${pkgconf}" --libs "${tf}"); do + [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) + done + done < <(find "${D}" -type f -name '*.pc' -print0) + + rm -f "${tf}" + fi + + local f + while IFS= read -r -d '' f; do # for all .la files + local archivefile=${f/%.la/.a} + + [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' + + # Remove static libs we're not supposed to link against. + if grep -q '^shouldnotlink=yes$' "${f}"; then + einfo "Removing unnecessary ${archivefile#${D%/}}" + rm -f "${archivefile}" + + # The .la file may be used by a module loader, so avoid removing it + # unless explicitly requested. + [[ ${removing_all} ]] || continue + fi + + # Remove .la files when: + # - user explicitly wants us to remove all .la files, + # - respective static archive doesn't exist, + # - they are covered by a .pc file already, + # - they don't provide any new information (no libs & no flags). + local reason + if [[ ${removing_all} ]]; then + reason='requested' + elif [[ ! -f ${archivefile} ]]; then + reason='no static archive' + elif has "${f##*/}" "${pc_libs[@]}"; then + reason='covered by .pc' + elif [[ ! $(sed -nre \ + "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \ + "${f}") ]]; then + reason='no libs & flags' + fi + + if [[ ${reason} ]]; then + einfo "Removing unnecessary ${f#${D%/}} (${reason})" + rm -f "${f}" + fi + done < <(find "${D}" -type f -name '*.la' -print0) +} + check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } fi |