Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Date: Wed, 30 May 2012 21:20:50
Message-Id: 201205301719.50449.vapier@gentoo.org
In Reply to: [gentoo-dev] [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use. by "Michał Górny"
1 On Monday 28 May 2012 03:58:56 Michał Górny wrote:
2 > +# @FUNCTION: remove_libtool_files
3
4 "preen_libtool_files" might be better. after all, you aren't just removing
5 them all.
6
7 > +# @USAGE: [all]
8
9 this is incorrect. the usage is:
10 <all | files to remove>
11
12 > + [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
13 > + if [[ ${#} -eq 1 ]]; then
14 > + case "${1}" in
15 > + all)
16 > + removing_all=1
17 > + ;;
18 > + *)
19 > + die "Invalid argument to ${FUNCNAME}(): ${1}"
20 > + esac
21 > + fi
22
23 personally i don't think the internal @ $ 0-9 # variables should get braces
24 unless absolutely necessary
25
26 the *) case is missing a ";;" ... yes, it's not required in the last case
27 statement, but that's easy to bite people, so i prefer to make it explicit
28
29 > + if [[ ! ${removing_all} ]]; then
30
31 i know you don't like specifying -z/-n but instead relying on the implicit -n,
32 but i find it less clear, especially for people who aren't aware of the exact
33 semantics
34
35 > + local arg
36 > + for arg in $(find "${D}" -name '*.pc' -exec \
37 > + sed -n -e 's;^Libs:;;p' {} +); do
38 > + [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
39 > + done
40
41 let sed do the processing:
42 pc_libs=(
43 $(find "${D}" -name '*.pc' \
44 -exec sed -n -e '/^Libs:/{s|^[^:]*:||;s: :\n:g;p}' {} + | \
45 sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}')
46 )
47
48 however, i'd point out that parsing these files directly doesn't actually work.
49 some .pc files use variables in the filename which isn't expanded by using sed.
50 thus your only recourse is to let pkg-config expand things for you.
51
52 $ grep '^Libs:.*-l[^ ]*[$]' /usr/lib64/pkgconfig/*.pc
53 /usr/lib64/pkgconfig/apr-1.pc:Libs: -L${libdir} -lapr-${APR_MAJOR_VERSION} ...
54 /usr/lib64/pkgconfig/gtk+-2.0.pc:Libs: -L${libdir} -lgtk-${target}-2.0
55
56 so maybe something like:
57 local pc
58 while read -rd '' pc ; do
59 sed -e '/^Requires:/d' "${pc}" > "${T}/${pc##*/}"
60 pc_libs+=(
61 $($(tc-getPKG_CONFIG) --libs "${T}"/${pc##*/}" | \
62 tr ' ' '\n' | \
63 sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}')
64 )
65 done < <(find "${D}" -name '*.pc' -type f -print0)
66 pc_libs=( $(printf '%s\n' "${pc_libs[@]}") | sort -u )
67
68 although, since we don't call die or anything, we can pipeline it to speed
69 things up a bit:
70 pc_libs=( $(
71 tpc="${T}/.pc"
72 find "${D}" -name '*.pc' -type f | \
73 while read pc ; do
74 sed -e '/^Requires:/d' "${pc}" > "${tpc}"
75 $(tc-getPKG_CONFIG) --libs "${tpc}"
76 done | tr ' ' '\n' | sort -u | \
77 sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}'
78 rm -f "${tpc}"
79 ) )
80
81 > + local archivefile=${f/%.la/.a}
82
83 remove the suffix and it'll be faster i think:
84 local archivefile="${f%.la}.a"
85
86 > + [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
87
88 no need to quote the ${f}, but eh
89
90 > + rm -f "${archivefile}" || die
91
92 `rm -f` almost never fails. in the edge cases where it does, you've got
93 bigger problems.
94
95 > + if [[ ${removing_all} ]]; then removing='forced'
96 > + elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
97
98 unwrap these
99
100 > + elif has "$(basename "${f}")" "${pc_libs[@]}"; then
101
102 use ${f##*/} rather than `basename`
103
104 > + removing='covered by .pc'
105 > + elif [[ ! $(sed -n -e \
106 > + "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
107 > + "${f}") ]]; then removing='no libs & flags'
108
109 unwrap that body, and use -r rather than escaping the (|) chars
110 -mike

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies