diff mbox

[PATCHv2,03/10] toolchain helpers: introduce function relpath_prefix

Message ID 20170204134214.20592-4-patrickdepinguin@gmail.com
State Superseded
Headers show

Commit Message

Thomas De Schampheleire Feb. 4, 2017, 1:42 p.m. UTC
From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>

The helper function copy_toolchain_sysroot has some logic to transform a
path into a number of '../' components based on the depth of that path.

As this same logic will be needed in another place in a subsequent patch,
extract it into a separate helper relpath_prefix.

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

 toolchain/helpers.mk | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

Comments

Romain Naour Feb. 7, 2017, 11:20 a.m. UTC | #1
Hi Thomas,

Le 04/02/2017 à 14:42, Thomas De Schampheleire a écrit :
> From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> The helper function copy_toolchain_sysroot has some logic to transform a
> path into a number of '../' components based on the depth of that path.
> 
> As this same logic will be needed in another place in a subsequent patch,
> extract it into a separate helper relpath_prefix.
> 
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
> v2: no changes
> 
>  toolchain/helpers.mk | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
> index 6720629..ba14b38 100644
> --- a/toolchain/helpers.mk
> +++ b/toolchain/helpers.mk
> @@ -121,11 +121,7 @@ copy_toolchain_sysroot = \
>  			cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
>  		fi ; \
>  		mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \
> -		relpath="./" ; \
> -		nbslashs=`printf $${ARCH_SUBDIR} | sed 's%[^/]%%g' | wc -c` ; \
> -		for slash in `seq 1 $${nbslashs}` ; do \
> -			relpath=$${relpath}"../" ; \
> -		done ; \
> +		relpath="$(call relpath_prefix,$${ARCH_SUBDIR})./" ; \
>  		ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \
>  		echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \
>  	fi ; \
> @@ -424,3 +420,22 @@ check_toolchain_ssp = \
>  gen_gdbinit_file = \
>  	mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \
>  	echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit
> +
> +# Given a path, determine the relative prefix (../) needed to return to the
> +# root level. Note that the last component is treated as a file component; use a
> +# trailing slash to force treating it as a directory. Examples:
> +#     relpath_prefix(lib32) = ""
> +#     relpath_prefix(lib32/octeon2) = "../"
> +#     relpath_prefix(lib32/octeon2/) = "../../"
> +#
> +# $1: input path
> +define relpath_prefix
> +$$( \
> +	prefix="" ; \
> +	nbslashs=`printf $1 | sed 's%[^/]%%g' | wc -c` ; \
> +	for slash in `seq 1 $${nbslashs}` ; do \
> +		prefix=$${prefix}"../" ; \
> +	done ; \
> +	printf "$$prefix" ;\

missing space after ";"

Best regards,
Romain


> +)
> +endef
>
diff mbox

Patch

diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index 6720629..ba14b38 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -121,11 +121,7 @@  copy_toolchain_sysroot = \
 			cp -a $${SYSROOT_DIR}/usr/include $(STAGING_DIR)/usr ; \
 		fi ; \
 		mkdir -p `dirname $(STAGING_DIR)/$${ARCH_SUBDIR}` ; \
-		relpath="./" ; \
-		nbslashs=`printf $${ARCH_SUBDIR} | sed 's%[^/]%%g' | wc -c` ; \
-		for slash in `seq 1 $${nbslashs}` ; do \
-			relpath=$${relpath}"../" ; \
-		done ; \
+		relpath="$(call relpath_prefix,$${ARCH_SUBDIR})./" ; \
 		ln -s $${relpath} $(STAGING_DIR)/$${ARCH_SUBDIR} ; \
 		echo "Symlinking $(STAGING_DIR)/$${ARCH_SUBDIR} -> $${relpath}" ; \
 	fi ; \
@@ -424,3 +420,22 @@  check_toolchain_ssp = \
 gen_gdbinit_file = \
 	mkdir -p $(STAGING_DIR)/usr/share/buildroot/ ; \
 	echo "set sysroot $(STAGING_DIR)" > $(STAGING_DIR)/usr/share/buildroot/gdbinit
+
+# Given a path, determine the relative prefix (../) needed to return to the
+# root level. Note that the last component is treated as a file component; use a
+# trailing slash to force treating it as a directory. Examples:
+#     relpath_prefix(lib32) = ""
+#     relpath_prefix(lib32/octeon2) = "../"
+#     relpath_prefix(lib32/octeon2/) = "../../"
+#
+# $1: input path
+define relpath_prefix
+$$( \
+	prefix="" ; \
+	nbslashs=`printf $1 | sed 's%[^/]%%g' | wc -c` ; \
+	for slash in `seq 1 $${nbslashs}` ; do \
+		prefix=$${prefix}"../" ; \
+	done ; \
+	printf "$$prefix" ;\
+)
+endef