prereq: merge common cases in SetupHostCommand
authorJonas Gorski <jonas.gorski@gmail.com>
Wed, 23 Aug 2023 07:47:57 +0000 (09:47 +0200)
committerJonas Gorski <jonas.gorski@gmail.com>
Sat, 26 Aug 2023 12:00:36 +0000 (14:00 +0200)
Now that most cases do the same thing in SetupHostCommand, merge them
together into one. To allow moving the generic symlink check, invert the
check and let it check for relative links by matching on link targets
that do not start with a slash.

This then allows us to also drop the absolute link case, shortening the
case statement further.

This reorders the check to

* if it is not a symlink, do not change it
* if it is a symlink and it points to the found command, do not change it
* if it is a symlink with a relative path, do not change it
* else, update/replace it

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
include/prereq.mk

index a4a07c223fa2653ec17ff80bf10a3fd1954c893a..1039c5540c6a01a17d61851a7aa2f334d8eb1df4 100644 (file)
@@ -107,15 +107,9 @@ define SetupHostCommand
                        bin="$$$$$$$$(command -v "$$$$$$$${cmd%% *}")"; \
                        if [ -x "$$$$$$$$bin" ] && eval "$$$$$$$$cmd" >/dev/null 2>/dev/null; then \
                                case "$$$$$$$$(ls -dl -- $(STAGING_DIR_HOST)/bin/$(strip $(1)))" in \
-                                       *" -> $$$$$$$$bin"*) \
-                                               [ -x "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0 \
-                                               ;; \
-                                       "-"*) \
-                                               [ -x "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0 \
-                                               ;; \
-                                       *" -> /"*) \
-                                               ;; \
-                                       *" -> "*) \
+                                       "-"* | \
+                                       *" -> $$$$$$$$bin"* | \
+                                       *" -> "[!/]*) \
                                                [ -x "$(STAGING_DIR_HOST)/bin/$(strip $(1))" ] && exit 0 \
                                                ;; \
                                esac; \