Re: [PATCH 05/12] ltmain.in: Don't encode RATHS which match default linker paths

Mike Frysinger <[email protected]> Tue, 16 Jan 2024 21:10:11 -0500
Newsgroups gmane.comp.gnu.libtool.patches
Message-ID <Zac3A58JEleq3n0W@vapier>
On 25 Oct 2021 15:33, Richard Purdie wrote:
> We don't want to add RPATHS which match default linker search paths, they're
> a waste of space. This patch filters libtools list of paths to encoode and
> removes the ones we don't need.
> 
> Libtool may be passed link paths of the form "/usr/lib/../lib" so normalize
> the paths before comparision.

add a bit more detail to the commit message, add the changelog, and fix the
typo in the subject line ("RATHS").

> --- a/build-aux/ltmain.in
> +++ b/build-aux/ltmain.in
> @@ -7672,8 +7672,16 @@ EOF
>  		  esac
>  		fi
>  	      else
> -		eval flag=\"$hardcode_libdir_flag_spec\"
> -		func_append dep_rpath " $flag"
> +                # We only want to hardcode in an rpath if it isn't in the
> +                # default dlsearch path.
> +                func_normal_abspath "$libdir"
> +                libdir_norm=$func_normal_abspath_result
> +	        case " $sys_lib_dlsearch_path " in
> +	        *" $libdir_norm "*) ;;
> +	        *) eval flag=\"$hardcode_libdir_flag_spec\"
> +                   func_append dep_rpath " $flag"
> +                   ;;
> +	        esac

this is a non-trivial amount of boiler plate that you're pasting in here.
can we introduce a func to make this more readable ?  something like this
untested code.

# func_is_in_list <ELEMENT> <LIST> [separator]
# blah blah blah
func_is_in_list ()
{
    case "${3:- }$2${3:- }" in
    *"${3:- }$1${3:- }"*) return 0;;
    esac
    return 1
}

then you could write:
  func_normal_abspath "$libdir"
  if ! func_is_in_list "$func_normal_abspath_result" "$sys_lib_dlsearch_path"; then
    eval flag=\"$hardcode_libdir_flag_spec\"
    func_append dep_rpath " $flag"
  fi

and there's 2 other places where $sys_lib_dlsearch_path is checked that could
be converted over to this helper.
-mike
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEuQK1JxMl+JKsJRrUQWM7n+g39YEFAmWnNwMACgkQQWM7n+g3
9YEAKw//TO/DL/rd1AoFwewX5Md8UFQZk13pcQj5HagXmjcM85vS5WRDFRzCHwc/
mS/p780yr8IpwdLtqx8P6vKaOfFczNH6m+tgSihZITpMSidQYOOLrZ1LSsLrfZ1/
VA1yaZR6oQc7ZWj5CQcWyPDfV1VbVfjCMBl03zEQRP/Ss+AdGykTDawA9LYHPRAF
EhJwVW3NGPLOEOJ3nshIn1zSDXFNfOMT1BnSFFooqvpByseEEQK58FPWoQseagBO
dV/MFjanmvYeqcDFgSRjUMCUg86PDF5PQBFds/mYDlgQM46Zp4QB0SONjUT2gq7R
tZBS4/7A93rUveyXfXRRG+AmAoELHWIliAU+TSsgTffOoLXAhIMHU8NloF+2V6MW
+bjDNbfzxvtOylKCs5DVWeiOIkdr6ysjOKfG7pc1B3rQ7xR9MNsIWsXIpGWxDPoI
annUiv3znkZwhuFHWu4qstD5QaSUmHlWyncFx77CH8WieKQJlqAMq6IfbDotO+DB
pwQzSBFp0PkWIt+kzZ+2ADCq71KiT//Nktr58yBA5kVXYzbSDVqagxF2Ts3TW0Bi
+LdtQ2X7QqtHSD6YGJevcfZwf42681+mUK/+vRl/+TQcmM+KrLPZ44EUYOQy5Qqb
ty7Vq7kOp8vZQfxk5Cw+kCrBuK7YTEE8GRFP5ToDGuERXRX02mI=
=zobB
-----END PGP SIGNATURE-----