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 | 6ed19d61c34344af63918f565f6dccaa6e70383b (patch) | |
tree | 448e892f8396b0c83a89c19a61d7e7f317ab6e02 /eclass | |
parent | Version bump. The new version introduces equations for heat capacity & speed ... (diff) | |
download | gentoo-2-6ed19d61c34344af63918f565f6dccaa6e70383b.tar.gz gentoo-2-6ed19d61c34344af63918f565f6dccaa6e70383b.tar.bz2 gentoo-2-6ed19d61c34344af63918f565f6dccaa6e70383b.zip |
Introduce prune_libtool_files() for .la file removal. Based on one used by autotools-utils.
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/ChangeLog | 6 | ||||
-rw-r--r-- | eclass/eutils.eclass | 98 |
2 files changed, 101 insertions, 3 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog index bfe5ed3f0e80..180ca73bd41d 100644 --- a/eclass/ChangeLog +++ b/eclass/ChangeLog @@ -1,6 +1,10 @@ # ChangeLog for eclass directory # Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.290 2012/06/05 18:31:54 grobian Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.291 2012/06/06 15:37:50 mgorny Exp $ + + 06 Jun 2012; Michał Górny <mgorny@gentoo.org> eutils.eclass: + Introduce prune_libtool_files() for .la file removal. Based on one used + by autotools-utils. 05 Jun 2012; Fabian Groffen <grobian@gentoo.org> autotools.eclass: Avoid type -P output for glibtoolize, bug #419641 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 |