微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将bash shellvariables传递给Makefile?

在我的env.sh里面:

export BIN="/home/user/stuff"

在我的Makefile里面:

等等等等

TARGET = filetobeinstalled

等等等等

Bash:按字节区分大小写的sorting命令或使用pythonsorting命令sorting文本文件

Bash cd命令自动完成自定义别名

Bash命令:variables和别名之间有什么区别?

从shell脚本捕获值,并在不使用subprocess的情况下在Python中使用

在Windows上使用64位Git Bash的Shell脚本

install: cp $(TARGET) $(BIN)

在运行make install之前,我在我的bash shell中定义了env vars: source /home/user/env.sh 。 我仔细检查,这些环境variables正在工作,通过在运行Makefile的shell中inputecho $BIN ,这给了我适当的响应( /home/user/stuff )。

所以,我试图将在shell提示符处定义的$BINvariables与source一起传递给引用$BIN Makefile中 ,但是没有定义它。 不幸的是,当我运行make install ,它并没有从输出中看到$BIN

$ source /home/user/env.sh $ echo $BIN $ /home/user/stuff $ make install make[1]: Entering directory `/home/user/stufftoinstall' cp filetobeinstalled cp: missing destination file operand after `filetobeinstalled' Try `cp --help' for more information. make[1]: *** [install] Error 1

在安装了cp filetobeinstalled的行上,我希望它会在运行make install之前获取使用source设置的env vars,以便行应该读取cp filetobeinstalled /home/user/stuff代替,但是不行。

我发现类似的post和散布在互联网上的点点滴滴,但是对于上述问题没有任何确定性和/或迄今没有任何工作。 希望这不是太明显,但对我来说容易,因为我绝对是一个Makefile的Nubile。

干杯

创build一个variables,其中包含直接在之前运行的命令的标准输出中的所有数字

在bash中search和回显一部分string

如何检查手册页是否存在?

BASH嵌套stream程replace

脚本和C二进制程序之间的竞争条件

确保导出在env文件中定义的变量,只有环境变量传递给子进程,而不是shell本地进程。 而且我会让这个名字变长(就像在下面的例子中),以避免可能的冲突。

export BINDIR=/bin/path ;# will do BINDIR=/bin/path; export BINDIR ;# will do as well BINDIR=/bin/path make install ;# even this willd make BINDIR=/bin/path install ;# and this,though using a different mechanism

加成:

如果你添加下面的目标,那么你可以运行make var=whatever printvar ,它会打印变量的值。 它可能有助于调试它。

.PHONY: printvar printvar: @echo "[$(var)]=[$($(var))]"

另外,如果使用-np运行make ,它将以-np运行模式运行,并将打印所有已定义的变量,因此您可以make -np install | fgrep -w BIN make -np install | fgrep -w BIN ,看看你有什么。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐