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

Posted on

Problem :

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

Solution :

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.

Leave a Reply

Your email address will not be published.