从控制台读取Makefile变量(如果未设置) [英] Read Makefile variable from console if not set

查看:124
本文介绍了从控制台读取Makefile变量(如果未设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新一个Makefile,该文件可以从外部来源访问某些资源,即存在以下形式的规则

I'm updating a Makefile that accesses some resources from an external source, i.e. there is a rule of the form

$(External)/% : 
    cvs up $@

...对于不受限制的资源,它可以按预期工作.现在,功能发生了变化,外部资源需要更复杂的登录,因此规则已更改为与此不太相似的地方:

...which works as expected for unrestricted resources. Now, there has been a feature drift, and the external resources requires a more complex login, so the rule has changed to something not too different from this:

$(External)/% : 
    cvs -d :pserver:$(CVSUSER)@cvs-server up $@

...这使得规则取决于变量CVSUSER.强制执行此操作的快速简便方法是,如果未定义,则会中止并显示一条有用的错误消息.但这没什么好玩的,我想从控制台读取CVSUSER变量,如果它在需要的时候没有被设置的话.我天真地尝试过

...which makes the rule dependent on the variable CVSUSER. The quick and easy way to enforce this would be to abort with a helpful error message if it's undefined. But that's no fun, I'd like to read the variable CVSUSER from console if it's unset by the time it's needed. I naively tried

CVSUSER ?= $(shell read -p "User name: ")

但是那显然是行不通的:)您将如何去做呢?

but that obviously does not work :) How would you go about doing this?

推荐答案

当然,我需要一个简单的扩展变量,而不是递归变量.这样,我可以让变量依赖于其自身,并使用普通的Make实用程序有条件地对其进行设置.条件赋值隐式创建一个普通的(递归)赋值,所以我需要做任何一个

Ah, of course, I need a simply expanded variable, not a recursive one. That way I can let the variable depend on itself and use normal Make utilities to conditionally set it. The conditional assignment implicitly creates a normal (recursive) one, so I need to do either

CVSUSER := $(shell if [ -z $(CVSUSER) ] ; then read -p "User name: " REPLY ; echo $$REPLY ; fi )

ifndef CVSUSER
    CVSUSER := $(shell then read -p "User name: " REPLY ; echo $$REPLY ; fi )
endif

这篇关于从控制台读取Makefile变量(如果未设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆