1From: Richard Purdie <richard.purdie@linuxfoundation.org>
2Subject: [PATCH 05/12] ltmain.in: Don't encode RATHS which match default linker paths
3
4We don't want to add RPATHS which match default linker search paths, they're
5a waste of space. This patch filters libtools list of paths to encoode and
6removes the ones we don't need.
7
8Libtool may be passed link paths of the form "/usr/lib/../lib" so normalize
9the paths before comparision.
10
11Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
12
13Upstream-Status: Submitted [https://lists.gnu.org/archive/html/libtool-patches/2021-10/msg00013.html]
14
15diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
16index 40cb94a..2fa055e 100644
17--- a/build-aux/ltmain.in
18+++ b/build-aux/ltmain.in
19@@ -7700,8 +7700,16 @@ EOF
20 		  esac
21 		fi
22 	      else
23-		eval flag=\"$hardcode_libdir_flag_spec\"
24-		func_append dep_rpath " $flag"
25+                # We only want to hardcode in an rpath if it isn't in the
26+                # default dlsearch path.
27+                func_normal_abspath "$libdir"
28+                libdir_norm=$func_normal_abspath_result
29+	        case " $sys_lib_dlsearch_path " in
30+	        *" $libdir_norm "*) ;;
31+	        *) eval flag=\"$hardcode_libdir_flag_spec\"
32+                   func_append dep_rpath " $flag"
33+                   ;;
34+	        esac
35 	      fi
36 	    elif test -n "$runpath_var"; then
37 	      case "$perm_rpath " in
38@@ -8434,8 +8442,16 @@ EOF
39 	      esac
40 	    fi
41 	  else
42-	    eval flag=\"$hardcode_libdir_flag_spec\"
43-	    func_append rpath " $flag"
44+            # We only want to hardcode in an rpath if it isn't in the
45+            # default dlsearch path.
46+            func_normal_abspath "$libdir"
47+            libdir_norm=$func_normal_abspath_result
48+	    case " $sys_lib_dlsearch_path " in
49+	    *" $libdir_norm "*) ;;
50+	    *) eval flag=\"$hardcode_libdir_flag_spec\"
51+               rpath+=" $flag"
52+               ;;
53+	    esac
54 	  fi
55 	elif test -n "$runpath_var"; then
56 	  case "$perm_rpath " in
57@@ -8489,8 +8505,14 @@ EOF
58 	      esac
59 	    fi
60 	  else
61-	    eval flag=\"$hardcode_libdir_flag_spec\"
62-	    func_append rpath " $flag"
63+            # We only want to hardcode in an rpath if it isn't in the
64+            # default dlsearch path.
65+	    case " $sys_lib_dlsearch_path " in
66+	    *" $libdir "*) ;;
67+	    *) eval flag=\"$hardcode_libdir_flag_spec\"
68+               func_append rpath " $flag"
69+               ;;
70+	    esac
71 	  fi
72 	elif test -n "$runpath_var"; then
73 	  case "$finalize_perm_rpath " in
74--
752.25.1
76
77