From 4523a26a12ab5f5c62208bce286c41e797b2af38 Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Thu, 4 Aug 2022 17:03:41 -0400 Subject: [PATCH] Refactor support for distro/version pattern rules in makefiles Create a new utility file, util.mk, which holds handy widgets for implementing makefiles, and rehome the code which underpins distro/version-based pattern rules there. Also, add a couple of other utility definitions. --- agent/containers/images/Makefile | 15 +++------------ jenkins/Makefile | 15 +++------------ utils/utils.mk | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 utils/utils.mk diff --git a/agent/containers/images/Makefile b/agent/containers/images/Makefile index 7bd391ef71..30990f1e7d 100644 --- a/agent/containers/images/Makefile +++ b/agent/containers/images/Makefile @@ -28,6 +28,9 @@ # all-dockerfiles: build all default distro ".repo" and ".Dockerfile" files # +# Include definition of _DISTROS +include ../utils/utils.mk + # By default we only build images for x86_64 architectures. _ARCH = x86_64 @@ -98,18 +101,6 @@ _WORKLOAD_RPMS = fio uperf # Not intended to be overridden with an environment variable. _ALL_RPMS = ${_TOOL_RPMS} ${_WORKLOAD_RPMS} -# Compose lists of potential distro-version strings with versions 0-99 -# (e.g., `_ALL_centos_VERSIONS` including "centos-7", "centos-8", "centos-9", -# `_ALL_fedora_VERSIONS` including "fedora-32", "fedora-33", and "fedora-34", -# and `_DISTROS` concatenating the contents of all the lists) which will be -# used to drive pattern matching on distro-based target rules. -_DIGITS := 0 1 2 3 4 5 6 7 8 9 -_NUMBERS := $(patsubst 0%,%,$(foreach tens,${_DIGITS},$(foreach ones,${_DIGITS},${tens}${ones}))) -_ALL_DISTRO_NAMES := centos fedora -_ADV_TMPL = _ALL_${d}_VERSIONS := $(foreach v,${_NUMBERS},${d}-${v}) # template for setting version lists -$(foreach d,${_ALL_DISTRO_NAMES},$(eval $(call _ADV_TMPL, ${d}))) # set _ALL_centos_VERSIONS, etc. -_DISTROS := $(foreach d,${_ALL_DISTRO_NAMES},${_ALL_${d}_VERSIONS}) - # By default we only build images for the following distributions. _DEFAULT_DISTROS = centos-7 centos-8 centos-9 fedora-35 diff --git a/jenkins/Makefile b/jenkins/Makefile index c0eb12aca5..5cd582f440 100644 --- a/jenkins/Makefile +++ b/jenkins/Makefile @@ -14,6 +14,9 @@ # push-rpmbuild-all: pushes all the default RPM build containers to the registry # +# Include definition of _DISTROS +include ../utils/utils.mk + # Default list of distributions for which to build containers in which to build RPMs RPMBUILD_BASEIMAGE_DEFAULTS = \ rhel-9 rhel-8 rhel-7 \ @@ -47,18 +50,6 @@ PKGMGR = dnf BRANCH := $(shell cat ./branch.name) -# Compose lists of potential distro-version strings with versions 0-99 -# (e.g., `_ALL_centos_VERSIONS` including "centos-7", "centos-8", "centos-9", -# `_ALL_fedora_VERSIONS` including "fedora-32", "fedora-33", and "fedora-34", -# and `_DISTROS` concatenating the contents of all the lists) which will be -# used to drive pattern matching on distro-based target rules. -_DIGITS := 0 1 2 3 4 5 6 7 8 9 -_NUMBERS := $(patsubst 0%,%,$(foreach tens,${_DIGITS},$(foreach ones,${_DIGITS},${tens}${ones}))) -_ALL_DISTRO_NAMES := centos fedora rhel -_ADV_TMPL = _ALL_${d}_VERSIONS := $(foreach v,${_NUMBERS},${d}-${v}) # template for setting version lists -$(foreach d,${_ALL_DISTRO_NAMES},$(eval $(call _ADV_TMPL, ${d}))) # set _ALL_centos_VERSIONS, etc. -_DISTROS := $(foreach d,${_ALL_DISTRO_NAMES},${_ALL_${d}_VERSIONS}) - # For any given target, extract the distribution name and version from the last # two fields, e.g., image-rpmbuild-rhel-7 would yield values "rhel" and "7" for # DIST_NAME and DIST_VERSION, respectively. diff --git a/utils/utils.mk b/utils/utils.mk new file mode 100644 index 0000000000..17ec192576 --- /dev/null +++ b/utils/utils.mk @@ -0,0 +1,26 @@ +# +# Utility widgets for makefiles +# +# This file is intended to be included into other makefiles. It provides useful +# devices of various sorts which are applicable to a variety of situations. +# + + +# Compose lists of potential distro-version strings with versions 0-99 +# (e.g., `_ALL_centos_VERSIONS` including "centos-7", "centos-8", "centos-9", +# `_ALL_fedora_VERSIONS` including "fedora-32", "fedora-33", and "fedora-34", +# `_ALL_rhel_VERSIONS` including "rhel-7", "rhel-8", and "rhel-9", and +# `_DISTROS` concatenating the contents of all the lists) which can be used to +# drive pattern matching on distro-based target rules. +_DIGITS := 0 1 2 3 4 5 6 7 8 9 +_NUMBERS := $(patsubst 0%,%,$(foreach tens,${_DIGITS},$(foreach ones,${_DIGITS},${tens}${ones}))) +_ALL_DISTRO_NAMES := centos fedora rhel +_ADV_TMPL = _ALL_${d}_VERSIONS := $(foreach v,${_NUMBERS},${d}-${v}) # template for setting version lists +$(foreach d,${_ALL_DISTRO_NAMES},$(eval $(call _ADV_TMPL, ${d}))) # set _ALL_centos_VERSIONS, etc. +_DISTROS := $(foreach d,${_ALL_DISTRO_NAMES},${_ALL_${d}_VERSIONS}) + +# In Make, it is hard to refer to a single blank or space character. This pair +# of definitions does that: create a definition which is literally empty, and +# then use that as a delimiter around a space character, and viola. +_empty:= +_space:= ${_empty} ${_empty}