+ ifdef CC65_HOME
+ TARGET_PATH = $(CC65_HOME)/target
+ else
+ TARGET_PATH := $(if $(wildcard ../target),../target,$(shell $(CL) --print-target-path))
+ endif
+
+ # If TARGET_PATH contains spaces then it is presumed to contain escaped spaces. GNU make
+ # has very limited support for paths containing spaces. $(wildcard) is the only function
+ # that is aware of escaped spaces. However, $(wildcard) never returns paths with escaped
+ # spaces !!! So if it e.g. finds 4 files in a path with 2 spaces then one ends up with a
+ # return value consisting of 12 plain words :-((
+ #
+ # Fortunately we can work around that behaviour here because we know that the files we
+ # are looking for have known extensions. So we can $(filter) the in our example above 12
+ # words for file extensions so we come up with 4 path fragments. Then we remove those
+ # path fragments with $(notdir) from the file names.
+ #
+ # So far so good. But here we want to process files from different paths in a single
+ # recipe further down below and therefore want to prepend the paths to the files with
+ # $(addprefix). However, $(foreach) isn't aware of escaped spaces (only $(wildcard) is).
+ # Therefore, we need to replace the spaces with some other character temporarily in order
+ # to have $(foreach) generate one invocation per file. We use the character '?' for that
+ # purpose here, just because it is known to not be part of file names.
+ #
+ # Inside the recipe generated per file we then replace the '?' again with a space. As we
+ # want to be compatible with cmd.exe for execution we're not using an escaped space but
+ # rather double-quote the whole path.
+ #
+ # Note: The "strange" $(wildcard) further down below just serves the purpose to unescape
+ # spaces for cmd.exe. This could have as well been done with another $(subst).
+
+ SUBST_TARGET_PATH := $(subst \$(SPACE),?,$(TARGET_PATH))