xref: /openbmc/linux/scripts/depmod.sh (revision 934193a6)
1fc4da9a3SMichal Marek#!/bin/sh
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3fc4da9a3SMichal Marek#
4fc4da9a3SMichal Marek# A depmod wrapper used by the toplevel Makefile
5fc4da9a3SMichal Marek
65a144a1aSMasahiro Yamadaif test $# -ne 2; then
75a144a1aSMasahiro Yamada	echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2
8fc4da9a3SMichal Marek	exit 1
9fc4da9a3SMichal Marekfi
10fc4da9a3SMichal MarekDEPMOD=$1
11fc4da9a3SMichal MarekKERNELRELEASE=$2
12fc4da9a3SMichal Marek
13934193a6SRandy Dunlapif ! test -r System.map ; then
14fc4da9a3SMichal Marek	exit 0
15fc4da9a3SMichal Marekfi
168937e897SJames Hogan
17934193a6SRandy Dunlapif [ -z $(command -v $DEPMOD) ]; then
18934193a6SRandy Dunlap	echo "'make modules_install' requires $DEPMOD. Please install it." >&2
19934193a6SRandy Dunlap	echo "This is probably in the kmod package." >&2
20934193a6SRandy Dunlap	exit 1
21934193a6SRandy Dunlapfi
22934193a6SRandy Dunlap
23bfe5424aSMichal Marek# older versions of depmod require the version string to start with three
24bfe5424aSMichal Marek# numbers, so we cheat with a symlink here
25bfe5424aSMichal Marekdepmod_hack_needed=true
268fc62e59SMichal Marektmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
278fc62e59SMichal Marekmkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
288fc62e59SMichal Marekif "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
298fc62e59SMichal Marek	if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
308fc62e59SMichal Marek		-e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
31bfe5424aSMichal Marek		depmod_hack_needed=false
32bfe5424aSMichal Marek	fi
33bfe5424aSMichal Marekfi
348fc62e59SMichal Marekrm -rf "$tmp_dir"
35bfe5424aSMichal Marekif $depmod_hack_needed; then
36bfe5424aSMichal Marek	symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
37bfe5424aSMichal Marek	ln -s "$KERNELRELEASE" "$symlink"
38bfe5424aSMichal Marek	KERNELRELEASE=99.98.$KERNELRELEASE
39bfe5424aSMichal Marekfi
40bfe5424aSMichal Marek
41fc4da9a3SMichal Marekset -- -ae -F System.map
42fc4da9a3SMichal Marekif test -n "$INSTALL_MOD_PATH"; then
43fc4da9a3SMichal Marek	set -- "$@" -b "$INSTALL_MOD_PATH"
44fc4da9a3SMichal Marekfi
455a144a1aSMasahiro Yamada"$DEPMOD" "$@" "$KERNELRELEASE"
46bfe5424aSMichal Marekret=$?
47bfe5424aSMichal Marek
48bfe5424aSMichal Marekif $depmod_hack_needed; then
49bfe5424aSMichal Marek	rm -f "$symlink"
50bfe5424aSMichal Marekfi
51bfe5424aSMichal Marek
52bfe5424aSMichal Marekexit $ret
53