install-extmod-build 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. set -eu
  4. destdir=${1}
  5. is_enabled() {
  6. grep -q "^$1=y" include/config/auto.conf
  7. }
  8. find_in_scripts() {
  9. find scripts \
  10. \( -name atomic -o -name dtc -o -name kconfig -o -name package \) -prune -o \
  11. ! -name unifdef -a ! -name mk_elfconfig -a \( -type f -o -type l \) -print
  12. }
  13. mkdir -p "${destdir}"
  14. (
  15. cd "${srctree}"
  16. echo Makefile
  17. find "arch/${SRCARCH}" -maxdepth 1 -name 'Makefile*'
  18. find "arch/${SRCARCH}" -name generated -prune -o -name include -type d -print
  19. find "arch/${SRCARCH}" -name Kbuild.platforms -o -name Platform
  20. find include \( -name config -o -name generated \) -prune -o \( -type f -o -type l \) -print
  21. find_in_scripts
  22. ) | tar -c -f - -C "${srctree}" -T - | tar -xf - -C "${destdir}"
  23. {
  24. if is_enabled CONFIG_OBJTOOL; then
  25. echo tools/objtool/objtool
  26. fi
  27. echo Module.symvers
  28. echo "arch/${SRCARCH}/include/generated"
  29. echo include/config/auto.conf
  30. echo include/config/kernel.release
  31. echo include/generated
  32. find_in_scripts
  33. if is_enabled CONFIG_GCC_PLUGINS; then
  34. find scripts/gcc-plugins -name '*.so'
  35. fi
  36. } | tar -c -f - -T - | tar -xf - -C "${destdir}"
  37. # When ${CC} and ${HOSTCC} differ, rebuild host programs using ${CC}.
  38. #
  39. # This caters to host programs that participate in Kbuild. objtool and
  40. # resolve_btfids are out of scope.
  41. if [ "${CC}" != "${HOSTCC}" ]; then
  42. echo "Rebuilding host programs with ${CC}..."
  43. cat <<-'EOF' > "${destdir}/Kbuild"
  44. subdir-y := scripts
  45. EOF
  46. # HOSTCXX is not overridden. The C++ compiler is used to build:
  47. # - scripts/kconfig/qconf, which is unneeded for external module builds
  48. # - GCC plugins, which will not work on the installed system even after
  49. # being rebuilt.
  50. #
  51. # Use the single-target build to avoid the modpost invocation, which
  52. # would overwrite Module.symvers.
  53. "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
  54. cat <<-'EOF' > "${destdir}/scripts/Kbuild"
  55. subdir-y := basic
  56. hostprogs-always-y := mod/modpost
  57. mod/modpost-objs := $(addprefix mod/, modpost.o file2alias.o sumversion.o symsearch.o)
  58. EOF
  59. # Run once again to rebuild scripts/basic/ and scripts/mod/modpost.
  60. "${MAKE}" HOSTCC="${CC}" KBUILD_EXTMOD="${destdir}" scripts/
  61. rm -f "${destdir}/Kbuild" "${destdir}/scripts/Kbuild"
  62. fi
  63. find "${destdir}" \( -name '.*.cmd' -o -name '*.o' \) -delete