From feaa92e37dce4eb1d06ac399e6efad1b36bd3bfb Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Mon, 8 Oct 2018 18:39:00 +0200 Subject: ptx/in-path: rewrite in make This is a lot faster than starting a shell. Signed-off-by: Michael Olbrich --- rules/pre/get_alternative.make | 20 +++++++++++++++++++- scripts/libptxdist.sh | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 # -- cgit v1.2.3