depmod.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # A depmod wrapper used by the toplevel Makefile
  5. if test $# -ne 3; then
  6. echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
  7. exit 1
  8. fi
  9. DEPMOD=$1
  10. KERNELRELEASE=$2
  11. SYMBOL_PREFIX=$3
  12. if ! test -r System.map ; then
  13. exit 0
  14. fi
  15. # legacy behavior: "depmod" in /sbin, no /sbin in PATH
  16. PATH="$PATH:/sbin"
  17. if [ -z $(command -v $DEPMOD) ]; then
  18. echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
  19. echo "This is probably in the kmod package." >&2
  20. exit 0
  21. fi
  22. # older versions of depmod don't support -P <symbol-prefix>
  23. # support was added in module-init-tools 3.13
  24. if test -n "$SYMBOL_PREFIX"; then
  25. release=$("$DEPMOD" --version)
  26. package=$(echo "$release" | cut -d' ' -f 1)
  27. if test "$package" = "module-init-tools"; then
  28. version=$(echo "$release" | cut -d' ' -f 2)
  29. later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1)
  30. if test "$later" != "$version"; then
  31. # module-init-tools < 3.13, drop the symbol prefix
  32. SYMBOL_PREFIX=""
  33. fi
  34. fi
  35. if test -n "$SYMBOL_PREFIX"; then
  36. SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
  37. fi
  38. fi
  39. # older versions of depmod require the version string to start with three
  40. # numbers, so we cheat with a symlink here
  41. depmod_hack_needed=true
  42. tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
  43. mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
  44. if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
  45. if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
  46. -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
  47. depmod_hack_needed=false
  48. fi
  49. fi
  50. rm -rf "$tmp_dir"
  51. if $depmod_hack_needed; then
  52. symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
  53. ln -s "$KERNELRELEASE" "$symlink"
  54. KERNELRELEASE=99.98.$KERNELRELEASE
  55. fi
  56. set -- -ae -F System.map
  57. if test -n "$INSTALL_MOD_PATH"; then
  58. set -- "$@" -b "$INSTALL_MOD_PATH"
  59. fi
  60. "$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
  61. ret=$?
  62. if $depmod_hack_needed; then
  63. rm -f "$symlink"
  64. fi
  65. exit $ret