Makefile 的几个语法坑

Makefile 和 Bash script 在使用的过程中有很多奇奇怪怪的坑,本文做一下纪录。 首先,有两个文件,一个叫 envs,里面定义了一个环境变量,比如 $ cat envs export GOPROXY="test.local" 第二个文件就是 Makefile ,假如我这样写 test: source ./envs echo ${GOPROXY} 所以,总的目标是,我希望在 Makefile 中导入另一个文件中事先定义好的环境变量。 然而这样的写法有很多问题。 source 命令找不到 加入直接运行 make, 很有可能你会看到这样的错误 $ make source ./envs make: source: Command not found 可是在 terminal 里面明明可以用 source 命令啊? 于是,第一个坑出现: source is a (non-POSIX) shell builtin, not an executable program on any conventional UNIX-like system. If source is changed to ., make changes its strategy; instead of trying to find and execute a program, it just passes the rule body to the system shell. ...

2021-09-26 · Me