blob: 3643b4f896eded47c9d8517ffc9585438bd62398 [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
Masahiro Yamada5a144a12018-05-09 16:23:48 +09006if test $# -ne 2; then
7 echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +02008 exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
12
Randy Dunlap934193a2018-07-01 19:46:06 -070013if ! test -r System.map ; then
Randy Dunlapf0b0d882018-09-06 16:37:24 -070014 echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +020015 exit 0
16fi
James Hogan8937e892013-02-06 12:56:59 +000017
Linus Torvaldscedd1862020-12-28 11:40:22 -080018# legacy behavior: "depmod" in /sbin, no /sbin in PATH
19PATH="$PATH:/sbin"
Randy Dunlap934193a2018-07-01 19:46:06 -070020if [ -z $(command -v $DEPMOD) ]; then
Randy Dunlap914b0872018-08-28 12:59:10 -070021 echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
Randy Dunlap934193a2018-07-01 19:46:06 -070022 echo "This is probably in the kmod package." >&2
Randy Dunlap914b0872018-08-28 12:59:10 -070023 exit 0
Randy Dunlap934193a2018-07-01 19:46:06 -070024fi
25
Michal Marekbfe54242011-06-09 16:35:41 +020026# older versions of depmod require the version string to start with three
27# numbers, so we cheat with a symlink here
28depmod_hack_needed=true
Michal Marek8fc62e52011-07-12 11:54:48 +020029tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
30mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
31if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
32 if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
33 -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
Michal Marekbfe54242011-06-09 16:35:41 +020034 depmod_hack_needed=false
35 fi
36fi
Michal Marek8fc62e52011-07-12 11:54:48 +020037rm -rf "$tmp_dir"
Michal Marekbfe54242011-06-09 16:35:41 +020038if $depmod_hack_needed; then
39 symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
40 ln -s "$KERNELRELEASE" "$symlink"
41 KERNELRELEASE=99.98.$KERNELRELEASE
42fi
43
Michal Marekfc4da9a2011-06-09 15:35:22 +020044set -- -ae -F System.map
45if test -n "$INSTALL_MOD_PATH"; then
46 set -- "$@" -b "$INSTALL_MOD_PATH"
47fi
Masahiro Yamada5a144a12018-05-09 16:23:48 +090048"$DEPMOD" "$@" "$KERNELRELEASE"
Michal Marekbfe54242011-06-09 16:35:41 +020049ret=$?
50
51if $depmod_hack_needed; then
52 rm -f "$symlink"
53fi
54
55exit $ret