收录日期:2019/08/19 20:48:21 时间:2010-06-16 01:48:52 标签:recursion,gnu-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]: Entering directory `/disk4/home/user/parent'
shell cd myDir; make; cd ..
/bin/sh: shell: command not found
[...]

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
(cd myDir ; make)

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

Here is what works:

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