--print-target-path may return a path with (escaped) spaces. We'll use that path with $(wildcard ...), that's fine. But then we use the outcome with $(foreach ...) and there things fail badly and there's nothing to do about it.
Therefore we a) try to avoid --print-target-path in the first place and b) explicitly bail out if we end up with spaces.
endif
ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),)
- TARGET_PATH := $(shell $(CL) --print-target-path)
+ ifdef CC65_HOME
+ TARGET_PATH = $(CC65_HOME)/target
+ else
+ TARGET_PATH := $(if $(wildcard ../target),../target,$(shell $(CL) --print-target-path))
+ endif
+
+ ifneq ($(words $(TARGET_PATH)),1)
+ $(error No space chars allowed in "$(TARGET_PATH)")
+ endif
EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*)
MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*)