Kundan Kumar
Kundan Kumar

Reputation: 2002

Setting CPPFLAGS through command line

Suppose in my makefile I have

   program_INCLUDE_DIRS += ../inc 
   CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))

Now I want to include a directory named ../inc2 (which is present one directory above where I am running the makefile) while running the makefile through the command line

I know that I should set the ../inc2 directory to CPPFLAGS.

Please suggest me the syntax of the command to include the directory ../inc2 through command line. Also I dont want to override the existing directory included in the makefile(../inc above).

Upvotes: 2

Views: 3512

Answers (1)

Karl Bielefeldt
Karl Bielefeldt

Reputation: 48998

The += means CPPFLAGS is appended instead of replaced. That means you can set it in your shell and the existing directories will get appended, like this:

export CPPFLAGS=-I../inc2
make

If you need to do this a lot, the better solution would be to change your makefile to say:

program_INCLUDE_DIRS += ../inc ../inc2

Upvotes: 1

Related Questions