kumquat-buildroot/package/pkg-waf.mk
Yann E. MORIN 1f6b283dd9 package/pkg-*.mk: do not conditionally set empty variables
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>
2021-12-30 21:30:08 +01:00

121 lines
3.8 KiB
Makefile

################################################################################
# WAF package infrastructure
#
# This file implements an infrastructure that eases development of package
# .mk files for WAF packages. It should be used for all packages that use
# WAF as their build system.
#
# See the Buildroot documentation for details on the usage of this
# infrastructure
#
# In terms of implementation, this WAF 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 WAF behaviour. The package can also define some
# post operation hooks.
#
################################################################################
################################################################################
# inner-waf-package -- defines how the configuration, compilation and
# installation of a waf package should be done, implements a few hooks
# to tune the build process for waf specifities 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-waf-package
# We need host-python3 to run waf
$(2)_DEPENDENCIES += host-python3
$(2)_NEEDS_EXTERNAL_WAF ?= NO
# If the package does not have its own waf, use our own.
ifeq ($$($(2)_NEEDS_EXTERNAL_WAF),YES)
$(2)_DEPENDENCIES += host-waf
$(2)_WAF = $$(HOST_DIR)/bin/waf
else
$(2)_WAF ?= ./waf
endif
#
# Configure step. Only define it if not already defined by the package
# .mk file.
#
ifndef $(2)_CONFIGURE_CMDS
define $(2)_CONFIGURE_CMDS
cd $$($$(PKG)_SRCDIR) && \
$$(TARGET_CONFIGURE_OPTS) \
$$($(2)_CONF_ENV) \
$$(HOST_DIR)/bin/python3 $$($(2)_WAF) configure \
--prefix=/usr \
--libdir=/usr/lib \
$$($(2)_CONF_OPTS) \
$$($(2)_WAF_OPTS)
endef
endif
#
# Build step. Only define it if not already defined by the package .mk
# file.
#
ifndef $(2)_BUILD_CMDS
define $(2)_BUILD_CMDS
cd $$($$(PKG)_SRCDIR) && \
$$(TARGET_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
build -j $$(PARALLEL_JOBS) $$($(2)_BUILD_OPTS) \
$$($(2)_WAF_OPTS)
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
cd $$($$(PKG)_SRCDIR) && \
$$(TARGET_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
install --destdir=$$(STAGING_DIR) \
$$($(2)_INSTALL_STAGING_OPTS) \
$$($(2)_WAF_OPTS)
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
cd $$($$(PKG)_SRCDIR) && \
$$(TARGET_MAKE_ENV) $$(HOST_DIR)/bin/python3 $$($(2)_WAF) \
install --destdir=$$(TARGET_DIR) \
$$($(2)_INSTALL_TARGET_OPTS) \
$$($(2)_WAF_OPTS)
endef
endif
# Call the generic package infrastructure to generate the necessary
# make targets
$(call inner-generic-package,$(1),$(2),$(3),$(4))
endef
################################################################################
# waf-package -- the target generator macro for WAF packages
################################################################################
waf-package = $(call inner-waf-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)