Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about CFLAGS in Makefile

Tags:

c

gcc

makefile

In a makefile, there is a line:

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

What's the use of shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1? It seems to do nothing. And how the whole line works? Thanks in advance.

like image 371
akirast Avatar asked Jan 17 '23 02:01

akirast


2 Answers

It tests whether -fno-stack-protector is a valid command-line option for your C compiler, and if it is it then appends this option to CFLAGS, otherwise it does nothing.

like image 148
Paul R Avatar answered Jan 25 '23 08:01

Paul R


If your compiler does not have the option -fno-stack-protector it will return an error code (i.e. something !=0) otherwise it will return 0 (meaning "true" in return codes), indicating everything was all right.

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

like image 41
bitmask Avatar answered Jan 25 '23 09:01

bitmask