blob: 8d421c6ab5a15c62767a413bf5e40b2e1eeab067 [file] [log] [blame]
Denis Vlasenkobd23fbb2008-05-24 20:54:14 +00001#!/bin/sh
2#
3# Simple depmod, use to generate modprobe.conf
4#
5# Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
6#
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkobd23fbb2008-05-24 20:54:14 +00008#
9
Denys Vlasenkobca4ea82017-01-24 20:52:42 +010010BASE="${1:-/usr/lib/modules}"
Denis Vlasenkobd23fbb2008-05-24 20:54:14 +000011
12find "$BASE" -name '*.ko.gz' | while read I ; do
13 N=`basename "$I" '.ko.gz'`
14 echo -n "@$N"
15 zcat "$I" | strings | grep '^depends=' | sed -e 's/^depends=$//' -e 's/^depends=/,/' -e 's/,/ @/g'
16done | awk '
17{
18 # modules which has no dependencies are resolved
19 if ( NF == 1 ) { res[$1] = ""; next }
20 # others have to be resolved based on those which already resolved
21 i = $1; $1 = ""; deps[i] = $0; ++ndeps
22}
23END {
24 # resolve implicit dependencies
25 while ( ndeps ) for (mod in deps) {
26 if ( index(deps[mod], "@") > 0 ) {
27 $0 = deps[mod]
28 for ( i=1; i<=NF; ++i ) {
29 if ( substr($i,1,1) == "@" ) {
30 if ( $i in res ) {
31 $i = res[$i] " " substr($i,2)
32 }
33 }
34 }
35 deps[mod] = $0
36 } else {
37 res[mod] = deps[mod]
38 delete deps[mod]
39 --ndeps
40 }
41 }
42
43 # output dependencies in modules.dep format
44 for ( mod in res ) {
45 $0 = res[mod]
46 s = ""
47 delete a
48 for ( i=1; i<=NF; ++i ) {
49 if ( ! ($i in a) ) {
50 a[$i] = $i
51 s = " ," $i s
52 }
53 }
54 print "," substr(mod,2) ":" s
55 }
56}
57' | sort | sed -r -e "s!,([^,: ]*)!/usr/lib/modules/\\1.ko.gz!g"