Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: Mike Frysinger <vapier@g.o>
Subject: Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Date: Wed, 30 May 2012 17:19:49 -0400
On Monday 28 May 2012 03:58:56 Michał Górny wrote:
> +# @FUNCTION: remove_libtool_files

"preen_libtool_files" might be better.  after all, you aren't just removing 
them all.

> +# @USAGE: [all]

this is incorrect.  the usage is:
	<all | files to remove>

> +	[[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()"
> +	if [[ ${#} -eq 1 ]]; then
> +		case "${1}" in
> +			all)
> +				removing_all=1
> +				;;
> +			*)
> +				die "Invalid argument to ${FUNCNAME}(): ${1}"
> +		esac
> +	fi

personally i don't think the internal @ $ 0-9 # variables should get braces 
unless absolutely necessary

the *) case is missing a ";;" ... yes, it's not required in the last case 
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 -n, 
but i find it less clear, especially for people who aren't aware of the exact 
semantics

> +		local arg
> +		for arg in $(find "${D}" -name '*.pc' -exec \
> +					sed -n -e 's;^Libs:;;p' {} +); do
> +			[[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la)
> +		done

let sed do the processing:
pc_libs=(
	$(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 work.  
some .pc files use variables in the filename which isn't expanded by using sed.  
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} ...
/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+=(
			$($(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=( $(printf '%s\n' "${pc_libs[@]}") | sort -u )

although, since we don't call die or anything, we can pipeline it to speed 
things up a bit:
	pc_libs=( $(
		tpc="${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=${f/%.la/.a}

remove the suffix and it'll be faster i think:
	local archivefile="${f%.la}.a"

> +		[[ "${f}" != "${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 
bigger problems.

> +		if [[ ${removing_all} ]]; then removing='forced'
> +		elif [[ ! -f ${archivefile} ]]; then removing='no static archive'

unwrap these

> +		elif has "$(basename "${f}")" "${pc_libs[@]}"; then

use ${f##*/} rather than `basename`

> +			removing='covered by .pc'
> +		elif [[ ! $(sed -n -e \
> +			"s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
> +			"${f}") ]]; then removing='no libs & flags'

unwrap that body, and use -r rather than escaping the (|) chars
-mike
Attachment:
signature.asc (This is a digitally signed message part.)
Replies:
[PATCH eutils] Introduce prune_libtool_files().
-- Michał Górny
Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
-- Michał Górny
References:
[PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
-- Michał Górny
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Next by thread:
Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
Previous by date:
Re: Should packages auto-eselect alternative implementation on removal?
Next by date:
Re: dev-libs/libusbx:1 the default provider for virtual/libusb:1 (for ~arch)


Updated Jun 29, 2012

Summary: Archive of the gentoo-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.