Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / scripts / depmod.sh
blob9831cca31240b8b9890d701308ed53bcd62c2ccf
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # A depmod wrapper used by the toplevel Makefile
6 if test $# -ne 3; then
7 echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
8 exit 1
9 fi
10 DEPMOD=$1
11 KERNELRELEASE=$2
12 SYMBOL_PREFIX=$3
14 if ! test -r System.map -a -x "$DEPMOD"; then
15 exit 0
18 # older versions of depmod don't support -P <symbol-prefix>
19 # support was added in module-init-tools 3.13
20 if 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=""
31 if test -n "$SYMBOL_PREFIX"; then
32 SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
36 # older versions of depmod require the version string to start with three
37 # numbers, so we cheat with a symlink here
38 depmod_hack_needed=true
39 tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
40 mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
41 if "$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
47 rm -rf "$tmp_dir"
48 if $depmod_hack_needed; then
49 symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
50 ln -s "$KERNELRELEASE" "$symlink"
51 KERNELRELEASE=99.98.$KERNELRELEASE
54 set -- -ae -F System.map
55 if test -n "$INSTALL_MOD_PATH"; then
56 set -- "$@" -b "$INSTALL_MOD_PATH"
58 "$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
59 ret=$?
61 if $depmod_hack_needed; then
62 rm -f "$symlink"
65 exit $ret