blob: 999d585eaa7358dd813b8b0d5a204fc1ea48ca3c [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
Michal Marekfc4da9a2011-06-09 15:35:22 +020014 exit 0
15fi
James Hogan8937e892013-02-06 12:56:59 +000016
Randy Dunlap934193a2018-07-01 19:46:06 -070017if [ -z $(command -v $DEPMOD) ]; then
18 echo "'make modules_install' requires $DEPMOD. Please install it." >&2
19 echo "This is probably in the kmod package." >&2
20 exit 1
21fi
22
Michal Marekbfe54242011-06-09 16:35:41 +020023# older versions of depmod require the version string to start with three
24# numbers, so we cheat with a symlink here
25depmod_hack_needed=true
Michal Marek8fc62e52011-07-12 11:54:48 +020026tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
27mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
28if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
29 if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
30 -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
Michal Marekbfe54242011-06-09 16:35:41 +020031 depmod_hack_needed=false
32 fi
33fi
Michal Marek8fc62e52011-07-12 11:54:48 +020034rm -rf "$tmp_dir"
Michal Marekbfe54242011-06-09 16:35:41 +020035if $depmod_hack_needed; then
36 symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
37 ln -s "$KERNELRELEASE" "$symlink"
38 KERNELRELEASE=99.98.$KERNELRELEASE
39fi
40
Michal Marekfc4da9a2011-06-09 15:35:22 +020041set -- -ae -F System.map
42if test -n "$INSTALL_MOD_PATH"; then
43 set -- "$@" -b "$INSTALL_MOD_PATH"
44fi
Masahiro Yamada5a144a12018-05-09 16:23:48 +090045"$DEPMOD" "$@" "$KERNELRELEASE"
Michal Marekbfe54242011-06-09 16:35:41 +020046ret=$?
47
48if $depmod_hack_needed; then
49 rm -f "$symlink"
50fi
51
52exit $ret