xref: /openbmc/linux/scripts/depmod.sh (revision b34e08d5)
1#!/bin/sh
2#
3# A depmod wrapper used by the toplevel Makefile
4
5if test $# -ne 3; then
6	echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2
7	exit 1
8fi
9DEPMOD=$1
10KERNELRELEASE=$2
11SYMBOL_PREFIX=$3
12
13if ! test -r System.map -a -x "$DEPMOD"; then
14	exit 0
15fi
16
17# older versions of depmod don't support -P <symbol-prefix>
18# support was added in module-init-tools 3.13
19if test -n "$SYMBOL_PREFIX"; then
20	release=$("$DEPMOD" --version)
21	package=$(echo "$release" | cut -d' ' -f 1)
22	if test "$package" = "module-init-tools"; then
23		version=$(echo "$release" | cut -d' ' -f 2)
24		later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1)
25		if test "$later" != "$version"; then
26			# module-init-tools < 3.13, drop the symbol prefix
27			SYMBOL_PREFIX=""
28		fi
29	fi
30	if test -n "$SYMBOL_PREFIX"; then
31		SYMBOL_PREFIX="-P $SYMBOL_PREFIX"
32	fi
33fi
34
35# older versions of depmod require the version string to start with three
36# numbers, so we cheat with a symlink here
37depmod_hack_needed=true
38tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX)
39mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE"
40if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then
41	if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \
42		-e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then
43		depmod_hack_needed=false
44	fi
45fi
46rm -rf "$tmp_dir"
47if $depmod_hack_needed; then
48	symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE"
49	ln -s "$KERNELRELEASE" "$symlink"
50	KERNELRELEASE=99.98.$KERNELRELEASE
51fi
52
53set -- -ae -F System.map
54if test -n "$INSTALL_MOD_PATH"; then
55	set -- "$@" -b "$INSTALL_MOD_PATH"
56fi
57"$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX
58ret=$?
59
60if $depmod_hack_needed; then
61	rm -f "$symlink"
62fi
63
64exit $ret
65