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 | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 16c280219ef89..e8b6cb83f30fb 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -352,6 +352,31 @@ linux-mod-r1_pkg_setup() {
        _modules_set_makeargs
 
        _modules_sanity_gccplugins
+
+       # Check whether modpost runs locally as it might have been built for a
+       # different arch. It should do nothing successfully when called without
+       # args. If it doesn't run, build it with make modules_prepare in a new
+       # environment using just the necessary files, and repoint KV_OUT_DIR 
there.
+       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 there is not already a separate output
+               # directory because the build system will complain that the 
source
+               # directory is not clean. In that case, copy the source 
directory.
+               if [[ ${KV_OUT_DIR} -ef ${KV_DIR} ]]; then
+                       cp -rsLT "${KV_OUT_DIR}" "${WORKDIR}"/extmod-build || 
die
+                       emake -C "${WORKDIR}"/extmod-build 
"${MODULES_MAKEARGS[@]}" modules_prepare
+               else
+                       mkdir "${WORKDIR}"/extmod-build || die
+                       # Don't use /proc/config.gz as it probably won't match 
this kernel.
+                       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 \
+                               -f "${KERNEL_MAKEFILE}" 
KBUILD_OUTPUT="${WORKDIR}"/extmod-build
+               fi
+               KV_OUT_DIR="${WORKDIR}"/extmod-build
+       fi
 }
 
 # @FUNCTION: linux-mod-r1_src_compile
-- 
2.49.0


Reply via email to