shell - 如何在makefile中获取shell环境变量?

标签 shell makefile

当我进入时在 shell 中

echo $demoPath

打印

/usr/local/demo

如何在 makefile 中获取此变量 $demoPath 的值?

最佳答案

如果您已导出环境变量:

export demoPath=/usr/local/demo

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

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

如果您尚未导出环境变量,则在导出之前无法访问它,或者除非您在命令行上显式传递它:

make DEMOPATH="${demoPath}" …

如果您使用的是 C shell 衍生版本,请将 setenv demoPath/usr/local/demo 替换为 export 命令。

关于shell - 如何在makefile中获取shell环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28890634/

相关文章:

linux - 使用 awk 从文件中检索一组特定的字符串

regex - 使用 sed 在两个模式之间替换多个惰性字符串

c++ - makefile: cpp + cu 文件 - undefined reference 错误

linux - 如何编写可以区分 Intel OS X 和 Linux 的 Makefile?

variables - Makefile 规则使用自动变量 $^ 无依赖

linux - 传递的参数小于 1 时出错,我在做什么?

c - 如何获取 C 语言中的本地 shell 变量?

node.js - Imagemagick/Shell/子进程 NodeJS

debugging - 使看不到带有%标记的规则

macos - 使用 C++11 在 g++ 中编译库