如何在makefile中获取shell环境变量? [英] How to get a shell environment variable in a makefile?

查看:666
本文介绍了如何在makefile中获取shell环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在外壳中,当我输入

echo $demoPath

它打印

/usr/local/demo

如何在生成文件中获取此变量$demoPath的值?

How can I get the value of this variable $demoPath in a makefile?

推荐答案

如果已导出环境变量:

export demoPath=/usr/local/demo

您可以简单地在makefile中按名称引用它(make导入您已设置的所有环境变量):

you can simply refer to it by name in the makefile (make imports all the environment variables you have set):

DEMOPATH = ${demoPath}    # Or $(demoPath) if you prefer.

如果您还没有导出环境变量,则除非您导出了环境变量,否则除非在命令行中明确传递它,否则无法访问它.

If you've not exported the environment variable, it is not accessible until you do export it, or unless you pass it explicitly on the command line:

make DEMOPATH="${demoPath}" …

如果使用的是C Shell派生,请用setenv demoPath /usr/local/demo代替export命令.

If you are using a C shell derivative, substitute setenv demoPath /usr/local/demo for the export command.

这篇关于如何在makefile中获取shell环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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