0

I was reading a makefile where I found this statement

 make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules 

Can anyone explain what is shell here. Command substitution is being tried here but for that only uname -r would have been sufficient. Why is shell word being used and what is its meaning?

I have already tried doing man on shell but as I expected it shows nothing. I also tried executing shell uname -r on command line. It does not work. I believe that this variable is defined in make.

1
  • I edited the tag since your question is related to the non-portable way gmake implements calls to external programs in order to use their output. Commented Jul 6, 2020 at 6:09

1 Answer 1

2

I bet this line is within a Makefile, most likely a recursive call to make.

Makefile use $(VAR) (or ${VAR}) for local variable or environment variable.

note the difference with bash where $(VAR) means "execute VAR and fetch result", thus for similar effect in Makefile anoter syntax is used

$(shell uname -r) 

to sum up

  • $(shell uname -r) will expand to result of uname -r
  • $(PWD) will expand to $PWD's value

see GNU Makefile reference

3
  • This feature is a non-portable gmake feature that does not work with make. Please do not use the name make when talking about non-portable methods. Other make implementations support variables in the form VAR :sh= uname -r and VAR :sh uname -r since before gmake started to exist. Commented Jul 6, 2020 at 5:58
  • I was merely trying to answer OP and explain seen line wether gmake or make Commented Jul 6, 2020 at 6:05
  • I believe that it is worth to inform people when they are using features that are not working the same way in the original program. It is so easy to inform people that they are using gmake while they believe that thay are using make. Using non-portable features in Makefiles is the first step for a non-portable program. Commented Jul 6, 2020 at 6:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.