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