18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# A depmod wrapper used by the toplevel Makefile 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciif test $# -ne 2; then 78c2ecf20Sopenharmony_ci echo "Usage: $0 /sbin/depmod <kernelrelease>" >&2 88c2ecf20Sopenharmony_ci exit 1 98c2ecf20Sopenharmony_cifi 108c2ecf20Sopenharmony_ciDEPMOD=$1 118c2ecf20Sopenharmony_ciKERNELRELEASE=$2 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciif ! test -r System.map ; then 148c2ecf20Sopenharmony_ci echo "Warning: modules_install: missing 'System.map' file. Skipping depmod." >&2 158c2ecf20Sopenharmony_ci exit 0 168c2ecf20Sopenharmony_cifi 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci# legacy behavior: "depmod" in /sbin, no /sbin in PATH 198c2ecf20Sopenharmony_ciPATH="$PATH:/sbin" 208c2ecf20Sopenharmony_ciif [ -z $(command -v $DEPMOD) ]; then 218c2ecf20Sopenharmony_ci echo "Warning: 'make modules_install' requires $DEPMOD. Please install it." >&2 228c2ecf20Sopenharmony_ci echo "This is probably in the kmod package." >&2 238c2ecf20Sopenharmony_ci exit 0 248c2ecf20Sopenharmony_cifi 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci# older versions of depmod require the version string to start with three 278c2ecf20Sopenharmony_ci# numbers, so we cheat with a symlink here 288c2ecf20Sopenharmony_cidepmod_hack_needed=true 298c2ecf20Sopenharmony_citmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/depmod.XXXXXX) 308c2ecf20Sopenharmony_cimkdir -p "$tmp_dir/lib/modules/$KERNELRELEASE" 318c2ecf20Sopenharmony_ciif "$DEPMOD" -b "$tmp_dir" $KERNELRELEASE 2>/dev/null; then 328c2ecf20Sopenharmony_ci if test -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep" -o \ 338c2ecf20Sopenharmony_ci -e "$tmp_dir/lib/modules/$KERNELRELEASE/modules.dep.bin"; then 348c2ecf20Sopenharmony_ci depmod_hack_needed=false 358c2ecf20Sopenharmony_ci fi 368c2ecf20Sopenharmony_cifi 378c2ecf20Sopenharmony_cirm -rf "$tmp_dir" 388c2ecf20Sopenharmony_ciif $depmod_hack_needed; then 398c2ecf20Sopenharmony_ci symlink="$INSTALL_MOD_PATH/lib/modules/99.98.$KERNELRELEASE" 408c2ecf20Sopenharmony_ci ln -s "$KERNELRELEASE" "$symlink" 418c2ecf20Sopenharmony_ci KERNELRELEASE=99.98.$KERNELRELEASE 428c2ecf20Sopenharmony_cifi 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciset -- -ae -F System.map 458c2ecf20Sopenharmony_ciif test -n "$INSTALL_MOD_PATH"; then 468c2ecf20Sopenharmony_ci set -- "$@" -b "$INSTALL_MOD_PATH" 478c2ecf20Sopenharmony_cifi 488c2ecf20Sopenharmony_ci"$DEPMOD" "$@" "$KERNELRELEASE" 498c2ecf20Sopenharmony_ciret=$? 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciif $depmod_hack_needed; then 528c2ecf20Sopenharmony_ci rm -f "$symlink" 538c2ecf20Sopenharmony_cifi 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciexit $ret 56