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.

2
  • Do you have any examples of this available offhand? Commented Jan 9, 2015 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. Commented Jan 9, 2015 at 14:35

1 Answer 1

19

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.