blob: c7b8f827c4b0918a668b1e35650da2f3acbed686 [file] [log] [blame]
Michal Marekfc4da9a2011-06-09 15:35:22 +02001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Michal Marekfc4da9a2011-06-09 15:35:22 +02003#
4# A depmod wrapper used by the toplevel Makefile
5
James Hogan8937e892013-02-06 12:56:59 +00006if test $# -ne 3; then
7 echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +02008 exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
James Hogan8937e892013-02-06 12:56:59 +000012SYMBOL_PREFIX=$3
Michal Marekfc4da9a2011-06-09 15:35:22 +020013
Randy Dunlap50123ab2018-07-01 19:46:06 -070014if ! test -r System.map ; then
Michal Marekfc4da9a2011-06-09 15:35:22 +020015 exit 0
16fi
James Hogan8937e892013-02-06 12:56:59 +000017
Linus Torvaldsf236d692020-12-28 11:40:22 -080018# legacy behavior: "depmod" in /sbin, no /sbin in PATH
19PATH="$PATH:/sbin"
Randy Dunlap50123ab2018-07-01 19:46:06 -070020if [ -z $(command -v $DEPMOD) ]; then
Randy Dunlap93708682018-08-28 12:59:10 -070021 echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
Randy Dunlap50123ab2018-07-01 19:46:06 -070022 echo "This is probably in the kmod package." >&2
Randy Dunlap93708682018-08-28 12:59:10 -070023 exit 0
Randy Dunlap50123ab2018-07-01 19:46:06 -070024fi
25
James Hogan8937e892013-02-06 12:56:59 +000026# older versions of depmod don't support -P <symbol-prefix>
27# support was added in module-init-tools 3.13
28if test -n "$SYMBOL_PREFIX"; then
29 release=$("$DEPMOD" --version)
30 package=$(echo "$release" | cut -d' ' -f 1)
31 if test "$package" = "module-init-tools"; then
32 version=$(echo "$release" | cut -d' ' -f 2)
33 later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1)
34 if test "$later" != "$version"; then
35 # module-init-tools < 3.13, drop the symbol prefix
36 SYMBOL_PREFIX=""
37 fi
38 fi
39 if test -n "$SYMBOL_PREFIX"; then
40 SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
41 fi
42fi
43
Michal Marekbfe54242011-06-09 16:35:41 +020044# older versions of depmod require the version string to start with three
45# numbers, so we cheat with a symlink here
46depmod_hack_needed=true
Michal Marek8fc62e52011-07-12 11:54:48 +020047tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
48mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
49if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
50 if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
51 -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
Michal Marekbfe54242011-06-09 16:35:41 +020052 depmod_hack_needed=false
53 fi
54fi
Michal Marek8fc62e52011-07-12 11:54:48 +020055rm -rf "$tmp_dir"
Michal Marekbfe54242011-06-09 16:35:41 +020056if $depmod_hack_needed; then
57 symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
58 ln -s "$KERNELRELEASE" "$symlink"
59 KERNELRELEASE=99.98.$KERNELRELEASE
60fi
61
Michal Marekfc4da9a2011-06-09 15:35:22 +020062set -- -ae -F System.map
63if test -n "$INSTALL_MOD_PATH"; then
64 set -- "$@" -b "$INSTALL_MOD_PATH"
65fi
James Hogan8937e892013-02-06 12:56:59 +000066"$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
Michal Marekbfe54242011-06-09 16:35:41 +020067ret=$?
68
69if $depmod_hack_needed; then
70 rm -f "$symlink"
71fi
72
73exit $ret