Я не знаю, сильно ли это помогает, но, похоже, вы все равно переосмысливаете свой вопрос.Ваш make-файл выглядит так, как будто он выполняет какое-то управление сборкой, по крайней мере, удаленно.(Обратите внимание, что вы можете написать свое правило с помощью шаблонов, но, похоже, вы стремитесь к чему-то другому.) Следующая перезапись вашего make-файла использует табличный инструментарий GNUmake , который выглядит как подходящий для ваших целей:
include gmtt/gmtt.mk
# Direct definition of the table in the file:
# define IMAGES :=
# 2
# http://farm1.static.flickr.com/93/238836380_a4db5526a9.jpg 281
# http://farm1.static.flickr.com/203/495381063_67fe69a64f.jpg 281
# http://farm1.static.flickr.com/93/238836380_a4db5526a9.jpg 285
# http://farm1.static.flickr.com/203/495381063_67fe69a64f.jpg 291
# http://farm3.static.flickr.com/2068/2218230147_c6559cd7ac.jpg 728
# http://farm2.static.flickr.com/1020/1459940961_6a54469e1e.jpg 279
# http://farm2.static.flickr.com/1140/1026808473_e4a2a76ded.jpg 285
# http://farm1.static.flickr.com/143/341257611_e730dfea3d.jpg 281
# http://farm3.static.flickr.com/2079/2226345732_0152a169fd.jpg 281
# http://farm3.static.flickr.com/2168/1834178819_e866ed3c04.jpg ???
# http://farm1.static.flickr.com/149/409910004_068c0fdec1.jpg ???
# endef
# Reading table from a file. File *must* be two columns (url, class) and nothing else - no comments either!
IMAGES := $(file < imagelist.txt)
$(info Processing file list:$(newline)$(IMAGES))
IMAGES := 2 $(IMAGES) # add the number of columns in front to make it a gmtt table
#Bash coloring
RED=\033[0;31m
GREEN=\033[0;32m
NC=\033[0m
#$1=URL $2=NAME $3=CONVERTED_PNG $4=CHECK $5=IDX
define IMAGE_BUILD_RULES
#download image
$2:
wget "$(strip $1)" -O $2
#convert
$3:$2
convert $2 -resize 224x224! $3
#check if correct class is identified. If not error
$4:$3 $(EXE)
@echo "Evaluating image $3"
./$(EXE) $3 | tee $4
@grep -q "Detected class: $(strip $5)" $4 && echo "$(GREEN)correctly identified image $2$(NC)" || (echo "$(RED)Did not correctly identify image $2$(NC)")
endef
#check if all images are classified correctly
check_all: $(foreach URL, $(IMAGE_URLS), check_$(basename $(notdir $(URL))))
@echo "$(GREEN)All correct!$(NC)"
# Just as a check for now, remove the whole $(info ...) if output too large
$(info Generating the following rules: $(newline)$(call map-select,1 2,$(IMAGES),t,$$(call IMAGE_BUILD_RULES,$$1,$$(notdir $$1),converted_$$(basename $$(notdir $$1)).png,check_$$(basename $$(notdir $$1)),$$2)))
# Rule definition - no need to call $(eval)
# Use the function `map-select` which applies a function on each selected line of a table. Syntax is $(call map-select,_column-numbers_,_table_,_where-clause_,_mapping-function_)
# We select columns one and two of the table. Where-clause is always true (t). Function is calling IMAGE_BUILD_RULES with the selected columns enumerated as $1,$2,$3,etc. - this parameter must be quoted ($$)
$(call map-select,1 2,$(IMAGES),t,$$(call IMAGE_BUILD_RULES,$$1,$$(notdir $$1),converted_$$(basename $$(notdir $$1)).png,check_$$(basename $$(notdir $$1)),$$2))
Ссылочный файл imagelist.txt
должен выглядеть следующим образом:
http://farm1.static.flickr.com/93/238836380_a4db5526a9.jpg 281
http://farm1.static.flickr.com/203/495381063_67fe69a64f.jpg 281
http://farm1.static.flickr.com/93/238836380_a4db5526a9.jpg 285
http://farm1.static.flickr.com/203/495381063_67fe69a64f.jpg 291
http://farm3.static.flickr.com/2068/2218230147_c6559cd7ac.jpg 728
http://farm2.static.flickr.com/1020/1459940961_6a54469e1e.jpg 279
http://farm2.static.flickr.com/1140/1026808473_e4a2a76ded.jpg 285
http://farm1.static.flickr.com/143/341257611_e730dfea3d.jpg 281
http://farm3.static.flickr.com/2079/2226345732_0152a169fd.jpg 281
http://farm3.static.flickr.com/2168/1834178819_e866ed3c04.jpg ???
http://farm1.static.flickr.com/149/409910004_068c0fdec1.jpg ???
Обратите внимание, что в ваших тестовых данных есть повторяющиеся URL-адреса.