xref: /openbmc/linux/scripts/depmod.sh (revision eb7ebfa3)
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; then
7	echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2
8	exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
12
13if ! test -r System.map ; then
14	exit 0
15fi
16
17if [ -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
23# 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
26tmp_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
31		depmod_hack_needed=false
32	fi
33fi
34rm -rf "$tmp_dir"
35if $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
41set -- -ae -F System.map
42if test -n "$INSTALL_MOD_PATH"; then
43	set -- "$@" -b "$INSTALL_MOD_PATH"
44fi
45"$DEPMOD" "$@" "$KERNELRELEASE"
46ret=$?
47
48if $depmod_hack_needed; then
49	rm -f "$symlink"
50fi
51
52exit $ret
53