summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-10-08 18:39:00 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2018-10-09 08:47:13 +0200
commitfeaa92e37dce4eb1d06ac399e6efad1b36bd3bfb (patch)
treefa6b5fce14338faaf0df040563ed9f0ba0c37c76
parentf4d2979ad7b356454233a5c80b9ee6c369f43839 (diff)
downloadptxdist-feaa92e37dce4eb1d06ac399e6efad1b36bd3bfb.tar.gz
ptxdist-feaa92e37dce4eb1d06ac399e6efad1b36bd3bfb.tar.xz
ptx/in-path: rewrite in make
This is a lot faster than starting a shell. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--rules/pre/get_alternative.make20
-rw-r--r--scripts/libptxdist.sh2
2 files changed, 21 insertions, 1 deletions
diff --git a/rules/pre/get_alternative.make b/rules/pre/get_alternative.make
index f8043639f..c93499162 100644
--- a/rules/pre/get_alternative.make
+++ b/rules/pre/get_alternative.make
@@ -11,7 +11,25 @@
ptx/get-alternative = $(shell ptxd_get_alternative $(1) $(2) && echo $$ptxd_reply)
ptx/get_alternative = $(error ptx/get_alternative has been renamed to ptx/get-alternative)
-ptx/in-path = $(shell ptxd_in_path $(1) $(2) && echo $$ptxd_reply)
+#
+# This must produce the same results as ptxd_in_path()
+# Fallback to the shell implementation for the complex case
+#
+# Strip whitespaces introduced by the multiline macros
+define ptx/in-path3
+$(if $(strip $(1)),$(strip $(2)),$(strip $(3)))
+endef
+# fallback to shell if a relative path is found
+define ptx/in-path2
+$(call ptx/in-path3,
+$(filter-out /%,$(3)),
+$(shell p='$($(strip $(1)))' ptxd_in_path p $(2) && echo $$ptxd_reply),
+$(firstword $(wildcard $(addsuffix /$(strip $(2)),$(3)))))
+endef
+# create a path ist from the variable with ':' separated paths
+define ptx/in-path
+$(call ptx/in-path2,$(1),$(2),$(subst :,$(ptx/def/space),$($(strip $(1)))))
+endef
ptx/in-platformconfigdir = $(if $(strip $(1)),$(shell ptxd_in_platformconfigdir $(1)))
diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh
index fcadf24bc..c8f652fa9 100644
--- a/scripts/libptxdist.sh
+++ b/scripts/libptxdist.sh
@@ -379,6 +379,8 @@ export -f ptxd_get_path
#
# ptxd_in_path - look for files and/or dirs
#
+# Note: the make implemenation in ptx/in-path must produce the same result.
+#
# $1 variable name with paths separated by ":"
# $2 filename to find within these paths
#