В общем ответ я придумал:
TEST_ARRAY = AA BB
K := $(foreach myTest,$(TEST_ARRAY),\
$(if $(filter AA,$(myTest)),\
$(eval $(myTest) := match),\
$(eval $(myTest) := mismatch)))
$(info "AA: ${AA}")
$(info "BB: ${BB}")
Выходом является:
"AA: match"
"BB: mismatch"
ответ на мой более конкретный вопрос довольно больше - рабочий фрагмент кода, как это:
#on widows
DEVNUL := NUL
WHICH := where
#on linux
#DEVNUL := /dev/null
#WHICH := which
# set path to be searched when command is not found in system PATH
GNU_PATH := c:\NSS\GNU_Tools_ARM_Embedded\5.4 2016q3\bin2
# optionally set command prefix - for example all your tools are not called "gcc" but "arm-gcc" so you would fill here "arm-"
GNU_PREFIX := arm-none-eabi-
# set command suffix - for example on windows all executable files have suffix ".exe"
GNU_SUFFIX := .exe
# escape spaces in path because make $(wildcard) can not handle them :(
empty :=
space := $(empty) $(empty)
GNU_PATH_ESCAPED := $(subst $(space),\ ,$(GNU_PATH))
# define used tool-chain commands
CC := gccx
AS := as
AR := ar
LD := ld
NM := nm
OBJDUMP := objdump
OBJCOPY := objcopy
SIZE := size
# detect if tool-chain commands are installed and fill correct path (prefer system PATH, then try to find them in suggested GNU_PATH)
# if not found on neither system path nor on user provided GNU_PATH then early error is reported to user
EXECUTABLES = CC AS AR LD NM OBJDUMP OBJCOPY SIZE
$(foreach myTestCommand,$(EXECUTABLES),\
$(if $(shell ${WHICH} ${GNU_PREFIX}$($(myTestCommand)) 2>${DEVNUL}),\
$(eval $(myTestCommand) := ${GNU_PREFIX}$($(myTestCommand))),\
$(if $(wildcard $(GNU_PATH_ESCAPED)\${GNU_PREFIX}$($(myTestCommand))$(GNU_SUFFIX)),\
$(eval $(myTestCommand) := '$(GNU_PATH)/${GNU_PREFIX}$($(myTestCommand))$(GNU_SUFFIX)'),\
$(error "Can not find tool ${GNU_PREFIX}$($(myTestCommand))$(GNU_SUFFIX), either make in in your system PATH or provide correct path in variable GNU_PATH"))))
# just print what tools will be used
$(foreach myTestCommand,$(EXECUTABLES),\
$(info found tool $($(myTestCommand))))
default:
@$(CC) --version
в моем тестовом ящике У меня есть все инструменты на моем пути, кроме gccx
, который расположенный в моей папке пользователя, представленной в GNU_PATH
.
found tool 'c:\NSS\GNU_Tools_ARM_Embedded\5.4 2016q3\bin2/arm-none-eabi-gccx.exe'
found tool arm-none-eabi-as
found tool arm-none-eabi-ar
found tool arm-none-eabi-ld
found tool arm-none-eabi-nm
found tool arm-none-eabi-objdump
found tool arm-none-eabi-objcopy
found tool arm-none-eabi-size