【问题标题】:cd.. works without ONESHELL in Makefilecd .. 在 Makefile 中没有 ONESHELL 的情况下工作
【发布时间】:2019-01-03 17:00:25
【问题描述】:

docs开始,需要在.ONESHELL中添加一个target,使所有命令运行在同一个子shell进程中。对此的进一步讨论是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 进程中运行,我不明白的是,如何使用make clean 命令删除父文件夹中的zip,因为它不包含在.ONESHELL 中?

版本:Ubuntu 18.04 上的 GNU Make 4.1

【问题讨论】:

    标签: ubuntu makefile gnu-make


    【解决方案1】:

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

    GNU make 手册说:

    如果 .ONESHELL 特殊目标出现在 makefile 中的任何位置,则 all 每个目标的配方行将提供给 shell 的一次调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多