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