GNU make executes weird shell

The shell function in GNU make behaves weird on Ubuntu. Consider this simple Makefile:

TEST1 := $(shell command -v sh)
TEST2 := $(shell /bin/sh -c 'command -v sh')
all: $(info TEST1 = $(TEST1)) $(info TEST2 = $(TEST2))

Running make prints

make: command: Command not found
TEST1 =
TEST2 = /usr/bin/sh

Weird. Why does the default shell not know the command built-in? And what is the default shell invoked by GNU make actually? According to the GNU make manual:

The program used as the shell is taken from the variable SHELL. If this variable is not set in your makefile, the program /bin/sh is used as the shell.

There is no SHELL variable in the Makefile above, so the shell should be /bin/sh. However, running /bin/sh explicitly from the default shell actually behaves as expected, so there must be some difference.

So what is the real problem? It seems to be specific to GNU make packaged in Ubuntu, since the aforementioned Makefile behaves as expected on other systems like Arch Linux (which symlinks /bin/sh to bash rather than dash, though), i.e. it prints TEST1 = /usr/bin/sh.

2 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like