3 # Copyright (c) 2001 David Schleef <ds@schleef.org>
4 # Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
5 # Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
6 # Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
7 # This program is free software; you can redistribute it and/or modify it
8 # under the same terms as Perl itself.
10 # TODO -- use strict mode...
17 # Set up some default values
26 # get command-line options
33 "basedir|b=s" => \$basedir,
34 "kernel|k=s" => \$kernel,
35 "kernelsyms|F=s" => \$kernelsyms,
36 "stdout|n" => \$stdout,
37 "verbose|v" => \$verbose,
40 if (defined $opt{help}) {
42 " $0 [OPTION]... [basedir]\n",
43 " -h --help\t\tShow this help screen\n",
44 " -b --basedir\tModules base directory (defaults to /lib/modules)\n",
45 " -k --kernel\tKernel binary for the target\n",
46 " -F --kernelsyms\tKernel symbol file\n",
47 " -n --stdout\tWrite to stdout instead of <basedir>/modules.dep\n",
48 " -v --verbose\tPrint out lots of debugging stuff\n",
53 if($basedir !~ m-/lib/modules-) {
54 warn "WARNING: base directory does not match ..../lib/modules\n";
57 # Find the list of .o files living under $basedir
58 #if ($verbose) { printf "Locating all modules\n"; }
63 if ( -f $_ && ! -d $_ ) {
64 $file = $File::Find::name;
65 if ( $file =~ /.o$/ ) {
66 push(@liblist, $file);
67 if ($verbose) { printf "$file\n"; }
71 if ($verbose) { printf "Finished locating modules\n"; }
73 foreach $obj ( @liblist, $kernel ){
74 # turn the input file name into a target tag name
75 # vmlinux is a special that is only used to resolve symbols
76 if($obj =~ /vmlinux/) {
79 ($tgtname) = $obj =~ m-(/lib/modules/.*)$-;
82 warn "MODULE = $tgtname\n" if $verbose;
84 # get a list of symbols
86 $ksymtab=grep m/ __ksymtab/, @output;
88 # gather the exported symbols
92 / __ksymtab_(.*)$/ and do {
93 warn "sym = $1\n" if $verbose;
94 $exp->{$1} = $tgtname;
98 # exporting all symbols
100 / [ABCDGRST] (.*)$/ and do {
101 warn "syma = $1\n" if $verbose;
102 $exp->{$1} = $tgtname;
106 # gather the unresolved symbols
107 foreach ( @output ) {
108 !/ __this_module/ && / U (.*)$/ and do {
109 warn "und = $1\n" if $verbose;
110 push @{$dep->{$tgtname}}, $1;
116 # reduce dependancies: remove unresolvable and resolved from vmlinux
118 foreach $module (keys %$dep) {
119 $mod->{$module} = {};
120 foreach (@{$dep->{$module}}) {
122 warn "resolved symbol $_ in file $exp->{$_}\n" if $verbose;
123 next if $exp->{$_} =~ /vmlinux/;
124 $mod->{$module}{$exp->{$_}} = 1;
126 warn "unresolved symbol $_ in file $module\n";
131 # resolve the dependancies for each module
133 foreach $module ( keys %$mod ) {
135 @sorted = sort bydep keys %{$mod->{$module}};
136 print join(" \\\n\t",@sorted);
140 open(OFILE, ">$basedir/modules.dep");
141 foreach $module ( keys %$mod ) {
142 print OFILE "$module:\t";
143 @sorted = sort bydep keys %{$mod->{$module}};
144 print OFILE join(" \\\n\t",@sorted);
152 foreach my $f ( keys %{$mod->{$b}} ) {
166 depmod.pl - a cross platform script to generate kernel module dependency
167 lists which can then be used by modprobe.
171 depmod.pl [OPTION]... [basedir]...
175 depmod.pl -F linux/System.map target/lib/modules
179 The purpose of this script is to automagically generate a list of of kernel
180 module dependancies. This script produces dependancy lists that should be
181 identical to the depmod program from the modutils package. Unlike the depmod
182 binary, however, depmod.pl is designed to be run on your host system, not
183 on your target system.
185 This script was written by David Schleef <ds@schleef.org> to be used in
186 conjunction with the BusyBox modprobe applet.
194 This displays the help message.
196 =item B<-b --basedir>
198 The base directory uner which the target's modules will be found. This
199 defaults to the /lib/modules directory.
203 Kernel binary for the target. You must either supply a kernel binary
204 or a kernel symbol file (using the -F option).
206 =item B<-F --kernelsyms>
208 Kernel symbol file for the target. You must supply either a kernel symbol file
209 kernel binary for the target (using the -k option).
213 Write to stdout instead of modules.dep. This is currently hard coded...
214 kernel binary for the target (using the -k option).
218 Be verbose (not implemented)
224 Copyright (c) 2001 David Schleef <ds@schleef.org>
225 Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
226 Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
227 This program is free software; you can redistribute it and/or modify it
228 under the same terms as Perl itself.
232 David Schleef <ds@schleef.org>
236 # $Id: depmod.pl,v 1.3 2003/07/14 21:20:51 andersen Exp $