shell - pushd 在 makefile 中不起作用

标签 shell makefile

我在makefile中有以下规则:

ninja:
    git clone git://github.com/martine/ninja.git
    pushd ninja
    pwd
    git checkout release
    ./configure.py --bootstrap
    popd

思路是下载构建ninja自 Action 为项目依赖项。请注意 pwd命令只是为了确保目录被推送。这是它生成的输出:
git clone git://github.com/martine/ninja.git
Cloning into 'ninja'...
remote: Counting objects: 8646, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8646 (delta 0), reused 0 (delta 0), pack-reused 8642
Receiving objects: 100% (8646/8646), 1.88 MiB | 427.00 KiB/s, done.
Resolving deltas: 100% (6114/6114), done.
Checking connectivity... done.
pushd ninja
~/Desktop/core/ninja ~/Desktop/core
pwd
/Users/fratelli/Desktop/core
git checkout release
error: pathspec 'release' did not match any file(s) known to git.
make: *** [ninja] Error 1

如您所见,目录确实被压入堆栈,但 pwd不返回正确的目录。这也是为什么checkout之后失败。任何想法如何解决这一问题?

最佳答案

makefile 目标配方中的每一行都在其自己的 shell session 中运行。这不会影响大多数配方,因为它们默认在它们需要的目录中运行。当他们不这样做时,您需要使用 cdpushd那么您需要将所有命令都写在同一行上,或者告诉 make 这些行是继续的。

Splitting Recipe Lines有关更多详细信息和示例。

关于shell - pushd 在 makefile 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32302228/

相关文章:

linux - GNU grep 和 AIX Unix grep 命令选项之间的差异

xcode - 使用 Xcode 构建后脚本创建 ZIP 存档

bash - 可能的攻击 : echo -e

variables - GNU 制造商 : Using % in a pattern-rule macro

c++ - 获取生成文件以更改输出可执行文件名称

makefile - 文件修改后重新运行的程序,例如 `make`?

bash - 提取包含多个部分的部分文件名

shell - 如何在 sftp 模式下在 shell 脚本中添加确认

python - 如何在 ubuntu 12.04 上为 python2.6 从源代码编译 pygtk

makefile - GNU 制作空配方与无配方