xref: /linux/scripts/depmod.sh (revision 856e7c4b619af622d56b3b454f7bec32a170ac99)
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 -a -x "$DEPMOD"; then
14	exit 0
15fi
16
17# older versions of depmod require the version string to start with three
18# numbers, so we cheat with a symlink here
19depmod_hack_needed=true
20tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
21mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
22if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
23	if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
24		-e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
25		depmod_hack_needed=false
26	fi
27fi
28rm -rf "$tmp_dir"
29if $depmod_hack_needed; then
30	symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
31	ln -s "$KERNELRELEASE" "$symlink"
32	KERNELRELEASE=99.98.$KERNELRELEASE
33fi
34
35set -- -ae -F System.map
36if test -n "$INSTALL_MOD_PATH"; then
37	set -- "$@" -b "$INSTALL_MOD_PATH"
38fi
39"$DEPMOD" "$@" "$KERNELRELEASE"
40ret=$?
41
42if $depmod_hack_needed; then
43	rm -f "$symlink"
44fi
45
46exit $ret
47