e271p314
e271p314

Reputation: 4039

Is there an option for gcc which discards -g flag?

I'm building a package which provides many makefiles, each makefile has hard coded in side something like

CFLAGS = -g -O2 -Wall ...
CXXFLAGS = -g -O2 -Wall ...

I want to discard -g option but I don't want to edit all makefiles (even not automatically with sed or something similar). The configure script which comes with the package doesn't have enable/disable debug option but I can pass it CFLAGS and CXXFLAGS variables and it concatenates their values to the CFLAGS and CXXFLAGS variables respectively which include the -g option.

Is there an option which will discard -g in case it is specified? Something like

gcc -option-im-looking-for -g file.c -o file

Will build the binary file without debug symbols. I don't want to strip the binary, I want it to be created stripped.

Upvotes: 12

Views: 2129

Answers (2)

devnull
devnull

Reputation: 123608

You could negate the effect of -g by adding -g0. Saying

gcc -g -g0 foo.c -o file.o

would produce a binary identical to one obtained by saying

gcc foo.c -o foo.o

Quoting man gcc:

   -glevel
   ...
        Level 0 produces no debug information at all.  Thus, -g0 negates
       -g.

Upvotes: 17

Martin Vidner
Martin Vidner

Reputation: 2337

You don't need to edit makefiles. Just override the variables on the command line:

$ cat Makefile 
CFLAGS = -g -Wall
all:
    echo $(CFLAGS)
$ make
echo -g -Wall
-g -Wall
$ make CFLAGS=-Wall
echo -Wall
-Wall

Upvotes: 1

Related Questions