depmod.sh 1.7 KB

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