![Yann E. MORIN](/assets/img/avatar_default.png)
Setting an unset variable to an empty value is useless in make; an unset variable just expands to an empty string anyway. So what we do currently has no side effect: variable set and not empty -> variable not modified variable set and empty -> variable not modified variable unset -> set to an empty string However, additional variables do have an impact on the parsing time of the Makefiles, and the more variables, the more collisions in the hash table used internally by make, which slows down the parsing. By dropping those conditionally-set-empty variables, we gain about 3%: Run Before After 1 5.572 5.325 2 5.434 5.354 3 5.490 5.320 4 5.525 5.330 5 5.476 5.330 6 5.511 5.434 7 5.498 5.388 8 5.524 5.371 9 5.479 5.346 10 5.637 5.324 Mean: 5.515 5.352 Yeah, 0.163s does not look like much, and this does not make autocompletion any more usable. Still, that 3% gain is not to be ashamed of either. Note that there are 3 others case where we do set empty variables, but those are unconditional and serve other purposes: - pkg-virtual: this is done on purpose to avoid a bug when the environment may have TOOLCHAIN_VERSION or _SOURCE set, and we really want those to be empty, so the assignment is not conditional; - pkg-python: the reason for setting those to empty is dubious at best; it's been there since the inception of the python infra, back in 2013; still, the case is different than this patch addresses; - pkg-toolchain-external: this is the case for a toolchain already installed, so indeed we want to set _SOURCE and _VERSION to empty. Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr> Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
212 lines
7.7 KiB
Makefile
212 lines
7.7 KiB
Makefile
################################################################################
|
|
# Meson package infrastructure
|
|
#
|
|
# This file implements an infrastructure that eases development of
|
|
# package .mk files for Meson packages. It should be used for all
|
|
# packages that use Meson as their build system.
|
|
#
|
|
# See the Buildroot documentation for details on the usage of this
|
|
# infrastructure
|
|
#
|
|
# In terms of implementation, this Meson infrastructure requires
|
|
# the .mk file to only specify metadata information about the
|
|
# package: name, version, download URL, etc.
|
|
#
|
|
# We still allow the package .mk file to override what the different
|
|
# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is
|
|
# already defined, it is used as the list of commands to perform to
|
|
# build the package, instead of the default Meson behaviour. The
|
|
# package can also define some post operation hooks.
|
|
#
|
|
################################################################################
|
|
|
|
#
|
|
# Pass PYTHONNOUSERSITE environment variable when invoking Meson or Ninja, so
|
|
# $(HOST_DIR)/bin/python3 will not look for Meson modules in
|
|
# $HOME/.local/lib/python3.x/site-packages
|
|
#
|
|
MESON = PYTHONNOUSERSITE=y $(HOST_DIR)/bin/meson
|
|
NINJA = PYTHONNOUSERSITE=y $(HOST_DIR)/bin/ninja
|
|
NINJA_OPTS = $(if $(VERBOSE),-v) -j$(PARALLEL_JOBS)
|
|
|
|
################################################################################
|
|
# inner-meson-package -- defines how the configuration, compilation and
|
|
# installation of a Meson package should be done, implements a few hooks to
|
|
# tune the build process and calls the generic package infrastructure to
|
|
# generate the necessary make targets
|
|
#
|
|
# argument 1 is the lowercase package name
|
|
# argument 2 is the uppercase package name, including a HOST_ prefix
|
|
# for host packages
|
|
# argument 3 is the uppercase package name, without the HOST_ prefix
|
|
# for host packages
|
|
# argument 4 is the type (target or host)
|
|
################################################################################
|
|
|
|
define inner-meson-package
|
|
|
|
#
|
|
# Configure step. Only define it if not already defined by the package
|
|
# .mk file. And take care of the differences between host and target
|
|
# packages.
|
|
#
|
|
ifndef $(2)_CONFIGURE_CMDS
|
|
ifeq ($(4),target)
|
|
|
|
$(2)_CFLAGS ?= $$(TARGET_CFLAGS)
|
|
$(2)_LDFLAGS ?= $$(TARGET_LDFLAGS)
|
|
$(2)_CXXFLAGS ?= $$(TARGET_CXXFLAGS)
|
|
|
|
# Configure package for target
|
|
#
|
|
#
|
|
define $(2)_CONFIGURE_CMDS
|
|
rm -rf $$($$(PKG)_SRCDIR)/build
|
|
mkdir -p $$($$(PKG)_SRCDIR)/build
|
|
sed -e 's%@TARGET_CROSS@%$$(TARGET_CROSS)%g' \
|
|
-e 's%@TARGET_ARCH@%$$(HOST_MESON_TARGET_CPU_FAMILY)%g' \
|
|
-e 's%@TARGET_CPU@%$$(HOST_MESON_TARGET_CPU)%g' \
|
|
-e 's%@TARGET_ENDIAN@%$$(HOST_MESON_TARGET_ENDIAN)%g' \
|
|
-e "s%@TARGET_CFLAGS@%$$(call make-sq-comma-list,$$($(2)_CFLAGS))%g" \
|
|
-e "s%@TARGET_LDFLAGS@%$$(call make-sq-comma-list,$$($(2)_LDFLAGS))%g" \
|
|
-e "s%@TARGET_CXXFLAGS@%$$(call make-sq-comma-list,$$($(2)_CXXFLAGS))%g" \
|
|
-e 's%@HOST_DIR@%$$(HOST_DIR)%g' \
|
|
-e 's%@STAGING_DIR@%$$(STAGING_DIR)%g' \
|
|
-e 's%@STATIC@%$$(if $$(BR2_STATIC_LIBS),true,false)%g' \
|
|
-e "/^\[binaries\]$$$$/s:$$$$:$$(foreach x,$$($(2)_MESON_EXTRA_BINARIES),\n$$(x)):" \
|
|
-e "/^\[properties\]$$$$/s:$$$$:$$(foreach x,$$($(2)_MESON_EXTRA_PROPERTIES),\n$$(x)):" \
|
|
package/meson/cross-compilation.conf.in \
|
|
> $$($$(PKG)_SRCDIR)/build/cross-compilation.conf
|
|
PATH=$$(BR_PATH) \
|
|
CC_FOR_BUILD="$$(HOSTCC)" \
|
|
CXX_FOR_BUILD="$$(HOSTCXX)" \
|
|
$$($$(PKG)_CONF_ENV) \
|
|
$$(MESON) \
|
|
--prefix=/usr \
|
|
--libdir=lib \
|
|
--default-library=$(if $(BR2_STATIC_LIBS),static,shared) \
|
|
--buildtype=$(if $(BR2_ENABLE_RUNTIME_DEBUG),debug,release) \
|
|
--cross-file=$$($$(PKG)_SRCDIR)/build/cross-compilation.conf \
|
|
-Db_pie=false \
|
|
-Dstrip=false \
|
|
-Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig \
|
|
$$($$(PKG)_CONF_OPTS) \
|
|
$$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
|
|
endef
|
|
else
|
|
|
|
# Configure package for host
|
|
define $(2)_CONFIGURE_CMDS
|
|
rm -rf $$($$(PKG)_SRCDIR)/build
|
|
mkdir -p $$($$(PKG)_SRCDIR)/build
|
|
$$(HOST_CONFIGURE_OPTS) \
|
|
$$($$(PKG)_CONF_ENV) $$(MESON) \
|
|
--prefix=$$(HOST_DIR) \
|
|
--libdir=lib \
|
|
--sysconfdir=$$(HOST_DIR)/etc \
|
|
--localstatedir=$$(HOST_DIR)/var \
|
|
--default-library=shared \
|
|
--buildtype=release \
|
|
-Dstrip=true \
|
|
$$($$(PKG)_CONF_OPTS) \
|
|
$$($$(PKG)_SRCDIR) $$($$(PKG)_SRCDIR)/build
|
|
endef
|
|
endif
|
|
endif
|
|
|
|
$(2)_DEPENDENCIES += host-meson
|
|
|
|
#
|
|
# Build step. Only define it if not already defined by the package .mk
|
|
# file.
|
|
#
|
|
ifndef $(2)_BUILD_CMDS
|
|
ifeq ($(4),target)
|
|
define $(2)_BUILD_CMDS
|
|
$$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
|
|
$$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
|
|
endef
|
|
else
|
|
define $(2)_BUILD_CMDS
|
|
$$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
|
|
$$(NINJA) $$(NINJA_OPTS) $$($$(PKG)_NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build
|
|
endef
|
|
endif
|
|
endif
|
|
|
|
#
|
|
# Host installation step. Only define it if not already defined by the
|
|
# package .mk file.
|
|
#
|
|
ifndef $(2)_INSTALL_CMDS
|
|
define $(2)_INSTALL_CMDS
|
|
$$(HOST_MAKE_ENV) $$($$(PKG)_NINJA_ENV) \
|
|
$$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
|
|
endef
|
|
endif
|
|
|
|
#
|
|
# Staging installation step. Only define it if not already defined by
|
|
# the package .mk file.
|
|
#
|
|
ifndef $(2)_INSTALL_STAGING_CMDS
|
|
define $(2)_INSTALL_STAGING_CMDS
|
|
$$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(STAGING_DIR) \
|
|
$$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
|
|
endef
|
|
endif
|
|
|
|
#
|
|
# Target installation step. Only define it if not already defined by
|
|
# the package .mk file.
|
|
#
|
|
ifndef $(2)_INSTALL_TARGET_CMDS
|
|
define $(2)_INSTALL_TARGET_CMDS
|
|
$$(TARGET_MAKE_ENV) $$($$(PKG)_NINJA_ENV) DESTDIR=$$(TARGET_DIR) \
|
|
$$(NINJA) $$(NINJA_OPTS) -C $$($$(PKG)_SRCDIR)/build install
|
|
endef
|
|
endif
|
|
|
|
# Call the generic package infrastructure to generate the necessary
|
|
# make targets
|
|
$(call inner-generic-package,$(1),$(2),$(3),$(4))
|
|
|
|
endef
|
|
|
|
################################################################################
|
|
# meson-package -- the target generator macro for Meson packages
|
|
################################################################################
|
|
|
|
meson-package = $(call inner-meson-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
|
|
host-meson-package = $(call inner-meson-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)
|
|
|
|
################################################################################
|
|
# Generation of the Meson cross-compilation.conf file
|
|
################################################################################
|
|
|
|
# Generate a Meson cross-compilation.conf suitable for use with the
|
|
# SDK; also install the file as a template for users to add their
|
|
# own flags if they need to.
|
|
define PKG_MESON_INSTALL_CROSS_CONF
|
|
mkdir -p $(HOST_DIR)/etc/meson
|
|
sed -e 's%@TARGET_CROSS@%$(TARGET_CROSS)%g' \
|
|
-e 's%@TARGET_ARCH@%$(HOST_MESON_TARGET_CPU_FAMILY)%g' \
|
|
-e 's%@TARGET_CPU@%$(HOST_MESON_TARGET_CPU)%g' \
|
|
-e 's%@TARGET_ENDIAN@%$(HOST_MESON_TARGET_ENDIAN)%g' \
|
|
-e "s%@TARGET_CFLAGS@%$(call make-sq-comma-list,$(TARGET_CFLAGS))@PKG_TARGET_CFLAGS@%g" \
|
|
-e "s%@TARGET_LDFLAGS@%$(call make-sq-comma-list,$(TARGET_LDFLAGS))@PKG_TARGET_CFLAGS@%g" \
|
|
-e "s%@TARGET_CXXFLAGS@%$(call make-sq-comma-list,$(TARGET_CXXFLAGS))@PKG_TARGET_CFLAGS@%g" \
|
|
-e 's%@HOST_DIR@%$(HOST_DIR)%g' \
|
|
-e 's%@STAGING_DIR@%$(STAGING_DIR)%g' \
|
|
-e 's%@STATIC@%$(if $(BR2_STATIC_LIBS),true,false)%g' \
|
|
$(HOST_MESON_PKGDIR)/cross-compilation.conf.in \
|
|
> $(HOST_DIR)/etc/meson/cross-compilation.conf.in
|
|
sed -e 's%@PKG_TARGET_CFLAGS@%%g' \
|
|
-e 's%@PKG_TARGET_LDFLAGS@%%g' \
|
|
-e 's%@PKG_TARGET_CXXFLAGS@%%g' \
|
|
$(HOST_DIR)/etc/meson/cross-compilation.conf.in \
|
|
> $(HOST_DIR)/etc/meson/cross-compilation.conf
|
|
endef
|
|
|
|
TOOLCHAIN_TARGET_FINALIZE_HOOKS += PKG_MESON_INSTALL_CROSS_CONF
|