Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[platform/kernel/linux-rpi.git] / scripts / depmod.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # A depmod wrapper used by the toplevel Makefile
5
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
13
14 if ! test -r System.map -a -x "$DEPMOD"; then
15         exit 0
16 fi
17
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=""
29                 fi
30         fi
31         if test -n "$SYMBOL_PREFIX"; then
32                 SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
33         fi
34 fi
35
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
45         fi
46 fi
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
52 fi
53
54 set -- -ae -F System.map
55 if test -n "$INSTALL_MOD_PATH"; then
56         set -- "$@" -b "$INSTALL_MOD_PATH"
57 fi
58 "$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
59 ret=$?
60
61 if $depmod_hack_needed; then
62         rm -f "$symlink"
63 fi
64
65 exit $ret