11

What is the intended use of EXTRA_CFLAGS?

I see it in some contexts but I've never understood why one wouldn't just append flags to CFLAGS instead of EXTRA_CFLAGS.

I first thought there was something to do with how make has defined its implicit rules, but this did not seem to be the case. As I understand it, there are no uses of EXTRA_CFLAGS in the make implicit rules, correct?

I would appreciate any enlightenment.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
Marcus Johansson
  • 2,626
  • 2
  • 24
  • 44
  • Do you have any examples of this available offhand? – Etan Reisner Jan 09 '15 at 14:23
  • I don't have any examples I can share. This question is also more about how this is used in general, and what coding conventions and software support/expectations that might exist for this parameter. – Marcus Johansson Jan 09 '15 at 14:35

1 Answers1

17

Well, that's not any part of standard make or built-in make rules, so it's just a convention that some of the makefiles you're used to have used. The reason why it's done as a separate flag is so you can use it on the command line:

make EXTRA_CFLAGS=-O3

Command line variable assignments override any setting of the variable inside the makefile, so appending doesn't work. That is:

$ cat Makefile
CFLAGS += -Dfoo

all: ; @echo '$(CFLAGS)'

$ make CFLAGS=-Dbar
-Dbar

$ make CFLAGS+=-Dbar
-Dbar

both will show -Dbar, not -Dfoo -Dbar.

That's why it's a separate flag. In automake environments, they explicitly preserve CFLAGS for the user to provide on the command line and all "normal" flags are put into other variables.

MadScientist
  • 92,819
  • 9
  • 109
  • 136