Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas De Schampheleire <patrickdepinguin@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCHv2 05/10] toolchain helpers: introduce simplify_symlink
Date: Sat,  4 Feb 2017 14:42:09 +0100	[thread overview]
Message-ID: <20170204134214.20592-6-patrickdepinguin@gmail.com> (raw)
In-Reply-To: <20170204134214.20592-1-patrickdepinguin@gmail.com>

From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

The external toolchain logic flattens the directory layout in the staging
directory.  Regardless of the number of levels present in the extracted
toolchain, libraries are always copied to lib/ and usr/lib/, and directory
symbolic links are provided to make the original paths available as well.

Due to this, the same library may be reachable through a number of paths:
one path without any symbolic link, and one or more paths using directory
symlinks.

Using a direct path in a symlink destination is generally preferred because
it is clearer, but it is also more robust against accidental removal of an
intermediate directory symlink.

Introduce a helper function to simplify a symlink's destination to such a
direct path. This function will be used in a subsequent patch.

Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
---
v2: new patch

 toolchain/helpers.mk | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index 1e775ea..0acbb52 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -457,3 +457,30 @@ $$( \
 	printf "$$prefix" ;\
 )
 endef
+
+# Replace the destination of a symbolic link with a simpler version
+# For example,
+#     usr/lib/libfoo.so -> ../../lib32/libfoo.so.1
+# becomes
+#     usr/lib/libfoo.so -> ../../lib/libfoo.so.1
+# since 'lib32' is a symlink to 'lib'.
+#
+# Likewise,
+#     usr/lib/octeon2/libbar.so -> ../../../lib32/octeon2/libbar.so.1
+# becomes
+#     usr/lib/octeon2/libbar.so -> ../../lib/libbar.so.1
+# assuming lib32->lib and lib/octeon2->lib.
+#
+# $1: symlink
+# $2: base path
+define simplify_symlink
+( \
+	FULL_SRC="$$(readlink -f $$(dirname $1))/$$(basename $1)" ; \
+	FULL_DEST="$$(readlink -f $1)" ; \
+	FULL_BASE="$$(readlink -f $2)" ; \
+	REL_SRC="$${FULL_SRC#$${FULL_BASE}/}" ; \
+	REL_DEST="$${FULL_DEST#$${FULL_BASE}/}" ; \
+	DOTS="$(call relpath_prefix,$${REL_SRC})" ; \
+	ln -sf "$${DOTS}$${REL_DEST}" "$${FULL_SRC}" ; \
+)
+endef
-- 
2.10.2

  parent reply	other threads:[~2017-02-04 13:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-04 13:42 [Buildroot] [PATCHv2 00/10] toolchain: improvements to copy_toolchain_sysroot and copy_toolchain_lib_root Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 01/10] toolchain-external: clarify rsync excludes in copy_toolchain_sysroot Thomas De Schampheleire
2017-02-07 10:26   ` Romain Naour
2017-02-07 11:39     ` Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 02/10] toolchain-external: handle ld.so fixups centrally Thomas De Schampheleire
2017-02-07 11:04   ` Romain Naour
2017-02-04 13:42 ` [Buildroot] [PATCHv2 03/10] toolchain helpers: introduce function relpath_prefix Thomas De Schampheleire
2017-02-07 11:20   ` Romain Naour
2017-02-04 13:42 ` [Buildroot] [PATCHv2 04/10] toolchain-external: cover multilib toolchains with lib/<variant> layout Thomas De Schampheleire
2017-02-04 13:42 ` Thomas De Schampheleire [this message]
2017-02-04 13:42 ` [Buildroot] [PATCHv2 06/10] toolchain-external: simplify previously-broken symbolic links Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 07/10] toolchain: copy_toolchain_lib_root: remove unused variable LIBDIR Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 08/10] toolchain: copy_toolchain_lib_root: clarify logic Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 09/10] toolchain: copy_toolchain_lib_root: clarify input parameter Thomas De Schampheleire
2017-02-04 13:42 ` [Buildroot] [PATCHv2 10/10] toolchain: copy_toolchain_lib_root: copy symlinks instead of recreating them Thomas De Schampheleire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170204134214.20592-6-patrickdepinguin@gmail.com \
    --to=patrickdepinguin@gmail.com \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox