1 |
A function which determines correct .la files for removal and removes |
2 |
them. |
3 |
--- |
4 |
gx86/eclass/eutils.eclass | 92 ++++++++++++++++++++++++++++++++++++++++++++- |
5 |
1 file changed, 91 insertions(+), 1 deletion(-) |
6 |
|
7 |
diff --git a/gx86/eclass/eutils.eclass b/gx86/eclass/eutils.eclass |
8 |
index c88ef35..b0399ac 100644 |
9 |
--- a/gx86/eclass/eutils.eclass |
10 |
+++ b/gx86/eclass/eutils.eclass |
11 |
@@ -18,7 +18,7 @@ |
12 |
if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then |
13 |
___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" |
14 |
|
15 |
-inherit multilib user |
16 |
+inherit multilib toolchain-funcs user |
17 |
|
18 |
DESCRIPTION="Based on the ${ECLASS} eclass" |
19 |
|
20 |
@@ -1330,6 +1330,96 @@ makeopts_jobs() { |
21 |
echo ${jobs:-1} |
22 |
} |
23 |
|
24 |
+# @FUNCTION: prune_libtool_files |
25 |
+# @USAGE: [--all] |
26 |
+# @DESCRIPTION: |
27 |
+# Locate unnecessary libtool files (.la) and libtool static archives |
28 |
+# (.a) and remove them from installation image. |
29 |
+# |
30 |
+# By default, .la files are removed whenever the static linkage can |
31 |
+# either be performed using pkg-config or doesn't introduce additional |
32 |
+# flags. |
33 |
+# |
34 |
+# If '--all' argument is passed, all .la files are removed. This is |
35 |
+# usually useful when the package installs plugins and does not use .la |
36 |
+# files for loading them. |
37 |
+# |
38 |
+# The .a files are only removed whenever corresponding .la files state |
39 |
+# that they should not be linked to, i.e. whenever these files |
40 |
+# correspond to plugins. |
41 |
+# |
42 |
+# Note: this function implicitly calls pkg-config. You should add it to |
43 |
+# your DEPEND when using it. |
44 |
+prune_libtool_files() { |
45 |
+ debug-print-function ${FUNCNAME} "$@" |
46 |
+ |
47 |
+ local removing_all opt |
48 |
+ for opt; do |
49 |
+ case "${opt}" in |
50 |
+ --all) |
51 |
+ removing_all=1 |
52 |
+ ;; |
53 |
+ *) |
54 |
+ die "Invalid argument to ${FUNCNAME}(): ${opt}" |
55 |
+ esac |
56 |
+ done |
57 |
+ |
58 |
+ # Create a list of all .pc-covered libs. |
59 |
+ local pc_libs=() |
60 |
+ if [[ ! ${removing_all} ]]; then |
61 |
+ local f |
62 |
+ local tf=${T}/prune-lt-files.pc |
63 |
+ local pkgconf=$(tc-getPKG_CONFIG) |
64 |
+ |
65 |
+ while IFS= read -r -d '' f; do # for all .pc files |
66 |
+ sed -e '/^Requires:/d' "${f}" > "${tf}" |
67 |
+ for arg in $("${pkgconf}" --libs "${tf}"); do |
68 |
+ [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la ) |
69 |
+ done |
70 |
+ done < <(find "${D}" -type f -name '*.pc' -print0) |
71 |
+ fi |
72 |
+ |
73 |
+ local f |
74 |
+ while IFS= read -r -d '' f; do # for all .la files |
75 |
+ local archivefile=${f/%.la/.a} |
76 |
+ |
77 |
+ [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed' |
78 |
+ |
79 |
+ # Remove static libs we're not supposed to link against. |
80 |
+ if grep -q '^shouldnotlink=yes$' "${f}"; then |
81 |
+ einfo "Removing unnecessary ${archivefile#${D%/}}" |
82 |
+ rm -f "${archivefile}" |
83 |
+ |
84 |
+ # The .la file may be used by a module loader, so avoid removing it |
85 |
+ # unless explicitly requested. |
86 |
+ [[ ${removing_all} ]] || continue |
87 |
+ fi |
88 |
+ |
89 |
+ # Remove .la files when: |
90 |
+ # - user explicitly wants us to remove all .la files, |
91 |
+ # - respective static archive doesn't exist, |
92 |
+ # - they are covered by a .pc file already, |
93 |
+ # - they don't provide any new information (no libs & no flags). |
94 |
+ local reason |
95 |
+ if [[ ${removing_all} ]]; then |
96 |
+ reason='requested' |
97 |
+ elif [[ ! -f ${archivefile} ]]; then |
98 |
+ reason='no static archive' |
99 |
+ elif has "${f##*/}" "${pc_libs[@]}"; then |
100 |
+ reason='covered by .pc' |
101 |
+ elif [[ ! $(sed -nre \ |
102 |
+ "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \ |
103 |
+ "${f}") ]]; then |
104 |
+ reason='no libs & flags' |
105 |
+ fi |
106 |
+ |
107 |
+ if [[ ${reason} ]]; then |
108 |
+ einfo "Removing unnecessary ${f#${D%/}} (${reason})" |
109 |
+ rm -f "${f}" |
110 |
+ fi |
111 |
+ done < <(find "${D}" -type f -name '*.la' -print0) |
112 |
+} |
113 |
+ |
114 |
check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } |
115 |
|
116 |
fi |
117 |
-- |
118 |
1.7.10.2 |