开发者

How can invoke a shell to make a new environment to run a make inside another make?

I would like in my GNUmakefile to have a target rule that invokes a new shell and then with the clean slate of the new shell invokes a new make.

What is the syntax to do this?

I tried this but it didn't work:

.PHONY: setup
setup:
 shell cd myDir; make; cd ..

It gets infinite repeat of the following error:

make[1]: Entering directory `/disk4/home/user/parent'
shell cd myDir; make; cd ..
/bin/sh: shell: command not found
make[1]: 开发者_StackOverflow中文版Entering directory `/disk4/home/user/parent'
shell cd myDir; make; cd ..
/bin/sh: shell: command not found
[...]


(cd myDir ; make)

The parens invoke a new subshell, with its own "current directory".


The parens are not necessary. Every line in a recipe is invoked in its own shell anyway. Your recipe seems to have a superfluous shell string, which your shell tries to execute as a command (/bin/sh (your shell, not make) complains shell: command not found).

Also, make's -C parameter is handy in this case.

Also, when calling make from the shell, use the ${MAKE} macro.

.PHONY: setup
setup:
    unset MAKEFLAGS; ${MAKE} -C myDir


Here is what works:

.PHONY: setup
setup:
 (cd myDir; env --unset=MAKEFLAGS make)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜