【问题标题】:makefile:: *** prerequisites cannot be defined in recipes. Stopmakefile:: *** 无法在配方中定义先决条件。停止
【发布时间】:2021-11-20 16:08:25
【问题描述】:

我正在实施以下帖子中的脚本。由于它有点旧,我想打开这个新线程,因为我在运行 makefile 时遇到了问题。

基本上我已经创建了一个顶级 makefile,它将在子文件夹中编译一组 docker 图像。

makefile - build mulitple files with multiple targets

# Assuming each subdirectory containins a Dockerfile
IMAGES  := $(patsubst %/,%,$(dir $(wildcard */Dockerfile)))
BUILD_TARGS = $(patsubst %,build_%,$(IMAGES))
TEST_TARGS = $(patsubst %,test_%,$(IMAGES))
PUSH_TARGS = $(patsubst %,push_%,$(IMAGES))

VERSION := 1 # $(shell git rev-parse --short=12 --verify HEAD)
DOCKER_REPO_URL := david.io/reponame

define docker_build =
build_$(1):
    @echo "Building $(1)"
    #docker build -t $(1) --force-rm $(1)
endef

define docker_test =
test_$(1):
    @echo "Testing $(1)"
    #docker inspect $(1)
    #docker run --rm $(1) help
endef

define docker_push =
push_$(1):
    @echo "Pushing $(1)"
    #docker tag $(1) $(DOCKER_REPO_URL):$(1)-$(VERSION)
    #docker push $(DOCKER_REPO_URL):$(1)-$(VERSION)
    #docker tag $$@ $(DOCKER_REPO_URL):$(1)
    #docker push $(DOCKER_REPO_URL):$(1)
endef

.PHONY: all build test release clean $(IMAGES) $(BUILD_TARGS) $(TEST_TARGS) $(PUSH_TARGS)

all: build test release

build: $(BUILD_TARGS)
    $(foreach image,$(IMAGES),$(eval $(call docker_build,$(image))))

#test: $(TEST_TARGS)
#    $(foreach image,$(IMAGES),$(eval $(call docker_test,$(image))))

#release: $(PUSH_TARGS)
#    $(foreach image,$(IMAGES),$(eval $(call docker_push,$(image))))

我有以下错误:

makefile:37: *** prerequisites cannot be defined in recipes.  Stop.

【问题讨论】:

标签: makefile gnu-make


【解决方案1】:

正如错误所说,您无法从配方中评估整个规则。

您需要在 make 解析 makefile 时执行此操作。

删除 foreach 循环之前的 TAB 字符,使它们不在配方中。

【讨论】:

  • 感谢删除标签解决了问题!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2016-08-18
  • 2013-04-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多