在我的Makefile中,我尝试通过不同的方式来编程地在目标中设置一个环境变量。但是,每个ifndef中的每个语句似乎每次都被执行。我怎么才能避免这种情况发生呢?
repository:
ifndef REPOSITORY_URI
@$(eval REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr describe-repositories --repository-names $(APP) | jq -r '.repositories[0].repositoryUri'"))
ifndef REPOSITORY_URI
@$(eval REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr create-repository --repository-name $(APP) | jq -r '.repositories[0].repositoryUri'"))
ifndef REPOSITORY_URI
echo "Could not establish link to AWS Repository, please ensure your credentials are set and try again"
endif
endif
endif发布于 2017-03-20 19:49:49
您试图使用make函数计算make变量REPOSITORY_URI的值,但您错误地认为计算make变量的值需要make目标和食谱。
repository菜谱的实际含义与您的想法有很大的不同,解释它的意义将是一个很大的偏离,因为不需要目标或菜谱。要做你想要做的事,只需写:
ifndef REPOSITORY_URI
REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr describe-repositories --repository-names $(APP) | jq -r '.repositories[0].repositoryUri'")
ifndef REPOSITORY_URI
REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr create-repository --repository-name $(APP) | jq -r '.repositories[0].repositoryUri'")
ifndef REPOSITORY_URI
$(error "Could not establish link to AWS Repository, please ensure your credentials are set and try again")
endif
endif
endif 在生成文件中的位置,您希望将值赋值给REPOSITORY_URI (或失败)。
这本身就构成了一个没有目标的makefile。但是,您可能想要在食谱中使用REPOSITORY_URI的值,用于一个或多个目标。
ifndef REPOSITORY_URI
REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr describe-repositories --repository-names $(APP) | jq -r '.repositories[0].repositoryUri'")
ifndef REPOSITORY_URI
REPOSITORY_URI := $(shell bash -c "aws --region $(REGION) ecr create-repository --repository-name $(APP) | jq -r '.repositories[0].repositoryUri'")
ifndef REPOSITORY_URI
$(error "Could not establish link to AWS Repository, please ensure your credentials are set and try again")
endif
endif
endif
.PHONY: all
all:
echo REPOSITORY_URI=$(REPOSITORY_URI) 我推荐GNU制作文档
https://stackoverflow.com/questions/42910490
复制相似问题