blob: 2de598d4691a06daf74ee9d43ecb9de0dd4186f3 [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
Elliot Berman7d5e1de2021-04-07 08:03:11 -07006if test $# -ne 2 -a $# -ne 3; then
7 echo "Usage: $0 /sbin/depmod <kernelrelease> [System.map folder]" >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +02008 exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
Elliot Berman7d5e1de2021-04-07 08:03:11 -070012KBUILD_MIXED_TREE=$3
Michal Marekfc4da9a2011-06-09 15:35:22 +020013
Elliot Berman7d5e1de2021-04-07 08:03:11 -070014if ! test -r ${KBUILD_MIXED_TREE}System.map ; then
Randy Dunlapf0b0d882018-09-06 16:37:24 -070015 echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +020016 exit 0
17fi
James Hogan8937e892013-02-06 12:56:59 +000018
Linus Torvalds43dee882020-12-28 11:40:22 -080019# legacy behavior: "depmod" in /sbin, no /sbin in PATH
20PATH="$PATH:/sbin"
Randy Dunlap934193a2018-07-01 19:46:06 -070021if [ -z $(command -v $DEPMOD) ]; then
Randy Dunlap914b0872018-08-28 12:59:10 -070022 echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
Randy Dunlap934193a2018-07-01 19:46:06 -070023 echo "This is probably in the kmod package." >&2
Randy Dunlap914b0872018-08-28 12:59:10 -070024 exit 0
Randy Dunlap934193a2018-07-01 19:46:06 -070025fi
26
Michal Marekbfe54242011-06-09 16:35:41 +020027# older versions of depmod require the version string to start with three
28# numbers, so we cheat with a symlink here
29depmod_hack_needed=true
Michal Marek8fc62e52011-07-12 11:54:48 +020030tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
31mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
32if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
33 if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
34 -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
Michal Marekbfe54242011-06-09 16:35:41 +020035 depmod_hack_needed=false
36 fi
37fi
Michal Marek8fc62e52011-07-12 11:54:48 +020038rm -rf "$tmp_dir"
Michal Marekbfe54242011-06-09 16:35:41 +020039if $depmod_hack_needed; then
40 symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
41 ln -s "$KERNELRELEASE" "$symlink"
42 KERNELRELEASE=99.98.$KERNELRELEASE
43fi
44
Elliot Berman7d5e1de2021-04-07 08:03:11 -070045set -- -ae -F ${KBUILD_MIXED_TREE}System.map
Michal Marekfc4da9a2011-06-09 15:35:22 +020046if test -n "$INSTALL_MOD_PATH"; then
47 set -- "$@" -b "$INSTALL_MOD_PATH"
48fi
Masahiro Yamada5a144a12018-05-09 16:23:48 +090049"$DEPMOD" "$@" "$KERNELRELEASE"
Michal Marekbfe54242011-06-09 16:35:41 +020050ret=$?
51
52if $depmod_hack_needed; then
53 rm -f "$symlink"
54fi
55
56exit $ret