Agrim Pathak
Agrim Pathak

Reputation: 3207

Append compiler flags when running make

I would like to append flags to the compiler flags when running make, without altering the Makefile in anyway, e.g.

make CXX_FLAGS+='-DDEBUG'

The above treats "+=" as "=", so it's not the correct symbol.

Upvotes: 2

Views: 3459

Answers (1)

CWLiu
CWLiu

Reputation: 4043

You just have to modify the variable as override in your Makefile once. And then you can do what you want to do.

Here's the example,

Makefile:

override CFLAGS+=-g                                                                                    

app: main.c
  gcc $(CFLAGS) -o app main.c

Run the make:

$ make
gcc -g -o app main.c

Append the '-Wall' to $CFLAGS from the command:

$ make CFLAGS=-Wall
gcc -Wall -g -o app main.c

Work fine here. And here's manual you can reference.

Upvotes: 4

Related Questions