Makefile

常见问题

Shell 与工作目录

Makefile 的每一行都是一个 sub shell. 因此,不能在 Makefile 中配置环境变量 ( 单独编写 .sh 进行配置 )。如果需要切换工作目录,则使用 && 或 ; 进行连接。

一般地,忽略错误并执行连续命令

1
2
3
4
5
6
7
8
9
10
11
phony:
-cmd_1
-cmd_2 ; cmd_3
````
注意:在 .sh 中 export 环境变量的方式也是无效的,都在自己的独立 shell 中执行。只有通过 source 方式执行脚本才能让命令在当前 shell 中生效。

```bash
# set-env.sh
export YOUR_PATH=$YOUR_PATH:<path>
# unset-env.sh
unset YOUR_PATH