| # |
| # Copyright 2021 Google LLC |
| # |
| # This program is free software; you can redistribute it and/or |
| # modify it under the terms of the GNU General Public License |
| # version 2 as published by the Free Software Foundation. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| |
| # Check for EAPI 5+ |
| case "${EAPI:-0}" in |
| 0|1|2|3|4) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;; |
| 5|6) inherit eapi7-ver ;; |
| 7) ;; |
| esac |
| |
| inherit linux-info linux-mod toolchain-funcs |
| |
| IUSE=" |
| +clang |
| +llvm_ias |
| module_sign |
| " |
| |
| REQUIRED_USE=" |
| llvm_ias? ( clang ) |
| " |
| |
| # Because our kernel version string ends with '+' (e.g. |
| # "4.4.21+"), Gentoo Linux's linux-info.eclass cannot locate the kernel build |
| # output directory. Hence we set it up here. |
| KBUILD_OUTPUT="${KERNEL_DIR}"/build |
| |
| pkg_setup() { |
| CONFIG_CHECK="" |
| MODULE_NAMES="${MODULE_NAME}(::)" |
| linux-mod_pkg_setup |
| BUILD_PARAMS="KERNEL_SOURCES=${KV_DIR} KBUILD_OUTPUT=${KBUILD_OUTPUT}" |
| } |
| |
| cos-linux-mod_src_prepare() { |
| # Allowing gcc to be used when clang is not set. |
| # This is copied from cros-kernel2.eclass to make sure the third |
| # party kernel module uses the same compiler as kernel. |
| use clang || cros_use_gcc |
| |
| default |
| } |
| |
| cos-linux-mod_src_compile() { |
| # Assemble with LLVM's integrated assembler on x86_64 and aarch64 |
| if use llvm_ias; then |
| export LLVM_IAS=1 |
| fi |
| BUILD_TARGETS="module" linux-mod_src_compile |
| } |
| |
| cos-linux-mod_src_install() { |
| if use module_sign ; then |
| # Sign the module first. |
| cp ${MODULE_NAME}.ko ${MODULE_NAME}.ko.orig |
| "${KBUILD_OUTPUT}"/scripts/sign-file \ |
| sha256 \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.pem \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.x509 \ |
| ${MODULE_NAME}.ko |
| fi |
| |
| linux-mod_src_install |
| } |