install-extmod-build 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. if is_enabled CONFIG_DEBUG_INFO_BTF_MODULES; then
  28. echo tools/bpf/resolve_btfids/resolve_btfids
  29. fi
  30. echo Module.symvers
  31. echo "arch/${SRCARCH}/include/generated"
  32. echo include/config/auto.conf
  33. echo include/config/kernel.release
  34. echo include/generated
  35. find_in_scripts
  36. if is_enabled CONFIG_GCC_PLUGINS; then
  37. find scripts/gcc-plugins -name '*.so'
  38. fi
  39. } | tar -c -f - -T - | tar -xf - -C "${destdir}"
  40. # When ${CC} and ${HOSTCC} differ, rebuild host programs using ${CC}.
  41. #
  42. # This caters to host programs that participate in Kbuild. objtool and
  43. # resolve_btfids are out of scope.
  44. if [ "${CC}" != "${HOSTCC}" ]; then
  45. cat "${destdir}/scripts/Makefile" - <<-'EOF' > "${destdir}/scripts/Kbuild"
  46. subdir-y += basic
  47. hostprogs-always-y += mod/modpost
  48. mod/modpost-objs := $(addprefix mod/, modpost.o file2alias.o sumversion.o symsearch.o)
  49. EOF
  50. # HOSTCXX is not overridden. The C++ compiler is used to build:
  51. # - scripts/kconfig/qconf, which is unneeded for external module builds
  52. # - GCC plugins, which will not work on the installed system even after
  53. # being rebuilt.
  54. #
  55. # Clear VPATH and srcroot because the source files reside in the output
  56. # directory.
  57. # shellcheck disable=SC2016 # $(MAKE) and $(build) will be expanded by Make
  58. "${MAKE}" run-command KBUILD_RUN_COMMAND='+$(MAKE) HOSTCC="'"${CC}"'" VPATH= srcroot=. $(build)='"$(realpath --relative-to=. "${destdir}")"/scripts
  59. rm -f "${destdir}/scripts/Kbuild"
  60. fi
  61. find "${destdir}" \( -name '.*.cmd' -o -name '*.o' \) -delete