3 # Copyright (c) 2001 David Schleef <ds@schleef.org>
4 # Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
5 # Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the same terms as Perl itself.
9 # TODO -- use strict mode...
16 # Set up some default values
25 # get command-line options
32 "basedir|b=s" => \$basedir,
33 "kernel|k=s" => \$kernel,
34 "kernelsyms|F=s" => \$kernelsyms,
35 "stdout|n" => \$stdout,
36 "verbose|v" => \$verbose,
39 if (defined $opt{help}) {
41 "$0 [OPTION]... [basedir]\n",
42 "\t-h --help\t\tShow this help screen\n",
43 "\t-b --basedir\t\tModules base directory (defaults to /lib/modules)\n",
44 "\t-k --kernel\t\tKernel binary for the target\n",
45 "\t-F --kernelsyms\t\tKernel symbol file\n",
46 "\t-n --stdout\t\tWrite to stdout instead of modules.dep\n",
47 "\t-v --verbose\t\tPrint out lots of debugging stuff\n",
52 if($basedir !~ m-/lib/modules-) {
53 warn "WARNING: base directory does not match ..../lib/modules\n";
56 # Find the list of .o files living under $basedir
57 #if ($verbose) { printf "Locating all modules\n"; }
61 if ( -f $_ && ! -d $_ ) {
62 $file = $File::Find::name;
63 if ( $file =~ /.o$/ ) {
64 push(@liblist, $file);
65 if ($verbose) { printf "$file\n"; }
69 if ($verbose) { printf "Finished locating modules\n"; }
71 foreach $obj ( @liblist, $kernel ){
72 # turn the input file name into a target tag name
73 # vmlinux is a special that is only used to resolve symbols
74 if($obj =~ /vmlinux/) {
77 ($tgtname) = $obj =~ m-(/lib/modules/.*)$-;
80 warn "MODULE = $tgtname\n" if $verbose;
82 # get a list of symbols
84 $ksymtab=grep m/ __ksymtab/, @output;
86 # gather the exported symbols
90 / __ksymtab_(.*)$/ and do {
91 warn "sym = $1\n" if $verbose;
92 $exp->{$1} = $tgtname;
96 # exporting all symbols
98 / [ABCDGRST] (.*)$/ and do {
99 warn "syma = $1\n" if $verbose;
100 $exp->{$1} = $tgtname;
104 # gather the unresolved symbols
105 foreach ( @output ) {
106 !/ __this_module/ && / U (.*)$/ and do {
107 warn "und = $1\n" if $verbose;
108 push @{$dep->{$tgtname}}, $1;
114 # reduce dependancies: remove unresolvable and resolved from vmlinux
116 foreach $module (keys %$dep) {
117 $mod->{$module} = {};
118 foreach (@{$dep->{$module}}) {
120 warn "resolved symbol $_ in file $exp->{$_}\n" if $verbose;
121 next if $exp->{$_} =~ /vmlinux/;
122 $mod->{$module}{$exp->{$_}} = 1;
124 warn "unresolved symbol $_ in file $module\n";
129 # resolve the dependancies for each module
130 foreach $module ( keys %$mod ) {
132 @sorted = sort bydep keys %{$mod->{$module}};
133 print join(" \\\n\t",@sorted);
134 # foreach $m (@sorted ) {
142 foreach my $f ( keys %{$mod->{$b}} ) {
156 depmod.pl - a cross platform script to generate kernel module dependency
157 lists which can then be used by modprobe.
161 depmod.pl [OPTION]... [FILE]...
165 depmod.pl -F linux/System.map target/lib/modules
169 The purpose of this script is to automagically generate a list of of kernel
170 module dependancies. This script produces dependancy lists that should be
171 identical to the depmod program from the modutils package. Unlike the depmod
172 binary, however, depmod.pl is designed to be run on your host system, not
173 on your target system.
175 This script was written by David Schleef <ds@schleef.org> to be used in
176 conjunction with the BusyBox modprobe applet.
184 This displays the help message.
186 =item B<-b --basedir>
188 The base directory uner which the target's modules will be found. This
189 defaults to the /lib/modules directory.
193 Kernel binary for the target. You must either supply a kernel binary
194 or a kernel symbol file (using the -F option).
196 =item B<-F --kernelsyms>
198 Kernel symbol file for the target. You must supply either a kernel symbol file
199 kernel binary for the target (using the -k option).
203 Write to stdout instead of modules.dep. This is currently hard coded...
204 kernel binary for the target (using the -k option).
208 Be verbose (not implemented)
214 Copyright (c) 2001 David Schleef <ds@schleef.org>
215 Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
216 Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
217 This program is free software; you can redistribute it and/or modify it
218 under the same terms as Perl itself.
222 David Schleef <ds@schleef.org>
226 # $Id: depmod.pl,v 1.1 2001/07/30 19:32:03 andersen Exp $