Erdinç Taşkın
Erdinç Taşkın

Reputation: 1578

pass variable to make file

I read documents about CPPFLAGS. Shortly, I understand that CPPFLAGS used for pass parameter to compiler. Sample usage CPPFLAGS in makefile is below.

gcc $(CPPFLAGS) main.c -o main.o

Execute make

make CPPFLAGS=-I../header

What is special CPPFLAGS text? It can be interchangable any other text like "FOO". What is the differences between FOO variable and CPPFLAGS variable? Replace all CPPFLAGS text with FOO text build is success again, nothing changes.

Main problem that actually need to solve. There are lots of makefiles. There is no include CPPFLAGS variable in these makefiles. Is there a way to pass compiler options without change makefiles.

Thanks.

Upvotes: 0

Views: 525

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136208

What is special CPPFLAGS text? It can be interchangable any other text like "FOO"

Three things are special about CPPFLAGS:

  1. It is a convention that many tools follow. Most notably GNU autoconf/automake.
  2. GNU Make provides implicit rules to build many target types. These implicit rules use CPPFLAGS variable when compiling .o from C and C++ sources. These rules can be replaced with one's own rules if necessary.
  3. When you use CPPFLAGS for preprocessor flags you follow the principle of least astonishment.

There is no include CPPFLAGS variable in these makefiles

If you meant that there are no occurrences of CPPFLAGS in the makefiles that may be because the implicit rules are used which I mentioned above.

Upvotes: 1

Related Questions