Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 3 | # |
| 4 | # A depmod wrapper used by the toplevel Makefile |
| 5 | |
Masahiro Yamada | 5a144a1 | 2018-05-09 16:23:48 +0900 | [diff] [blame] | 6 | if test $# -ne 2; then |
| 7 | echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2 |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 8 | exit 1 |
| 9 | fi |
| 10 | DEPMOD=$1 |
| 11 | KERNELRELEASE=$2 |
| 12 | |
Randy Dunlap | 934193a | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 13 | if ! test -r System.map ; then |
Randy Dunlap | f0b0d88 | 2018-09-06 16:37:24 -0700 | [diff] [blame] | 14 | echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2 |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 15 | exit 0 |
| 16 | fi |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 17 | |
Randy Dunlap | 934193a | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 18 | if [ -z $(command -v $DEPMOD) ]; then |
Randy Dunlap | 914b087 | 2018-08-28 12:59:10 -0700 | [diff] [blame] | 19 | echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2 |
Randy Dunlap | 934193a | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 20 | echo "This is probably in the kmod package." >&2 |
Randy Dunlap | 914b087 | 2018-08-28 12:59:10 -0700 | [diff] [blame] | 21 | exit 0 |
Randy Dunlap | 934193a | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 22 | fi |
| 23 | |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 24 | # older versions of depmod require the version string to start with three |
| 25 | # numbers, so we cheat with a symlink here |
| 26 | depmod_hack_needed=true |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 27 | tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) |
| 28 | mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" |
| 29 | if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then |
| 30 | if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \ |
| 31 | -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 32 | depmod_hack_needed=false |
| 33 | fi |
| 34 | fi |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 35 | rm -rf "$tmp_dir" |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 36 | if $depmod_hack_needed; then |
| 37 | symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" |
| 38 | ln -s "$KERNELRELEASE" "$symlink" |
| 39 | KERNELRELEASE=99.98.$KERNELRELEASE |
| 40 | fi |
| 41 | |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 42 | set -- -ae -F System.map |
| 43 | if test -n "$INSTALL_MOD_PATH"; then |
| 44 | set -- "$@" -b "$INSTALL_MOD_PATH" |
| 45 | fi |
Masahiro Yamada | 5a144a1 | 2018-05-09 16:23:48 +0900 | [diff] [blame] | 46 | "$DEPMOD" "$@" "$KERNELRELEASE" |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 47 | ret=$? |
| 48 | |
| 49 | if $depmod_hack_needed; then |
| 50 | rm -f "$symlink" |
| 51 | fi |
| 52 | |
| 53 | exit $ret |