Unverified Commit 1d77a8e2 authored by Viktor Söderqvist's avatar Viktor Söderqvist Committed by GitHub
Browse files

Makefile respect user's REDIS_CFLAGS and OPT (#13073)

This change to the Makefile makes it possible to opt out of
`-fno-omit-frame-pointer` added in #12973 and `-flto` (#11350). Those
features were implemented by conditionally modifying the `REDIS_CFLAGS`
and `REDIS_LDFLAGS` variables. Historically, those variables provided a
way for users to pass options to the compiler and linker unchanged.

Instead of conditionally appending optimization flags to REDIS_CFLAGS
and REDIS_LDFLAGS, I want to append them to the OPTIMIZATION variable.

Later in the Makefile, we have `OPT=$(OPTIMIZATION)` (meaning
OPTIMIZATION is only a default for OPT, but OPT can be overridden by the
user), and later the flags are combined like this:

FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
    FINAL_LDFLAGS=$(LDFLAGS) $(OPT) $(REDIS_LDFLAGS) $(DEBUG)

This makes it possible for the the user to override all optimization
flags with e.g. `make OPT=-O1` or just `make OPT=`.

For some reason `-O3` was also already added to REDIS_LDFLAGS by default
in #12339, so I added OPT to FINAL_LDFLAGS to avoid more complex logic
(such as introducing a separate LD_OPT variable).
parent 3b3d16f7
...@@ -16,17 +16,20 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') ...@@ -16,17 +16,20 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh')
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
CLANG := $(findstring clang,$(shell sh -c '$(CC) --version | head -1')) CLANG := $(findstring clang,$(shell sh -c '$(CC) --version | head -1'))
# Optimization flags. To override, the OPTIMIZATION variable can be passed, but
# some automatic defaults are added to it. To specify optimization flags
# explicitly without any defaults added, pass the OPT variable instead.
OPTIMIZATION?=-O3 OPTIMIZATION?=-O3
ifeq ($(OPTIMIZATION),-O3) ifeq ($(OPTIMIZATION),-O3)
ifeq (clang,$(CLANG)) ifeq (clang,$(CLANG))
REDIS_CFLAGS+=-flto OPTIMIZATION+=-flto
else else
REDIS_CFLAGS+=-flto=auto OPTIMIZATION+=-flto=auto
endif endif
REDIS_LDFLAGS+=-O3 -flto
endif endif
ifneq ($(OPTIMIZATION),-O0) ifneq ($(OPTIMIZATION),-O0)
REDIS_CFLAGS+=-fno-omit-frame-pointer OPTIMIZATION+=-fno-omit-frame-pointer
endif endif
DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram fpconv DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram fpconv
NODEPS:=clean distclean NODEPS:=clean distclean
...@@ -120,7 +123,7 @@ endif ...@@ -120,7 +123,7 @@ endif
-include .make-settings -include .make-settings
FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS) FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
FINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG) FINAL_LDFLAGS=$(LDFLAGS) $(OPT) $(REDIS_LDFLAGS) $(DEBUG)
FINAL_LIBS=-lm FINAL_LIBS=-lm
DEBUG=-g -ggdb DEBUG=-g -ggdb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment