Reputation:
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
Upvotes: 2
Views: 1095
Reputation: 38315
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.
Upvotes: 3