Skip to content

Commit

Permalink
package.mk: add gc-sections and lto support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Oct 13, 2023
1 parent 411c670 commit 71e53ab
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions trunk/include/package.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ PKG_JOBS ?= -j$(HOST_NCPU)
SRC_DIR ?= ./src
PATCH_DIR ?= ./patches

PKG_BUILD_FLAGS?=
__unknown_flags=$(filter-out gc-sections no-gc-sections lto no-lto,$(PKG_BUILD_FLAGS))
ifneq ($(__unknown_flags),)
$(error unknown PKG_BUILD_FLAGS: $(__unknown_flags))
endif

# $1=flagname, $2=default (0/1)
define pkg_build_flag
$(if $(filter no-$(1),$(PKG_BUILD_FLAGS)),0,$(if $(filter $(1),$(PKG_BUILD_FLAGS)),1,$(2)))
endef

ifeq ($(call pkg_build_flag,gc-sections,$(if $(CONFIG_USE_GC_SECTIONS),1,0)),1)
TARGET_CFLAGS+= -ffunction-sections -fdata-sections
TARGET_CXXFLAGS+= -ffunction-sections -fdata-sections
TARGET_LDFLAGS+= -Wl,--gc-sections
endif
ifeq ($(call pkg_build_flag,lto,$(if $(CONFIG_USE_LTO),1,0)),1)
TARGET_CFLAGS+= -flto=auto -fno-fat-lto-objects
TARGET_CXXFLAGS+= -flto=auto -fno-fat-lto-objects
TARGET_LDFLAGS+= -flto=auto -fuse-linker-plugin
endif

include $(INCLUDE_DIR)/download.mk
include $(INCLUDE_DIR)/unpack.mk
include $(INCLUDE_DIR)/autotools.mk
Expand Down

0 comments on commit 71e53ab

Please sign in to comment.