私はこの解決策を見つけました。唯一の欠点は、問題のリストに存在しない特殊文字を選択する必要があることです。
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
# Pick a non-space character that NEVER appears in any word in $S. Here we use a comma.
XX := ,
S := This is very funny world and YOU is the funniest of all!
FIND := YOU
$(info Find $(FIND) in $(S))
S := $(XX)$(subst $(SPACE),$(XX),$(S))$(XX)
$(info S is $(S))
S := $(subst $(XX)$(FIND)$(XX),$(XX)$(FIND)$(SPACE),$(S))
$(info S is $(S))
S := $(firstword $(S))
$(info S is $(S))
S := $(subst $(XX),$(SPACE),$(S))
$(info S is $(S))
IDX = $(words $(S))
$(info IDX of $(FIND) is $(IDX))
# Combine into a giant function that can be called.
IDX = $(words $(subst $(XX),$(SPACE),$(firstword $(subst $(XX)$(2)$(XX),$(XX)$(2)$(SPACE),$(XX)$(subst $(SPACE),$(XX),$(1))$(XX)))))
$(info Index of $(FIND) is $(call IDX,$(S),$(FIND)))
# Define a function that returns the list element of the first argument that
# is at the same position as the second argument is in the third argument.
ATIDX = $(word $(call IDX,$3,$2),$1)
そのため、規則は次のようになります。
%.a: %.b
myprogram $(call, ATIDX,$(Y),$(*),$(X)) $(call ATIDX,$(Z),$(*),$(X)) $< $@
$(warning test $(call IDX,aaa bbb ccc ddd,eee))
そして$(warning test $(call IDX,aaa bbb ccc ddd,ddd))
どちらも4を返します。単語が気に入らない場合は5(インデックス外)を返す、やや良いバージョンを提供できます。IDX = $(words $(subst $(XX),$(SPACE),$(firstword $(subst $(XX)$(2)$(XX),$(SPACE)$(2)$(SPACE),$(XX)IDX***DUMMY$(XX)$(subst $(SPACE),$(XX),$(1))$(XX)))))