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 | |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 14 | if ! test -r System.map -a -x "$DEPMOD"; then |
| 15 | exit 0 |
| 16 | fi |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 17 | |
| 18 | # older versions of depmod don't support -P <symbol-prefix> |
| 19 | # support was added in module-init-tools 3.13 |
| 20 | if test -n "$SYMBOL_PREFIX"; then |
| 21 | release=$("$DEPMOD" --version) |
| 22 | package=$(echo "$release" | cut -d' ' -f 1) |
| 23 | if test "$package" = "module-init-tools"; then |
| 24 | version=$(echo "$release" | cut -d' ' -f 2) |
| 25 | later=$(printf '%s\n' "$version" "3.13" | sort -V | tail -n 1) |
| 26 | if test "$later" != "$version"; then |
| 27 | # module-init-tools < 3.13, drop the symbol prefix |
| 28 | SYMBOL_PREFIX="" |
| 29 | fi |
| 30 | fi |
| 31 | if test -n "$SYMBOL_PREFIX"; then |
| 32 | SYMBOL_PREFIX="-P $SYMBOL_PREFIX" |
| 33 | fi |
| 34 | fi |
| 35 | |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 36 | # older versions of depmod require the version string to start with three |
| 37 | # numbers, so we cheat with a symlink here |
| 38 | depmod_hack_needed=true |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 39 | tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) |
| 40 | mkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" |
| 41 | if "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then |
| 42 | if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \ |
| 43 | -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 44 | depmod_hack_needed=false |
| 45 | fi |
| 46 | fi |
Michal Marek | 8fc62e5 | 2011-07-12 11:54:48 +0200 | [diff] [blame] | 47 | rm -rf "$tmp_dir" |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 48 | if $depmod_hack_needed; then |
| 49 | symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" |
| 50 | ln -s "$KERNELRELEASE" "$symlink" |
| 51 | KERNELRELEASE=99.98.$KERNELRELEASE |
| 52 | fi |
| 53 | |
Michal Marek | fc4da9a | 2011-06-09 15:35:22 +0200 | [diff] [blame] | 54 | set -- -ae -F System.map |
| 55 | if test -n "$INSTALL_MOD_PATH"; then |
| 56 | set -- "$@" -b "$INSTALL_MOD_PATH" |
| 57 | fi |
James Hogan | 8937e89 | 2013-02-06 12:56:59 +0000 | [diff] [blame] | 58 | "$DEPMOD" "$@" "$KERNELRELEASE" $SYMBOL_PREFIX |
Michal Marek | bfe5424 | 2011-06-09 16:35:41 +0200 | [diff] [blame] | 59 | ret=$? |
| 60 | |
| 61 | if $depmod_hack_needed; then |
| 62 | rm -f "$symlink" |
| 63 | fi |
| 64 | |
| 65 | exit $ret |