#include \nmain() {printf(...">

What happened to the following GNU: shell shell extension?

In this line:

GCCVER:=$(shell a=`mktemp` && echo $'#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$a" -xc -; "$a"; rm "$a") 

I get:

 *** unterminated call to function `shell': missing `)'. Stop. 

What happened to my dumb cool variable?

Update0

 $ make --version GNU Make 3.81 $ bash --version GNU bash, version 4.2.8(1)-release (x86_64-pc-linux-gnu) $ uname -a Linux 2.6.38-10-generic #46-Ubuntu SMP x86_64 GNU/Linux $ gcc --version gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 
+6
source share
1 answer

when using $ for Bash inside the Makefile you need to double them: $$a for example. I am not familiar with the designation $' , but I must assume that you know what you are doing with it. if it is not a Makefile construct, you also need to double the dollar sign on that.

also the hash sign # completes the shell extension in the Make assessment, so it never sees the correct guy. slipping away from him helps, but I don't have a job yet. [/ p>

I debug it by doing two steps: first set GCCVER as a list of commands without closing $(shell) , and then in the 2nd step GCCVER := $(shell $(GCCVER)) . you can also try this by commenting on the $(shell) step when it doesn't work, using export and creating the "set" recipe:

 GCCVER := some commands here #GCCVER := $(shell $(GCCVER)) # expand the commands, commented out now export # all variables available to shell set: set # make sure this is prefixed by a tab, not spaces 

Then:

 make set | grep GCCVER 

[update]:

 GCCVER := a=`mktemp` && echo -e '\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a" GCCVER := $(shell $(GCCVER)) export default: set jcomeau@intrepid :/tmp$ make | grep GCCVER GCCVER=4.6 

And a full circle, getting rid of the extra step:

 jcomeau@intrepid :/tmp$ make | grep GCCVER; cat Makefile GCCVER=4.6 GCCVER := $(shell a=`mktemp` && echo -e '\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a") export default: set 

Using the $' Bash construct:

 jcomeau@intrepid :/tmp$ make | grep GCCVER; cat Makefile GCCVER=4.6 GCCVER := $(shell a=`mktemp` && echo $$'\#include <stdio.h>\nmain() {printf("%u.%u\\n", __GNUC__, __GNUC_MINOR__);}' | gcc -o "$$a" -xc -; "$$a"; rm "$$a") export default: set 

Since your system does not work the same as mine, I'm going to sort it out and say either use the reinierpost clause, or alternatively:

 GCCVER := $(shell gcc -dumpversion | cut -d. -f1,2) 
+10
source

Source: https://habr.com/ru/post/894903/


All Articles