public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use.
@ 2012-05-28  7:58 Michał Górny
  2012-05-28  9:03 ` Pacho Ramos
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Michał Górny @ 2012-05-28  7:58 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

As autotools-utils exports phase functions, it will be better if
remove_libtool_files() functions would be somewhere else.
---
 eutils.eclass |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/eutils.eclass b/eutils.eclass
index c88ef35..fb92256 100644
--- a/eutils.eclass
+++ b/eutils.eclass
@@ -1330,6 +1330,74 @@ makeopts_jobs() {
 	echo ${jobs:-1}
 }
 
+# @FUNCTION: remove_libtool_files
+# @USAGE: [all]
+# @DESCRIPTION:
+# Determines unnecessary libtool files (.la) and libtool static archives (.a),
+# and removes them from installation image.
+#
+# To unconditionally remove all libtool files, pass 'all' as an argument.
+# Otherwise, libtool archives required for static linking will be preserved.
+remove_libtool_files() {
+	debug-print-function ${FUNCNAME} "$@"
+	local removing_all
+	[[ ${#} -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
+
+	local pc_libs=()
+	if [[ ! ${removing_all} ]]; then
+		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
+	fi
+
+	local f
+	find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
+		local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
+		local archivefile=${f/%.la/.a}
+		[[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed'
+
+		# Remove static libs we're not supposed to link against.
+		if [[ ${shouldnotlink} ]]; then
+			einfo "Removing unnecessary ${archivefile#${D%/}}"
+			rm -f "${archivefile}" || die
+			# The .la file may be used by a module loader, so avoid removing it
+			# unless explicitly requested.
+			[[ ${removing_all} ]] || continue
+		fi
+
+		# Remove .la files when:
+		# - user explicitly wants us to remove all .la files,
+		# - respective static archive doesn't exist,
+		# - they are covered by a .pc file already,
+		# - they don't provide any new information (no libs & no flags).
+		local removing
+		if [[ ${removing_all} ]]; then removing='forced'
+		elif [[ ! -f ${archivefile} ]]; then removing='no static archive'
+		elif has "$(basename "${f}")" "${pc_libs[@]}"; then
+			removing='covered by .pc'
+		elif [[ ! $(sed -n -e \
+			"s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p" \
+			"${f}") ]]; then removing='no libs & flags'
+		fi
+
+		if [[ ${removing} ]]; then
+			einfo "Removing unnecessary ${f#${D%/}} (${removing})"
+			rm -f "${f}" || die
+		fi
+	done
+}
+
 check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
 
 fi
-- 
1.7.10.2




^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-06-06 15:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28  7:58 [gentoo-dev] [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use Michał Górny
2012-05-28  9:03 ` Pacho Ramos
2012-05-29 13:50 ` [gentoo-dev] " Steven J Long
2012-05-29 14:26   ` Steven J Long
2012-05-30 17:16   ` Michał Górny
2012-05-30 21:19 ` [gentoo-dev] " Mike Frysinger
2012-05-31  5:46   ` Michał Górny
2012-05-31  6:09     ` Mike Frysinger
2012-05-31 11:40       ` Michał Górny
2012-05-31 12:55   ` [gentoo-dev] [PATCH eutils] Introduce prune_libtool_files() Michał Górny
2012-06-05  6:00     ` Mike Frysinger
2012-06-06 15:40       ` Michał Górny
2012-06-05  2:46 ` [gentoo-dev] Re: [PATCH eutils] Move remove_libtool_files() from autotools-utils for wider use Ryan Hill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox