blob: 1a6f85e0e6e15731367fe4696129d0d5d91f1a0a [file] [log] [blame]
Michal Marekfc4da9a2011-06-09 15:35:22 +02001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Michal Marekfc4da9a2011-06-09 15:35:22 +02003#
4# A depmod wrapper used by the toplevel Makefile
5
Masahiro Yamada5a144a12018-05-09 16:23:48 +09006if test $# -ne 2; then
7 echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2
Michal Marekfc4da9a2011-06-09 15:35:22 +02008 exit 1
9fi
10DEPMOD=$1
11KERNELRELEASE=$2
12
Michal Marekfc4da9a2011-06-09 15:35:22 +020013if ! test -r System.map -a -x "$DEPMOD"; then
14 exit 0
15fi
James Hogan8937e892013-02-06 12:56:59 +000016
Michal Marekbfe54242011-06-09 16:35:41 +020017# 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
Michal Marek8fc62e52011-07-12 11:54:48 +020020tmp_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
Michal Marekbfe54242011-06-09 16:35:41 +020025 depmod_hack_needed=false
26 fi
27fi
Michal Marek8fc62e52011-07-12 11:54:48 +020028rm -rf "$tmp_dir"
Michal Marekbfe54242011-06-09 16:35:41 +020029if $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
Michal Marekfc4da9a2011-06-09 15:35:22 +020035set -- -ae -F System.map
36if test -n "$INSTALL_MOD_PATH"; then
37 set -- "$@" -b "$INSTALL_MOD_PATH"
38fi
Masahiro Yamada5a144a12018-05-09 16:23:48 +090039"$DEPMOD" "$@" "$KERNELRELEASE"
Michal Marekbfe54242011-06-09 16:35:41 +020040ret=$?
41
42if $depmod_hack_needed; then
43 rm -f "$symlink"
44fi
45
46exit $ret