views:

23

answers:

3

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
[...]
+2  A: 
(cd myDir ; make)

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

Ignacio Vazquez-Abrams
The new subshell is inheriting something from the parent because the (cd myDir; make) behaves differently than invoking that from the top outside the makefile with this rule for setup.
WilliamKF
Yes, it will inherit all exported variables. Use `env` if you want to prevent even this.
Ignacio Vazquez-Abrams
Please elaborate on how env is used. Is it 'env -i' somehow?
WilliamKF
A: 

Here is what works:

.PHONY: setup
setup:
 (cd myDir; env --unset=MAKEFLAGS make)
WilliamKF
+1  A: 

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
bobbogo