path in makefile not working

好久不见. 提交于 2019-12-11 04:36:31

问题


Im running the following makefile which needs to change dir to specific target and run there 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 ?

For example

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

Now the second command is npm install

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 ?

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

and here is the package.json

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

The makefile is

module:

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

回答1:


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

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

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



来源:https://stackoverflow.com/questions/51022628/path-in-makefile-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!