Skip to content

Commit

Permalink
Add NOOPT make option to disable optimization
Browse files Browse the repository at this point in the history
GCC recommends use of -Og for debug builds, which theoretically
disables optimizations that will cause problems for debugging, but
leaves some on to improve performance.  Presently, in non-release
builds, the Makefile always uses -Og if supported by the compiler.
Unfortunately, it appears that even -Og permits control flow to --
from the standpoint of someone using a debugger -- not step a single
line at a time when stepping, as lines may have been optimized out.

Provide a make option NOOPT, so that if someone really needs -O0
builds, they can get them from the command line without patching the
Makefile each time (and possibly letting that change slip into pull
requests).
  • Loading branch information
mark7 committed Dec 19, 2019
1 parent e8be1ac commit 79f53ba
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# make DYNAMIC_LINKING=1
# Use MSYS2 as the build environment on Windows
# make MSYS2=1
# Turn off all optimizations, even debug-friendly optimizations
# make NOOPT=1
# Astyle all source files.
# make astyle
# Check if source files are styled properly.
Expand Down Expand Up @@ -303,10 +305,18 @@ ifdef RELEASE
endif

ifndef RELEASE
ifeq ($(shell $(CXX) -E -Og - < /dev/null > /dev/null 2>&1 && echo fog),fog)
OPTLEVEL = -Og
else
ifdef NOOPT
# While gcc claims to include all information required for
# debugging at -Og, at least with gcc 8.3, control flow
# doesn't move line-by-line at -Og. Provide a command-line
# way to turn off optimization (make NOOPT=1) entirely.
OPTLEVEL = -O0
else
ifeq ($(shell $(CXX) -E -Og - < /dev/null > /dev/null 2>&1 && echo fog),fog)
OPTLEVEL = -Og
else
OPTLEVEL = -O0
endif
endif
CXXFLAGS += $(OPTLEVEL)
endif
Expand Down

0 comments on commit 79f53ba

Please sign in to comment.