#!/bin/sh -eu

# dummy depmod implementation for use in tests.  We can't reasonably
# include binary modules as test data, and the real depmod will fail
# if we give it fake module files.
#
# This needs to print some module dependencies rather than just doing
# nothing, because copy-modules reasonably treats that as an error.

basedir=
dry_run=
installedname=

while [ $# -gt 0 ]; do
    case "$1" in
    -b)
	basedir="$2"
	shift 2
	;;
    -n)
	dry_run=y
	shift
	;;
    -*)
	echo >&2 "$0: unsupported option $1"
	exit 2
	;;
    *)
	if [ "$installedname" ]; then
	   echo >&2 "$0: multiple versions given"
	   exit 2
	fi
	installedname="$1"
	shift
	;;
    esac
done

if [ -z "$dry_run" ]; then
    echo >&2 "%0: missing option -n"
    exit 2
fi

lastpath=
find "$basedir/lib/modules/$installedname" -name '*.ko*' -printf '%P\n' \
| LC_COLLATE=C.UTF-8 sort \
| while read path; do
    echo "$path: $lastpath"
    lastpath="$path"
done
