Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Gentoo: Dev

[PATCH eutils] Introduce prune_libtool_files().

 

 

Gentoo dev RSS feed   Index | Next | Previous | View Threaded


mgorny at gentoo

May 31, 2012, 5:55 AM

Post #1 of 3 (152 views)
Permalink
[PATCH eutils] Introduce prune_libtool_files().

A function which determines correct .la files for removal and removes
them.
---
gx86/eclass/eutils.eclass | 92 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 1 deletion(-)

diff --git a/gx86/eclass/eutils.eclass b/gx86/eclass/eutils.eclass
index c88ef35..b0399ac 100644
--- a/gx86/eclass/eutils.eclass
+++ b/gx86/eclass/eutils.eclass
@@ -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"

@@ -1330,6 +1330,96 @@ 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: this function implicitly calls pkg-config. You should add it to
+# your DEPEND when using it.
+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
+ 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)
+ 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
--
1.7.10.2


vapier at gentoo

Jun 4, 2012, 11:00 PM

Post #2 of 3 (144 views)
Permalink
Re: [PATCH eutils] Introduce prune_libtool_files(). [In reply to]

On Thursday 31 May 2012 08:55:25 Michał Górny wrote:
> +# Note: this function implicitly calls pkg-config. You should add it to
> +# your DEPEND when using it.

should clarify: implicitly calls pkg-config when your package provides a .pc.

> + 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
> + sed -e '/^Requires:/d' "${f}" > "${tf}"
> + for arg in $("${pkgconf}" --libs "${tf}"); do

missing `local arg`

> + done < <(find "${D}" -type f -name '*.pc' -print0)

not a big deal since it'll get cleaned anyways, but this doesn't clean up $tf
when done

if no one else has feedback, i guess merge it
-mike
Attachments: signature.asc (0.82 KB)


mgorny at gentoo

Jun 6, 2012, 8:40 AM

Post #3 of 3 (138 views)
Permalink
Re: [PATCH eutils] Introduce prune_libtool_files(). [In reply to]

On Tue, 5 Jun 2012 02:00:34 -0400
Mike Frysinger <vapier [at] gentoo> wrote:

> if no one else has feedback, i guess merge it

/var/cvsroot/gentoo-x86/eclass/ChangeLog,v <-- ChangeLog
new revision: 1.291; previous revision: 1.290
/var/cvsroot/gentoo-x86/eclass/eutils.eclass,v <-- eutils.eclass
new revision: 1.395; previous revision: 1.394

--
Best regards,
Michał Górny
Attachments: signature.asc (0.31 KB)

Gentoo dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.