Skip to content

Commit

Permalink
Makefile: Add optimization flags
Browse files Browse the repository at this point in the history
Signed-off-by: KenHV <[email protected]>
  • Loading branch information
KenHV committed Aug 18, 2022
1 parent c293291 commit fb1646c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ endif
HOSTPKG_CONFIG = pkg-config

KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
-O2 -fomit-frame-pointer -std=gnu11 \
-O3 -fomit-frame-pointer -std=gnu11 \
-Wdeclaration-after-statement -pipe
KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
KBUILD_USERLDFLAGS := $(USERLDFLAGS)

KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O3 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)

Expand Down Expand Up @@ -754,11 +754,29 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)

ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
KBUILD_CFLAGS += -O2
KBUILD_AFLAGS += -O2
KBUILD_CFLAGS += -O2
ifdef CONFIG_CC_IS_CLANG
ifdef CONFIG_LTO
KBUILD_LDFLAGS += --lto-O2
else
KBUILD_LDFLAGS += -O2
endif
endif
else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
KBUILD_CFLAGS += -O3
KBUILD_AFLAGS += -O3
KBUILD_CFLAGS += -O3
ifdef CONFIG_CC_IS_CLANG
ifdef CONFIG_LTO
KBUILD_LDFLAGS += --lto-O3
else
KBUILD_LDFLAGS += -O3
endif
endif
else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os
KBUILD_AFLAGS += -Os
KBUILD_CFLAGS += -Os
KBUILD_LDFLAGS += -Os
endif

# Tell gcc to never replace conditional load with a non-conditional one
Expand Down

0 comments on commit fb1646c

Please sign in to comment.