首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Makefile中的嵌套ifndef

Makefile中的嵌套ifndef
EN

Stack Overflow用户
提问于 2017-03-20 17:45:19
回答 1查看 1.7K关注 0票数 0

在我的Makefile中,我尝试通过不同的方式来编程地在目标中设置一个环境变量。但是,每个ifndef中的每个语句似乎每次都被执行。我怎么才能避免这种情况发生呢?

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-20 19:49:49

您试图使用make函数计算make变量REPOSITORY_URI的值,但您错误地认为计算make变量的值需要make目标和食谱。

repository菜谱的实际含义与您的想法有很大的不同,解释它的意义将是一个很大的偏离,因为不需要目标或菜谱。要做你想要做的事,只需写:

代码语言:javascript
复制
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的值,用于一个或多个目标。

代码语言:javascript
复制
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制作文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42910490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档