depmod.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # A depmod wrapper used by the toplevel Makefile
  5. if test $# -ne 2; then
  6. echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2
  7. exit 1
  8. fi
  9. DEPMOD=$1
  10. KERNELRELEASE=$2
  11. if ! test -r System.map ; then
  12. echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
  13. exit 0
  14. fi
  15. if [ -z $(command -v $DEPMOD) ]; then
  16. echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
  17. echo "This is probably in the kmod package." >&2
  18. exit 0
  19. fi
  20. # older versions of depmod require the version string to start with three
  21. # numbers, so we cheat with a symlink here
  22. depmod_hack_needed=true
  23. tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
  24. mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
  25. if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
  26. if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
  27. -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
  28. depmod_hack_needed=false
  29. fi
  30. fi
  31. rm -rf "$tmp_dir"
  32. if $depmod_hack_needed; then
  33. symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
  34. ln -s "$KERNELRELEASE" "$symlink"
  35. KERNELRELEASE=99.98.$KERNELRELEASE
  36. fi
  37. set -- -ae -F System.map
  38. if test -n "$INSTALL_MOD_PATH"; then
  39. set -- "$@" -b "$INSTALL_MOD_PATH"
  40. fi
  41. "$DEPMOD" "$@" "$KERNELRELEASE"
  42. ret=$?
  43. if $depmod_hack_needed; then
  44. rm -f "$symlink"
  45. fi
  46. exit $ret