# Note: Due to the addition of build numbers, we have to be somewhat more careful here.
# If module A depends on module B version 3.1.0, then it should record the current build number and save
# that. Otherwise we can end up in a situation where a new module being installed can cause dependencies
# to fail to load correctly. The goal of the below is to explicitly add the latest build number, if none
# is specified. It works as follows:
# $(if $(shell [[ "$($1_VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$$ ]] && echo match), ## We test that the module version is of the form x.y.z exactly. In that case...
# $(notdir $(firstword $(shell ls -dvr $(E3_SITEMODS_PATH)/$1/$($1_VERSION)?(-+([0-9])) 2> /dev/null ))), ## ...find the highest build number with the given version...
# $($1_VERSION)) ## ... else preserve the module number as is.
defineADD_SITEMODS_INCLUDES
$(eval $(1)_VERSION := $(patsubst ${E3_SITEMODS_PATH}/$(1)/%/include,%,$(firstword $(shell ls -dvr ${E3_SITEMODS_PATH}/$(1)/$(VERSIONGLOB)/include 2>/dev/null))))
@$(foreach m,${REQ},echo "$m$(or ${$m_VERSION},$(and $(wildcard ${E3_SITEMODS_PATH}/$m),$(error REQUIRED module $m has no numbered version. Set $m_VERSION)),$(warning REQUIRED module $m not found for ${T_A}.))">>$@;)
@$(foreach m,${REQ},echo "$m$(or ${$m_VERSION_BUILD},$(and $(wildcard ${E3_SITEMODS_PATH}/$m),$(error REQUIRED module $m has no numbered version. Set $m_VERSION)),$(warning REQUIRED module $m not found for ${T_A}.))">>$@;)
endif
# Update the version numbers to ensure that the build number is included