cd .. 在 Makefile 中没有 ONESHELL 也能工作

cd.. works without ONESHELL in Makefile

来自 docs, it is necessary to add a target in .ONESHELL to make all the commands run in a same sub-shell process. Further discussion on that is here.

这是我的 makefile,

.PHONY: clean build
.ONESHELL: deploy

zip := my.zip

clean:
    cd ..
    rm -f $(zip)

build: clean
    npm install .
    zip -r ../$(zip) . \
        --exclude=package-lock.json \
        --exclude=.gitignore \
        --exclude=makefile \
        --exclude=*.git* 

... more lines

因此,当我执行 make build 时,会创建父文件夹中的 zip 文件。当我执行 make clean(来自同一目录)时,zip 也从父文件夹中删除。我不明白的是,因为 cd .. 在独立的 shell 进程中运行,父文件夹中的 zip 如何使用 make clean 命令删除,因为它不包含在 .ONESHELL?

版本:Ubuntu18.04

上的 GNU Make 4.1

.ONESHELL 不接受先决条件(或者更准确地说,它忽略它们)。如果您定义它,它会为整个 makefile 启用。目前无法仅针对单个目标指定 .ONESHELL

GNU make 手册说:

If the .ONESHELL special target appears anywhere in the makefile then all recipe lines for each target will be provided to a single invocation of the shell.