Rename .lilo extension to .lkrn and updated dependencies
[gpxe.git] / src / util / parserom.pl
blob56bb9445a662025a5e1b7d902d4f4c57f135cd4f
1 #!/usr/bin/perl -w
3 # Parse PCI_ROM and ISA_ROM entries from a source file on stdin and
4 # output the relevant Makefile variable definitions to stdout
6 # Based upon portions of Ken Yap's genrules.pl
8 use strict;
9 use warnings;
11 die "Syntax: $0 driver_source.c" unless @ARGV == 1;
12 my $source = shift;
13 open DRV, "<$source" or die "Could not open $source: $!\n";
15 ( my $family, my $driver_name ) = ( $source =~ /^(.*?([^\/]+))\..$/ )
16 or die "Could not parse source file name \"$source\"\n";
18 my $printed_family;
20 sub rom {
21 ( my $type, my $image, my $desc, my $vendor, my $device ) = @_;
22 my $ids = $vendor ? "$vendor,$device" : "-";
23 unless ( $printed_family ) {
24 print "\n";
25 print "# NIC\t\n";
26 print "# NIC\tfamily\t$family\n";
27 print "DRIVERS += $driver_name\n";
28 $printed_family = 1;
30 print "\n";
31 print "# NIC\t$image\t$ids\t$desc\n";
32 print "DRIVER_$image = $driver_name\n";
33 print "ROM_TYPE_$image = $type\n";
34 print "ROM_DESCRIPTION_$image = \"$desc\"\n";
35 print "PCI_VENDOR_$image = $vendor\n" if $vendor;
36 print "PCI_DEVICE_$image = $device\n" if $device;
37 print "ROMS += $image\n";
38 print "ROMS_$driver_name += $image\n";
41 while ( <DRV> ) {
42 next unless /(PCI|ISA)_ROM\s*\(/;
44 if ( /^\s*PCI_ROM\s*\(
45 \s*(0x[0-9A-Fa-f]{4})\s*, # PCI vendor
46 \s*(0x[0-9A-Fa-f]{4})\s*, # PCI device
47 \s*\"([^\"]*)\"\s*, # Image
48 \s*\"([^\"]*)\"\s* # Description
49 \)/x ) {
50 ( my $vendor, my $device, my $image, my $desc ) = ( lc $1, lc $2, $3, $4 );
51 rom ( "pci", $image, $desc, $vendor, $device );
52 } elsif ( /^\s*ISA_ROM\s*\(
53 \s*\"([^\"]*)\"\s*, # Image
54 \s*\"([^\"]*)\"\s* # Description
55 \)/x ) {
56 ( my $image, my $desc ) = ( $1, $2 );
57 rom ( "isa", $image, $desc );
58 } else {
59 warn "Malformed PCI_ROM or ISA_ROM macro on line $. of $source\n";
63 close DRV;