re-order a little for alphabetical
[oweals/busybox.git] / examples / depmod.pl
index e65f07b686534b68faed26a4159d05af508ece5f..9af192208a44e391a906e503819c65e38903badc 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/perl -w
 # vi: set ts=4:
 # Copyright (c) 2001 David Schleef <ds@schleef.org>
-# Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
+# Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
 # Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
-# This program is free software; you can redistribute it and/or modify it 
+# Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
+# This program is free software; you can redistribute it and/or modify it
 # under the same terms as Perl itself.
 
 # TODO -- use strict mode...
@@ -18,7 +19,7 @@ use File::Find;
 my $basedir="";
 my $kernel;
 my $kernelsyms;
-my $stdout=1;
+my $stdout=0;
 my $verbose=0;
 
 
@@ -38,13 +39,13 @@ GetOptions(
 
 if (defined $opt{help}) {
        print
-               "$0 [OPTION]... [basedir]\n",
-               "\t-h --help\t\tShow this help screen\n",
-               "\t-b --basedir\t\tModules base directory (defaults to /lib/modules)\n",
-               "\t-k --kernel\t\tKernel binary for the target\n",
-               "\t-F --kernelsyms\t\tKernel symbol file\n",
-               "\t-n --stdout\t\tWrite to stdout instead of modules.dep\n",
-               "\t-v --verbose\t\tPrint out lots of debugging stuff\n",
+       "  $0 [OPTION]... [basedir]\n",
+       "     -h --help\t\tShow this help screen\n",
+       "     -b --basedir\tModules base directory (defaults to /lib/modules)\n",
+       "     -k --kernel\tKernel binary for the target\n",
+       "     -F --kernelsyms\tKernel symbol file\n",
+       "     -n --stdout\tWrite to stdout instead of <basedir>/modules.dep\n",
+       "     -v --verbose\tPrint out lots of debugging stuff\n",
        ;
        exit 1;
 }
@@ -53,12 +54,13 @@ if($basedir !~ m-/lib/modules-) {
     warn "WARNING: base directory does not match ..../lib/modules\n";
 }
 
-# Find the list of .o files living under $basedir 
+# Find the list of .o files living under $basedir
 #if ($verbose) { printf "Locating all modules\n"; }
+my($ofile) = "";
 my($file) = "";
 my(@liblist) = ();
-find sub { 
-       if ( -f $_  && ! -d $_ ) { 
+find sub {
+       if ( -f $_  && ! -d $_ ) {
                $file = $File::Find::name;
                if ( $file =~ /.o$/ ) {
                        push(@liblist, $file);
@@ -116,27 +118,35 @@ foreach $obj ( @liblist, $kernel ){
 foreach $module (keys %$dep) {
     $mod->{$module} = {};
     foreach (@{$dep->{$module}}) {
-        if( $exp->{$_} ) { 
+        if( $exp->{$_} ) {
             warn "resolved symbol $_ in file $exp->{$_}\n" if $verbose;
             next if $exp->{$_} =~ /vmlinux/;
             $mod->{$module}{$exp->{$_}} = 1;
         } else {
             warn "unresolved symbol $_ in file $module\n";
         }
-    } 
+    }
 }
 
 # resolve the dependancies for each module
-foreach $module ( keys %$mod )  {
-    print "$module:\t";
-    @sorted = sort bydep keys %{$mod->{$module}};
-    print join(" \\\n\t",@sorted);
-#    foreach $m (@sorted ) {
-#        print "\t$m\n";
-#    }
-    print "\n\n";
+if ($stdout == 1) {
+       foreach $module ( keys %$mod ) {
+               print "$module:\t";
+               @sorted = sort bydep keys %{$mod->{$module}};
+               print join(" \\\n\t",@sorted);
+               print "\n\n";
+       }
+} else {
+       open(OFILE, ">$basedir/modules.dep");
+       foreach $module ( keys %$mod ) {
+               print OFILE "$module:\t";
+               @sorted = sort bydep keys %{$mod->{$module}};
+               print OFILE join(" \\\n\t",@sorted);
+               print OFILE "\n\n";
+       }
 }
 
+
 sub bydep
 {
     foreach my $f ( keys %{$mod->{$b}} ) {
@@ -158,7 +168,7 @@ depmod.pl - a cross platform script to generate kernel module dependency
 
 =head1 SYNOPSIS
 
-depmod.pl [OPTION]... [FILE]...
+depmod.pl [OPTION]... [basedir]...
 
 Example:
 
@@ -212,9 +222,9 @@ Be verbose (not implemented)
 =head1 COPYRIGHT
 
 Copyright (c) 2001 David Schleef <ds@schleef.org>
-Copyright (c) 2001 Erik Andersen <andersen@lineo.com>
+Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
 Copyright (c) 2001 Stuart Hughes <stuarth@lineo.com>
-This program is free software; you can redistribute it and/or modify it 
+This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.
 
 =head1 AUTHOR
@@ -223,5 +233,5 @@ David Schleef <ds@schleef.org>
 
 =cut
 
-# $Id: depmod.pl,v 1.1 2001/07/30 19:32:03 andersen Exp $
+# $Id: depmod.pl,v 1.4 2004/03/15 08:28:33 andersen Exp $