Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] autotools-utils.eclass: punt unnecessary .la files even w/ USE=static-libs.
Date: Mon, 12 Sep 2011 19:56:55
Message-Id: 1315857465-8179-1-git-send-email-mgorny@gentoo.org
1 Right now, autotools-utils.eclass punts .la files only with
2 USE=-static-libs. We'd like to broaden the range of it and strip .la
3 files when they are not necessary for static linkage as well.
4
5 The following patch introduces an initial support for that. It assumes
6 that the .la file can be removed if the library is mentioned in any of
7 pkg-config files installed by the package, or if doesn't specify any
8 dependency libs nor linker flags.
9
10 The code would probably use some refactoring but we will handle that
11 after more testing (and possibly extensions) to the concept itself.
12 ---
13 autotools-utils.eclass | 25 +++++++++++++++++++++++--
14 1 files changed, 23 insertions(+), 2 deletions(-)
15
16 diff --git a/autotools-utils.eclass b/autotools-utils.eclass
17 index 7905d44..ce6613b 100644
18 --- a/autotools-utils.eclass
19 +++ b/autotools-utils.eclass
20 @@ -132,7 +132,7 @@ _check_build_dir() {
21 }
22
23 # @FUNCTION: remove_libtool_files
24 -# @USAGE: [all|none]
25 +# @USAGE: [all|only-not-required|none]
26 # @DESCRIPTION:
27 # Determines unnecessary libtool files (.la) and libtool static archives (.a)
28 # and removes them from installation image.
29 @@ -145,11 +145,32 @@ _check_build_dir() {
30 remove_libtool_files() {
31 debug-print-function ${FUNCNAME} "$@"
32
33 + if [[ "$1" == 'only-not-required' ]]; then
34 + local pc_libs=''
35 +
36 + for arg in $(find "${D}" -name '*.pc' -exec sed -n -e 's;^Libs:;;p' {} +); do
37 + if [[ ${arg} == -l* ]]; then
38 + pc_libs="${pc_libs} lib${arg#-l}.la"
39 + fi
40 + done
41 + fi
42 +
43 local f
44 for f in $(find "${D}" -type f -name '*.la'); do
45 # Keep only .la files with shouldnotlink=yes - likely plugins
46 local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
47 if [[ "$1" == 'all' || -z ${shouldnotlink} ]]; then
48 + if [[ "$1" == 'only-not-required' ]]; then
49 + # remove .la files only when .pc files provide the libs
50 + # already or they don't give any information
51 + ! has $(basename "${f}") ${pc_libs} \
52 + && [[ -n "$(sed -n \
53 + -e "s/^dependency_libs='\(.*\)'$/\1/p" \
54 + -e "s/^inherited_linker_flags='\(.*\)'$/\1/p" \
55 + "${f}")" ]] \
56 + && continue
57 + fi
58 +
59 if [[ "$1" != 'none' ]]; then
60 echo "Removing unnecessary ${f}"
61 rm -f "${f}"
62 @@ -246,7 +267,7 @@ autotools-utils_src_install() {
63
64 # Remove libtool files and unnecessary static libs
65 local args
66 - has static-libs ${IUSE//+} && ! use static-libs || args='none'
67 + has static-libs ${IUSE//+} && ! use static-libs || args='only-not-required'
68 remove_libtool_files ${args}
69 }
70
71 --
72 1.7.6.1

Replies