How do I make sure my code is compiling with -o3 in gnu make?

0

1

I have a huge Makefile I'm working with and trying to trim down. Right now, it's layed out to build several different programs with tons of options I'll never use. My hope is to first make sure the code builds the right way, and then cut out parts I don't need.

First things first, I want to make sure my code in compiling with -o3 (lots of optimizations) but I'm not sure that it is. I see a chunk of the Makefile that says:

ifeq ($(findstring $(CFLAGS),-O),)
    CFLAGS_COMMON += -O3
    # only add -O3 if no -O flag is in $(CFLAGS)
endif

which provides some solace...but doesn't there have to be a -O flag in place for it to compile at all, negating the if-statement?

Here's the whole Makefile: http://textuploader.com/bj98

Volumetricsteve

Posted 2015-06-29T01:41:00.807

Reputation: 555

!) That option uses a capitalized 'O'. 2) See http://stackoverflow.com/questions/5820303/how-do-i-force-make-gcc-to-show-me-the-commands and verbose mode in http://elinux.org/Debugging_Makefiles

– sawdust – 2015-06-29T03:15:47.743

Answers

1

LDFLAGS            ?=
CFLAGS             ?=
CXXFLAGS           ?=
CPPFLAGS           ?=
LIBS               ?=
RADIANT_ABOUTMSG   ?= Custom build

I'd add -O3 to CPPFLAGS, CXXFLAGS and CFLAGS. BUT:

This will only change the code of your project's changed files. To be sure all your files are recompiled, do a make clean first. BUT:

This does not guarantee externally linked files, such as libraries. Those generally are not compiled with -O3. If your want to assure they are, you will have to recompile all the libraries too (not forgetting to changeing all their Makefiles!). And. if those files depend on other libraries (they probably do), you'll also have to recompile those.

jcoppens

Posted 2015-06-29T01:41:00.807

Reputation: 629

If this was useful, please don't forget to mark the answer as accepted (click the 'V' left of the answer) and/or upvote the answer (click on the up-arrow). This way others can more easily find it! Thanks. – jcoppens – 2015-06-29T17:21:21.320