About CFLAGS in a Makefile

There is a line in the makefile:

CFLAGS += $(shell $(CC) -fno-stack-protector -E -xc /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) 

What use is shell $(CC) -fno-stack-protector -E -xc /dev/null >/dev/null 2>&1 ? Seems to be doing nothing. And how does the whole line work? Thanks in advance.

+4
source share
3 answers

If your compiler does not have the -fno-stack-protector option, it will return an error code (that is, something !=0 ), otherwise it will return 0 (which means "true" in the return codes), indicating that everything is in order.

Now the expression foo && bar means that bar will be executed only if foo returns error-free code (i.e. 0 ). So, you see that if your compiler does not have this flag, it will return false (something !=0 ), and the echo command will never be executed. But if it has a flag, echo will be executed.

+4
source

It checks if -fno-stack-protector valid command line parameter for your C compiler, and if it is, it adds this option to CFLAGS , otherwise it does nothing.

+5
source

Is this a test? Is the -fno-stack-protector option available?

0
source

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


All Articles