The kernel we're building against may have had its tools (e.g. modpost)
built for the target arch or even some other arch than the we're
building with now. To work around this, rebuild those tools with make
modules_prepare when necessary.

Doing this in pkg_setup is not ideal, but some ebuilds have their own
src_configure and src_compile functions. It will not trigger in the vast
majority of cases, and it is not done when installing binary packages.

Signed-off-by: James Le Cuirot <ch...@gentoo.org>
---
 eclass/linux-mod-r1.eclass | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 16c280219ef89..9047b962819c1 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -351,6 +351,8 @@ linux-mod-r1_pkg_setup() {

        _modules_set_makeargs

+       _modules_prepare_cross
+
        _modules_sanity_gccplugins
 }

@@ -668,6 +670,36 @@ _modules_check_migration() {
        # - ECONF_PARAMS: documented but was a no-op in linux-mod too
 }

+# @FUNCTION: _modules_prepare_cross
+# @INTERNAL
+# @DESCRIPTION:
+# Checks whether modpost works locally as it might have been built for a
+# different architecture.  If it doesn't work, it is built in a new
+# environment and KV_OUT_DIR is repointed there.
+_modules_prepare_cross() {
+       # modpost should do nothing successfully when called without args.
+       if ! "${KV_OUT_DIR}"/scripts/mod/modpost &>/dev/null; then
+               # Try to run make modules_prepare in a new separate output 
directory.
+               # This cannot be done if the source directory is not clean. In 
that
+               # case, copy the whole source directory.
+               if [[ -e ${KV_DIR}/.config ]]; then
+                       cp -rLT --reflink=auto -- "${KV_DIR}" 
"${WORKDIR}"/extmod-build || die
+                       emake -C "${WORKDIR}"/extmod-build 
"${MODULES_MAKEARGS[@]}" modules_prepare \
+                               KBUILD_OUTPUT=
+               else
+                       mkdir -- "${WORKDIR}"/extmod-build || die
+                       cp -- "${KV_OUT_DIR}"/{.config,Module.symvers} 
"${WORKDIR}"/extmod-build || die
+                       # KV_OUT_DIR may have been prepared with 
install-extmod-build, which
+                       # doesn't include all the files needed to call make 
modules_prepare,
+                       # so use the Makefile from the full kernel sources.
+                       emake -C "${WORKDIR}"/extmod-build 
"${MODULES_MAKEARGS[@]}" modules_prepare \
+                               KBUILD_OUTPUT="${WORKDIR}"/extmod-build -f 
"${KERNEL_MAKEFILE}"
+               fi
+               KV_OUT_DIR=${WORKDIR}/extmod-build
+               KBUILD_OUTPUT=${KBUILD_OUTPUT+${KV_OUT_DIR}}
+       fi
+}
+
 # @FUNCTION: _modules_prepare_kernel
 # @INTERNAL
 # @DESCRIPTION:
--
2.49.0

Reply via email to