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 | |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 6 | if test $# -ne 3; then |
| 7 | echo "Usage: $0 /sbin/depmod <kernelrelease> <symbolprefix>" >&2 |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 8 | exit 1 |
| 9 | fi |
| 10 | DEPMOD=$1 |
| 11 | KERNELRELEASE=$2 |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 12 | SYMBOL_PREFIX=$3 |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 13 | |
Randy Dunlap | 50123ab | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 14 | if ! test -r System.map ; then |
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 | |
Linus Torvalds | f236d69 | 2020-12-28 11:40:22 -0800 | [diff] [blame] | 18 | # legacy behavior: "depmod" in /sbin, no /sbin in PATH |
| 19 | PATH="$PATH:/sbin" |
Randy Dunlap | 50123ab | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 20 | if [ -z $(command -v $DEPMOD) ]; then |
Randy Dunlap | 9370868 | 2018-08-28 12:59:10 -0700 | [diff] [blame] | 21 | echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2 |
Randy Dunlap | 50123ab | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 22 | echo "This is probably in the kmod package." >&2 |
Randy Dunlap | 9370868 | 2018-08-28 12:59:10 -0700 | [diff] [blame] | 23 | exit 0 |
Randy Dunlap | 50123ab | 2018-07-01 19:46:06 -0700 | [diff] [blame] | 24 | fi |
| 25 | |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 26 | # older versions of depmod don't support -P <symbol-prefix> |
| 27 | # support was added in module-init-tools 3.13 |
| 28 | if test -n "$SYMBOL_PREFIX"; then |
| 29 | release=$("$DEPMOD" --version) |
| 30 | package=$(echo "$release" | cut -d' ' -f 1) |
| 31 | if test "$package" = "module-init-tools"; then |
| 32 | version=$(echo "$release" | cut -d' ' -f 2) |
| 33 | later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1) |
| 34 | if test "$later" != "$version"; then |
| 35 | # module-init-tools < 3.13, drop the symbol prefix |
| 36 | SYMBOL_PREFIX="" |
| 37 | fi |
| 38 | fi |
| 39 | if test -n "$SYMBOL_PREFIX"; then |
| 40 | SYMBOL_PREFIX="-P $SYMBOL_PREFIX" |
| 41 | fi |
| 42 | fi |
| 43 | |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 44 | # older versions of depmod require the version string to start with three |
| 45 | # numbers, so we cheat with a symlink here |
| 46 | depmod_hack_needed=true |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 47 | tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) |
| 48 | mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" |
| 49 | if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then |
| 50 | if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \ |
| 51 | -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 52 | depmod_hack_needed=false |
| 53 | fi |
| 54 | fi |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 55 | rm -rf "$tmp_dir" |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 56 | if $depmod_hack_needed; then |
| 57 | symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" |
| 58 | ln -s "$KERNELRELEASE" "$symlink" |
| 59 | KERNELRELEASE=99.98.$KERNELRELEASE |
| 60 | fi |
| 61 | |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 62 | set -- -ae -F System.map |
| 63 | if test -n "$INSTALL_MOD_PATH"; then |
| 64 | set -- "$@" -b "$INSTALL_MOD_PATH" |
| 65 | fi |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 66 | "$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 67 | ret=$? |
| 68 | |
| 69 | if $depmod_hack_needed; then |
| 70 | rm -f "$symlink" |
| 71 | fi |
| 72 | |
| 73 | exit $ret |