[e1000] Use PCI_BASE_ADDRESS_* symbols instead of integers
[gpxe.git] / contrib / initrd / include-modules
blob60e76fc6f73f688fc076182f2b7a1b305c8b0ddb
1 #!/usr/bin/perl -w
3 # Retrieve modules required for an initrd image
4 # $Id$
6 unless ( @ARGV ) {
7 die "Syntax: $0 [ -d target_directory ] module_1 module_2 module_3\n"
10 # Parse command line arguments
11 my @requested_modules = ();
12 my $target_dir = "";
13 my $kernel_ver;
14 my $quiet;
15 chomp ( my $current_kernel_ver = `uname -r` );
16 while ( $_ = shift ) {
17 if ( /-d/ ) { $target_dir = shift }
18 elsif ( /-k/ ) { $kernel_ver = shift }
19 elsif ( /-q/ ) { $quiet = 1 }
20 else { push @requested_modules, $_ };
23 # Create target directory if required
24 if ( $target_dir ) {
25 print STDERR "Target directory is $target_dir\n" unless $quiet;
26 system ( "mkdir -p $target_dir" );
27 chdir $target_dir;
30 # Use modprobe -nav to retrieve locations of modules and their dependencies
31 print STDERR "Requested modules ". join (' ', @requested_modules)."\n" unless $quiet;
32 my @modules_dups;
33 foreach my $module ( @requested_modules ) {
34 my @module_list = map { /^\S+\s+(.*)$/ ; $1 } `/sbin/modprobe -nva $module`;
35 die "Cannot find any modules matching $module\n" unless @module_list;
36 push @modules_dups, @module_list;
39 # Remove duplicates from list
40 my %module_basenames = ();
41 my @modules = ();
42 foreach my $module ( @modules_dups ) {
43 # Ugly hack : assume that dependencies are independent of kernel version
44 # This seems to be necessary because we can't run modprobe and specify
45 # an alternate modules.dep file; it refuses to understand lines of the
46 # form "depfile=XXX" as documented in modules.conf(5)
47 $module =~ s/$current_kernel_ver/$kernel_ver/ if $kernel_ver;
48 push @modules, $module unless $module_basenames{$module};
49 ( my $basename ) = ( $module =~ /([^\/]+)\.o/ );
50 $module_basenames{$module} = $basename;
53 # Process module list
54 print "#!/bin/sh\n";
55 foreach my $module ( @modules ) {
56 my $basename = $module_basenames{$module};
57 # Report via stdout
58 print STDERR "Using module $basename from $module\n" unless $quiet;
59 # Copy uncompressed module to current directory
60 system ("gunzip -c $module > $basename.o");
61 # Print insmod line to stdout
62 print "insmod $basename\n";