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: Michał Górny <mgorny@g.o>
Subject: [PATCH] autotools-utils.eclass: punt unnecessary .la files even w/ USE=static-libs.
Date: Mon, 12 Sep 2011 21:57:45 +0200
Right now, autotools-utils.eclass punts .la files only with
USE=-static-libs. We'd like to broaden the range of it and strip .la
files when they are not necessary for static linkage as well.

The following patch introduces an initial support for that. It assumes
that the .la file can be removed if the library is mentioned in any of
pkg-config files installed by the package, or if doesn't specify any
dependency libs nor linker flags.

The code would probably use some refactoring but we will handle that
after more testing (and possibly extensions) to the concept itself.
---
 autotools-utils.eclass |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/autotools-utils.eclass b/autotools-utils.eclass
index 7905d44..ce6613b 100644
--- a/autotools-utils.eclass
+++ b/autotools-utils.eclass
@@ -132,7 +132,7 @@ _check_build_dir() {
 }
 
 # @FUNCTION: remove_libtool_files
-# @USAGE: [all|none]
+# @USAGE: [all|only-not-required|none]
 # @DESCRIPTION:
 # Determines unnecessary libtool files (.la) and libtool static archives (.a)
 # and removes them from installation image.
@@ -145,11 +145,32 @@ _check_build_dir() {
 remove_libtool_files() {
 	debug-print-function ${FUNCNAME} "$@"
 
+	if [[ "$1" == 'only-not-required' ]]; then
+		local pc_libs=''
+
+		for arg in $(find "${D}" -name '*.pc' -exec sed -n -e 's;^Libs:;;p' {} +); do
+			if [[ ${arg} == -l* ]]; then
+				pc_libs="${pc_libs} lib${arg#-l}.la"
+			fi
+		done
+	fi
+
 	local f
 	for f in $(find "${D}" -type f -name '*.la'); do
 		# Keep only .la files with shouldnotlink=yes - likely plugins
 		local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}")
 		if [[  "$1" == 'all' || -z ${shouldnotlink} ]]; then
+			if [[ "$1" == 'only-not-required' ]]; then
+				# remove .la files only when .pc files provide the libs
+				# already or they don't give any information
+				! has $(basename "${f}") ${pc_libs} \
+						&& [[ -n "$(sed -n \
+							-e "s/^dependency_libs='\(.*\)'$/\1/p" \
+							-e "s/^inherited_linker_flags='\(.*\)'$/\1/p" \
+							"${f}")" ]] \
+						&& continue
+			fi
+
 			if [[ "$1" != 'none' ]]; then
 				echo "Removing unnecessary ${f}"
 				rm -f "${f}"
@@ -246,7 +267,7 @@ autotools-utils_src_install() {
 
 	# Remove libtool files and unnecessary static libs
 	local args
-	has static-libs ${IUSE//+} && ! use static-libs || args='none'
+	has static-libs ${IUSE//+} && ! use static-libs || args='only-not-required'
 	remove_libtool_files ${args}
 }
 
-- 
1.7.6.1



Replies:
[PATCH autotools-utils 1/9] Fix handling whitespace in filenames when looking for .la files.
-- Michał Górny
Re: [PATCH] autotools-utils.eclass: punt unnecessary .la files even w/ USE=static-libs.
-- Donnie Berkholz
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
A big thanks to Matt Turner for his hard work on Gentoo/MIPS
Next by thread:
Re: [PATCH] autotools-utils.eclass: punt unnecessary .la files even w/ USE=static-libs.
Previous by date:
Re: multilib setup
Next by date:
Re: multilib setup


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.