• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# A depmod wrapper used by the toplevel Makefile
5
6if test $# -ne 2 -a $# -ne 3; then
7	echo "Usage: $0 /sbin/depmod <kernelrelease> [System.map folder]" >&2
8	exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
12KBUILD_MIXED_TREE=$3
13
14if ! test -r ${KBUILD_MIXED_TREE}System.map ; then
15	echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2
16	exit 0
17fi
18
19# legacy behavior: "depmod" in /sbin, no /sbin in PATH
20PATH="$PATH:/sbin"
21if [ -z $(command -v $DEPMOD) ]; then
22	echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2
23	echo "This is probably in the kmod package." >&2
24	exit 0
25fi
26
27# 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
30tmp_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
35		depmod_hack_needed=false
36	fi
37fi
38rm -rf "$tmp_dir"
39if $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
45set -- -ae -F ${KBUILD_MIXED_TREE}System.map
46if test -n "$INSTALL_MOD_PATH"; then
47	set -- "$@" -b "$INSTALL_MOD_PATH"
48fi
49"$DEPMOD" "$@" "$KERNELRELEASE"
50ret=$?
51
52if $depmod_hack_needed; then
53	rm -f "$symlink"
54fi
55
56exit $ret
57