Makefile中的路径不起作用 [英] path in makefile not working

查看:118
本文介绍了Makefile中的路径不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下makefile 需要将dir更改为特定目标并在其中运行npm install

Im running the following makefile which needs to change dir to specific target and run there npm install

问题是我能够在输出中看到它将目录(project/app)打印到正确的目录,但是安装(npm install)在升级(项目)时运行,为什么?

The problem is that I was able to see in the output that it print the directory (project/app) to the right directory but the installation (npm install) run on level up (project), why ?

例如

当我运行它时,我会从cd $ {DIR)/app中看到 /Users/i03432/go/src/project/app

When I run it I see from cd $(DIR)/app /Users/i03432/go/src/project/app

现在第二个命令是 npm install

我得到一个错误,即id在正确的项目路径中找不到包json ...它仅在app路径中.为什么CD不能正常工作?

And I got error that id doesn’t find the package json in the project path which is right... it’s only in the app path. Why the cd is not working ?

它试图在这里找到它 /Users/i03432/go/src/project/package.json

it try to find it here /Users/i03432/go/src/project/package.json

这是package.json

and here is the package.json

/Users/i03432/go/src/project/app/package.json

makefile是

module:

   DIR=$(PWD)
   @echo $(DIR)
   cd $(DIR)/app
   npm install

推荐答案

规则中的每个命令都在单个进程(子外壳)中运行.因此,您在环境上执行的每个更改都与该特定线路相关.您要将代码段更改为

Every command in a rule is run in a single process (sub-shell). Every change you perform on the environment is hence tied to that particular line. You want to change your snippet to

cd $(PWD)/app && npm install

此命令在单个子进程中运行,应产生期望的结果.请注意,DIR的定义也会发生此问题,因此您可能需要将此行向上移动几行:

This command runs in a single subprocess and should yield the desired result. Note that this problem occurs for the definition of DIR, too, so you might want to move this a few lines up:

DIR = $(PWD)

module:
    cd $(DIR) && npm install

这样,您引用的是make提供的变量,并且您在这里不依赖于子过程.

This way, you are referring to a variable that make provides, and you don't rely upon subprocesses here.

这篇关于Makefile中的路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆