diff options
| author | Konstantin Demin | 2025-05-02 20:47:01 +0000 |
|---|---|---|
| committer | Christian Marangi | 2025-05-04 16:25:03 +0000 |
| commit | e8b470139c78db269f0ac4908662d7aa9c4586ed (patch) | |
| tree | 9b3df57d7694f57eb221c7e721625f060f8cf789 | |
| parent | faef19c22c4f891ac4cc830c64d5505181e506aa (diff) | |
| download | openwrt-e8b470139c78db269f0ac4908662d7aa9c4586ed.tar.gz | |
tools: add options to optimize host binaries
Mains goals are:
- reduce binary size of host tools;
- reduce i/o load on build host;
- increase performance of host tools being built.
Signed-off-by: Konstantin Demin <rockdrilla@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/18659
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
| -rw-r--r-- | config/Config-devel.in | 54 | ||||
| -rw-r--r-- | rules.mk | 15 |
2 files changed, 65 insertions, 4 deletions
diff --git a/config/Config-devel.in b/config/Config-devel.in index cbac91c09d..3fe78f325b 100644 --- a/config/Config-devel.in +++ b/config/Config-devel.in @@ -62,6 +62,60 @@ menuconfig DEVEL Compile all host host tools even if not needed. This is needed to prepare a universal precompiled host tools archive to use in another buildroot. + menuconfig OPTIMIZE_HOST_TOOLS + bool "Host Tools compile options" if DEVEL + + if OPTIMIZE_HOST_TOOLS + + config HOST_FLAGS_OPT + string "Host Tools optimization flags" + default "-O2" + help + Compiler flags which are used to build host tools. + + E.g.: "-O2", "-O3 -fno-tree-vectorize". + + Default is "-O2". + + config HOST_TOOLS_STRIP + bool "Strip Host Tools" + help + Instructs compiler/linker to use flags from HOST_FLAGS_STRIP + in order to reduce binary size of host tools. + + config HOST_FLAGS_STRIP + string "Host Tools compiler/linker flags for stripping symbols" + depends on HOST_TOOLS_STRIP + default "-Wl,-s" + help + Compiler flags which are used to strip symbols from host tools. + + Each flag should be prefixed with "-Wl," string + because compiler (GCC) passes this value to linker. + + Default is "-Wl,-s" which means "strip all symbols" - specifically, + debug symbols and other symbols not needed for relocation processing. + + comment "Host Tools miscellaneous flags" + + config HOST_EXTRA_CFLAGS + string "Host Tools extra CFLAGS" + default "" + + config HOST_EXTRA_CXXFLAGS + string "Host Tools extra CXXFLAGS" + default "" + + config HOST_EXTRA_CPPFLAGS + string "Host Tools extra CPPFLAGS" + default "" + + config HOST_EXTRA_LDFLAGS + string "Host Tools extra LDFLAGS" + default "" + + endif + config BUILD_SUFFIX string "Build suffix to append to the target BUILD_DIR variable" if DEVEL default "" @@ -278,12 +278,19 @@ PKG_CONFIG:=$(STAGING_DIR_HOST)/bin/pkg-config export PKG_CONFIG +HOST_FLAGS_OPT:=$(call qstrip,$(CONFIG_HOST_FLAGS_OPT)) +HOST_FLAGS_STRIP:=$(call qstrip,$(CONFIG_HOST_FLAGS_STRIP)) +HOST_EXTRA_CFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CFLAGS)) +HOST_EXTRA_CXXFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CXXFLAGS)) +HOST_EXTRA_CPPFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_CPPFLAGS)) +HOST_EXTRA_LDFLAGS:=$(call qstrip,$(CONFIG_HOST_EXTRA_LDFLAGS)) + HOSTCC:=$(STAGING_DIR_HOST)/bin/gcc HOSTCXX:=$(STAGING_DIR_HOST)/bin/g++ -HOST_CPPFLAGS:=-I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include) -HOST_CFLAGS:=-O2 $(HOST_CPPFLAGS) -HOST_CXXFLAGS:=$(HOST_CFLAGS) -HOST_LDFLAGS:=-L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib) +HOST_CPPFLAGS:=$(strip -I$(STAGING_DIR_HOST)/include $(if $(IS_PACKAGE_BUILD),-I$(STAGING_DIR_HOSTPKG)/include -I$(STAGING_DIR)/host/include) $(HOST_EXTRA_CPPFLAGS)) +HOST_CFLAGS:=$(strip $(HOST_FLAGS_OPT) $(HOST_EXTRA_CFLAGS) $(HOST_CPPFLAGS) $(HOST_FLAGS_STRIP)) +HOST_CXXFLAGS:=$(strip $(HOST_CFLAGS) $(HOST_EXTRA_CXXFLAGS)) +HOST_LDFLAGS:=$(strip -L$(STAGING_DIR_HOST)/lib $(if $(IS_PACKAGE_BUILD),-L$(STAGING_DIR_HOSTPKG)/lib -L$(STAGING_DIR)/host/lib) $(HOST_EXTRA_LDFLAGS) $(HOST_FLAGS_STRIP)) BUILD_KEY=$(TOPDIR)/key-build BUILD_KEY_APK_SEC=$(TOPDIR)/private-key.pem |