From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SZqK1-0007k3-3M for garchives@archives.gentoo.org; Wed, 30 May 2012 21:20:50 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7509FE07F9; Wed, 30 May 2012 21:20:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 8D700E0713 for ; Wed, 30 May 2012 21:19:49 +0000 (UTC) Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 07E1F1B401E for ; Wed, 30 May 2012 21:19:49 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use. Date: Wed, 30 May 2012 17:19:49 -0400 User-Agent: KMail/1.13.7 (Linux/3.4.0; KDE/4.6.5; x86_64; ; ) References: <1338191936-2091-1-git-send-email-mgorny@gentoo.org> In-Reply-To: <1338191936-2091-1-git-send-email-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3367982.ZEV0yAybOd"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201205301719.50449.vapier@gentoo.org> X-Archives-Salt: 3e414b02-a3c9-4348-94d4-2fb64f76011f X-Archives-Hash: ffb2485e07e1c6d6cf82f62a9572aaf1 --nextPart3367982.ZEV0yAybOd Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Monday 28 May 2012 03:58:56 Micha=C5=82 G=C3=B3rny wrote: > +# @FUNCTION: remove_libtool_files "preen_libtool_files" might be better. after all, you aren't just removing= =20 them all. > +# @USAGE: [all] this is incorrect. the usage is: > + [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()" > + if [[ ${#} -eq 1 ]]; then > + case "${1}" in > + all) > + removing_all=3D1 > + ;; > + *) > + die "Invalid argument to ${FUNCNAME}(): ${1}" > + esac > + fi personally i don't think the internal @ $ 0-9 # variables should get braces= =20 unless absolutely necessary the *) case is missing a ";;" ... yes, it's not required in the last case=20 statement, but that's easy to bite people, so i prefer to make it explicit > + if [[ ! ${removing_all} ]]; then i know you don't like specifying -z/-n but instead relying on the implicit = =2Dn,=20 but i find it less clear, especially for people who aren't aware of the exa= ct=20 semantics > + local arg > + for arg in $(find "${D}" -name '*.pc' -exec \ > + sed -n -e 's;^Libs:;;p' {} +); do > + [[ ${arg} =3D=3D -l* ]] && pc_libs+=3D(lib${arg#-l}.la) > + done let sed do the processing: pc_libs=3D( $(find "${D}" -name '*.pc' \ -exec sed -n -e '/^Libs:/{s|^[^:]*:||;s: :\n:g;p}' {} + | \ sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}') ) however, i'd point out that parsing these files directly doesn't actually w= ork. =20 some .pc files use variables in the filename which isn't expanded by using = sed. =20 thus your only recourse is to let pkg-config expand things for you. $ grep '^Libs:.*-l[^ ]*[$]' /usr/lib64/pkgconfig/*.pc /usr/lib64/pkgconfig/apr-1.pc:Libs: -L${libdir} -lapr-${APR_MAJOR_VERSION} = =2E.. /usr/lib64/pkgconfig/gtk+-2.0.pc:Libs: -L${libdir} -lgtk-${target}-2.0 so maybe something like: local pc while read -rd '' pc ; do sed -e '/^Requires:/d' "${pc}" > "${T}/${pc##*/}" pc_libs+=3D( $($(tc-getPKG_CONFIG) --libs "${T}"/${pc##*/}" | \ tr ' ' '\n' | \ sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}') ) done < <(find "${D}" -name '*.pc' -type f -print0) pc_libs=3D( $(printf '%s\n' "${pc_libs[@]}") | sort -u ) although, since we don't call die or anything, we can pipeline it to speed= =20 things up a bit: pc_libs=3D( $( tpc=3D"${T}/.pc" find "${D}" -name '*.pc' -type f | \ while read pc ; do sed -e '/^Requires:/d' "${pc}" > "${tpc}" $(tc-getPKG_CONFIG) --libs "${tpc}" done | tr ' ' '\n' | sort -u | \ sed -n '/^-l/{s:^-l:lib:;s:$:.la:;p}' rm -f "${tpc}" ) ) > + local archivefile=3D${f/%.la/.a} remove the suffix and it'll be faster i think: local archivefile=3D"${f%.la}.a" > + [[ "${f}" !=3D "${archivefile}" ]] || die 'regex sanity check failed' no need to quote the ${f}, but eh > + rm -f "${archivefile}" || die `rm -f` almost never fails. in the edge cases where it does, you've got=20 bigger problems. > + if [[ ${removing_all} ]]; then removing=3D'forced' > + elif [[ ! -f ${archivefile} ]]; then removing=3D'no static archive' unwrap these > + elif has "$(basename "${f}")" "${pc_libs[@]}"; then use ${f##*/} rather than `basename` > + removing=3D'covered by .pc' > + elif [[ ! $(sed -n -e \ > + "s/^\(dependency_libs\|inherited_linker_flags\)=3D'\(.*\)'$/\2/p" \ > + "${f}") ]]; then removing=3D'no libs & flags' unwrap that body, and use -r rather than escaping the (|) chars =2Dmike --nextPart3367982.ZEV0yAybOd Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJPxo72AAoJEEFjO5/oN/WBw6QP/2gH1x+H3z7+QoCCpn/e6QNB /oHHczbbJXCfIZ96+018yorwsJzZK9uhAKAO1UWquY4IxMcC7hdddNZ0zxEigwL0 WSxEpVsiSE6W927/dcgJs8GCs3fqHZHzGxNyy7L3wuz1M+7cz/pQXX6ETWKp0lRN 01qPeuCwBhY2pT70QGGQOXXeFfaXyrTI7n7runR8G8e1Hug4wqzV8JkR7jNayPZO dKWiEhh4SIChnIM0UikumEbA6sEZc1TtEUZPgGmVnKsdYWfpO/TjzW6PoHBWT67k ycARZVBPlLv0giXHwxd/uivw1rAwvum3MNi7MRsbg9MRdgOPjBeVJfjt/adEt+3W iAT5idRtCVrIBnT4ZHQu71nv7s3U3qUKNxTqkwTk2der7C4c9etAB4caVJ6pNTLW a8fQB5UThV0ful+h4uYFkXNQQBcvrqqPuydUResTlUyFooBrWApLRkHls0O156FQ jPamCf1BqFIpmhZ2gB2QIJL/atPZLI++SLgCqxvd3bIEcFRVoTr3qu1Z9i7w11Op yvDAhjBE6gbWD33sHgdPjhWV/iQTCG1bySkAOdE9rp4u1PlWg739ZdOQDr1AAjuN yvpmbMlf4AvxBTeQQAI121hvmWosR774DX46toBMOE/PfXrAtnJrtyxnIEWYVwE0 aCPVV8fSEkrLcqyLAFUs =rcwq -----END PGP SIGNATURE----- --nextPart3367982.ZEV0yAybOd--