eclass/linux-mod: Sync with Gentoo

It's from Gentoo commit eee74b9fca1b5237299ee08fd041997e7271304a.
This commit is contained in:
Krzesimir Nowak 2022-09-28 13:08:22 +02:00
parent 7986606ee5
commit 6621fcf787

View File

@ -19,14 +19,14 @@
# A Couple of env vars are available to effect usage of this eclass # A Couple of env vars are available to effect usage of this eclass
# These are as follows: # These are as follows:
# @ECLASS-VARIABLE: MODULES_OPTIONAL_USE # @ECLASS_VARIABLE: MODULES_OPTIONAL_USE
# @PRE_INHERIT # @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# A string containing the USE flag to use for making this eclass optional # A string containing the USE flag to use for making this eclass optional
# The recommended non-empty value is 'modules' # The recommended non-empty value is 'modules'
# @ECLASS-VARIABLE: MODULES_OPTIONAL_USE_IUSE_DEFAULT # @ECLASS_VARIABLE: MODULES_OPTIONAL_USE_IUSE_DEFAULT
# @PRE_INHERIT # @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -34,29 +34,29 @@
# flag. Default value is unset (false). True represented by 1 or 'on', other # flag. Default value is unset (false). True represented by 1 or 'on', other
# values including unset treated as false. # values including unset treated as false.
# @ECLASS-VARIABLE: KERNEL_DIR # @ECLASS_VARIABLE: KERNEL_DIR
# @DESCRIPTION: # @DESCRIPTION:
# A string containing the directory of the target kernel sources. The default value is # A string containing the directory of the target kernel sources. The default value is
# "/usr/src/linux" # "/usr/src/linux"
: ${KERNEL_DIR:=/usr/src/linux} : ${KERNEL_DIR:=/usr/src/linux}
# @ECLASS-VARIABLE: ECONF_PARAMS # @ECLASS_VARIABLE: ECONF_PARAMS
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# It's a string containing the parameters to pass to econf. # It's a string containing the parameters to pass to econf.
# If this is not set, then econf isn't run. # If this is not set, then econf isn't run.
# @ECLASS-VARIABLE: BUILD_PARAMS # @ECLASS_VARIABLE: BUILD_PARAMS
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# It's a string with the parameters to pass to emake. # It's a string with the parameters to pass to emake.
# @ECLASS-VARIABLE: BUILD_TARGETS # @ECLASS_VARIABLE: BUILD_TARGETS
# @DESCRIPTION: # @DESCRIPTION:
# It's a string with the build targets to pass to make. The default value is "clean module" # It's a string with the build targets to pass to make. The default value is "clean module"
: ${BUILD_TARGETS:=clean module} : ${BUILD_TARGETS:=clean module}
# @ECLASS-VARIABLE: MODULE_NAMES # @ECLASS_VARIABLE: MODULE_NAMES
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# It's a string containing the modules to be built automatically using the default # It's a string containing the modules to be built automatically using the default
@ -101,14 +101,14 @@
# There is also support for automated modprobe.d file generation. # There is also support for automated modprobe.d file generation.
# This can be explicitly enabled by setting any of the following variables. # This can be explicitly enabled by setting any of the following variables.
# @ECLASS-VARIABLE: MODULESD_<modulename>_ENABLED # @ECLASS_VARIABLE: MODULESD_<modulename>_ENABLED
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This is used to disable the modprobe.d file generation otherwise the file will be # This is used to disable the modprobe.d file generation otherwise the file will be
# always generated (unless no MODULESD_<modulename>_* variable is provided). Set to "no" to disable # always generated (unless no MODULESD_<modulename>_* variable is provided). Set to "no" to disable
# the generation of the file and the installation of the documentation. # the generation of the file and the installation of the documentation.
# @ECLASS-VARIABLE: MODULESD_<modulename>_EXAMPLES # @ECLASS_VARIABLE: MODULESD_<modulename>_EXAMPLES
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This is a bash array containing a list of examples which should # This is a bash array containing a list of examples which should
@ -120,7 +120,7 @@
# #
# where array_component is "<modulename> options" (see modprobe.conf(5)) # where array_component is "<modulename> options" (see modprobe.conf(5))
# @ECLASS-VARIABLE: MODULESD_<modulename>_ALIASES # @ECLASS_VARIABLE: MODULESD_<modulename>_ALIASES
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This is a bash array containing a list of associated aliases. # This is a bash array containing a list of associated aliases.
@ -131,20 +131,20 @@
# #
# where array_component is "wildcard <modulename>" (see modprobe.conf(5)) # where array_component is "wildcard <modulename>" (see modprobe.conf(5))
# @ECLASS-VARIABLE: MODULESD_<modulename>_ADDITIONS # @ECLASS_VARIABLE: MODULESD_<modulename>_ADDITIONS
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This is a bash array containing a list of additional things to # This is a bash array containing a list of additional things to
# add to the bottom of the file. This can be absolutely anything. # add to the bottom of the file. This can be absolutely anything.
# Each entry is a new line. # Each entry is a new line.
# @ECLASS-VARIABLE: MODULESD_<modulename>_DOCS # @ECLASS_VARIABLE: MODULESD_<modulename>_DOCS
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This is a string list which contains the full path to any associated # This is a string list which contains the full path to any associated
# documents for <modulename>. These files are installed in the live tree. # documents for <modulename>. These files are installed in the live tree.
# @ECLASS-VARIABLE: KV_OBJ # @ECLASS_VARIABLE: KV_OBJ
# @INTERNAL # @INTERNAL
# @DESCRIPTION: # @DESCRIPTION:
# It's a read-only variable. It contains the extension of the kernel modules. # It's a read-only variable. It contains the extension of the kernel modules.
@ -193,46 +193,6 @@ DEPEND="${RDEPEND}
# eclass utilities # eclass utilities
# ---------------------------------- # ----------------------------------
check_vermagic() {
debug-print-function ${FUNCNAME} $*
local curr_gcc_ver=$(gcc -dumpversion)
local tmpfile old_chost old_gcc_ver result=0
[ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
tmpfile=`find "${KV_DIR}/" -iname "*.o.cmd" -exec grep usr/lib/gcc {} \; -quit`
tmpfile=${tmpfile//*usr/lib}
tmpfile=${tmpfile//\/include*}
old_chost=${tmpfile//*gcc\/}
old_chost=${old_chost//\/*}
old_gcc_ver=${tmpfile//*\/}
if [[ -z ${old_gcc_ver} || -z ${old_chost} ]]; then
ewarn ""
ewarn "Unable to detect what version of GCC was used to compile"
ewarn "the kernel. Build will continue, but you may experience problems."
elif [[ ${curr_gcc_ver} != ${old_gcc_ver} ]]; then
ewarn ""
ewarn "The version of GCC you are using (${curr_gcc_ver}) does"
ewarn "not match the version of GCC used to compile the"
ewarn "kernel (${old_gcc_ver})."
result=1
elif [[ ${CHOST} != ${old_chost} ]]; then
ewarn ""
ewarn "The current CHOST (${CHOST}) does not match the chost"
ewarn "used when compiling the kernel (${old_chost})."
result=1
fi
if [[ ${result} -gt 0 ]]; then
ewarn ""
ewarn "Build will not continue, because you will experience problems."
ewarn "To fix this either change the version of GCC you wish to use"
ewarn "to match the kernel, or recompile the kernel first."
die "GCC Version Mismatch."
fi
}
# @FUNCTION: use_m # @FUNCTION: use_m
# @RETURN: true or false # @RETURN: true or false
# @DESCRIPTION: # @DESCRIPTION:
@ -267,11 +227,10 @@ convert_to_m() {
fi fi
} }
# internal function # @FUNCTION: update_depmod
# # @INTERNAL
# FUNCTION: update_depmod # @DESCRIPTION:
# DESCRIPTION: # Updates the modules.dep file for the current kernel.
# It updates the modules.dep file for the current kernel.
update_depmod() { update_depmod() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -292,11 +251,10 @@ update_depmod() {
fi fi
} }
# internal function # @FUNCTION: move_old_moduledb
# # @INTERNAL
# FUNCTION: move_old_moduledb # @DESCRIPTION:
# DESCRIPTION: # Updates the location of the database used by the module-rebuild utility.
# It updates the location of the database used by the module-rebuild utility.
move_old_moduledb() { move_old_moduledb() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -312,11 +270,9 @@ move_old_moduledb() {
fi fi
} }
# internal function # @FUNCTION: update_moduledb
# # @DESCRIPTION:
# FUNCTION: update_moduledb # Adds the package to the /var/lib/module-rebuild/moduledb database used by the module-rebuild utility.
# DESCRIPTION:
# It adds the package to the /var/lib/module-rebuild/moduledb database used by the module-rebuild utility.
update_moduledb() { update_moduledb() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -334,12 +290,9 @@ update_moduledb() {
fi fi
} }
# internal function # @FUNCTION: remove_moduledb
# # @DESCRIPTION:
# FUNCTION: remove_moduledb # Removes the package from the /var/lib/module-rebuild/moduledb database used by
# DESCRIPTION:
# It removes the package from the /var/lib/module-rebuild/moduledb database used by
# the module-rebuild utility.
remove_moduledb() { remove_moduledb() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -369,6 +322,10 @@ set_kvobj() {
# einfo "Using KV_OBJ=${KV_OBJ}" # einfo "Using KV_OBJ=${KV_OBJ}"
} }
# @FUNCTION: get-KERNEL_CC
# @RETURN: Name of the C compiler.
# @DESCRIPTION:
# Return name of the C compiler while honoring variables defined in ebuilds.
get-KERNEL_CC() { get-KERNEL_CC() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -389,12 +346,11 @@ get-KERNEL_CC() {
echo "${kernel_cc}" echo "${kernel_cc}"
} }
# internal function # @FUNCTION: generate_modulesd
# # @INTERNAL
# FUNCTION: # @USAGE: /path/to/the/modulename_without_extension
# USAGE: /path/to/the/modulename_without_extension # @RETURN: A file in /etc/modprobe.d
# RETURN: A file in /etc/modprobe.d # @DESCRIPTION:
# DESCRIPTION:
# This function will generate and install the neccessary modprobe.d file from the # This function will generate and install the neccessary modprobe.d file from the
# information contained in the modules exported parms. # information contained in the modules exported parms.
# (see the variables MODULESD_<modulename>_ENABLED, MODULESD_<modulename>_EXAMPLES, # (see the variables MODULESD_<modulename>_ENABLED, MODULESD_<modulename>_EXAMPLES,
@ -543,12 +499,11 @@ generate_modulesd() {
return 0 return 0
} }
# internal function # @FUNCTION: find_module_params
# # @USAGE: A string "NAME(LIBDIR:SRCDIR:OBJDIR)"
# FUNCTION: find_module_params # @INTERNAL
# USAGE: A string "NAME(LIBDIR:SRCDIR:OBJDIR)" # @RETURN: The string "modulename:NAME libdir:LIBDIR srcdir:SRCDIR objdir:OBJDIR"
# RETURN: The string "modulename:NAME libdir:LIBDIR srcdir:SRCDIR objdir:OBJDIR" # @DESCRIPTION:
# DESCRIPTION:
# Analyze the specification NAME(LIBDIR:SRCDIR:OBJDIR) of one module as described in MODULE_NAMES. # Analyze the specification NAME(LIBDIR:SRCDIR:OBJDIR) of one module as described in MODULE_NAMES.
find_module_params() { find_module_params() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -621,10 +576,6 @@ linux-mod_pkg_setup() {
strip_modulenames; strip_modulenames;
[[ -n ${MODULE_NAMES} ]] && check_modules_supported [[ -n ${MODULE_NAMES} ]] && check_modules_supported
set_kvobj; set_kvobj;
# Commented out with permission from johnm until a fixed version for arches
# who intentionally use different kernel and userland compilers can be
# introduced - Jason Wever <weeve@gentoo.org>, 23 Oct 2005
#check_vermagic;
} }
# @FUNCTION: linux-mod_pkg_setup_binary # @FUNCTION: linux-mod_pkg_setup_binary
@ -645,6 +596,9 @@ linux-mod_pkg_setup_binary() {
linux-info_pkg_setup; linux-info_pkg_setup;
} }
# @FUNCTION: strip_modulenames
# @DESCRIPTION:
# Remove modules from being built automatically using the default src_compile/src_install
strip_modulenames() { strip_modulenames() {
debug-print-function ${FUNCNAME} $* debug-print-function ${FUNCNAME} $*
@ -719,7 +673,7 @@ linux-mod_src_compile() {
fi fi
done done
set_arch_to_portage set_arch_to_pkgmgr
ABI="${myABI}" ABI="${myABI}"
} }
@ -757,7 +711,22 @@ linux-mod_src_install() {
einfo "Installing ${modulename} module" einfo "Installing ${modulename} module"
cd "${objdir}" || die "${objdir} does not exist" cd "${objdir}" || die "${objdir} does not exist"
insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir} insinto "${INSTALL_MOD_PATH}"/lib/modules/${KV_FULL}/${libdir}
# check here for CONFIG_MODULE_COMPRESS_<compression option> (NONE, GZIP, XZ, ZSTD)
# and similarily compress the module being built if != NONE.
if linux_chkconfig_present MODULE_COMPRESS_XZ; then
xz ${modulename}.${KV_OBJ}
doins ${modulename}.${KV_OBJ}.xz || die "doins ${modulename}.${KV_OBJ}.xz failed"
elif linux_chkconfig_present MODULE_COMPRESS_GZIP; then
gzip ${modulename}.${KV_OBJ}
doins ${modulename}.${KV_OBJ}.gz || die "doins ${modulename}.${KV_OBJ}.gz failed"
elif linux_chkconfig_present MODULE_COMPRESS_ZSTD; then
zstd ${modulename}.${KV_OBJ}
doins ${modulename}.${KV_OBJ}.zst || die "doins ${modulename}.${KV_OBJ}.zst failed"
else
doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed" doins ${modulename}.${KV_OBJ} || die "doins ${modulename}.${KV_OBJ} failed"
fi
cd "${OLDPWD}" cd "${OLDPWD}"
generate_modulesd "${objdir}/${modulename}" generate_modulesd "${objdir}/${modulename}"