Selaa lähdekoodia

[efi] Tidy up output of EFI header import script

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 vuotta sitten
vanhempi
commit
bf2b1c8e47

+ 5
- 0
src/include/ipxe/efi/ProcessorBind.h Näytä tiedosto

@@ -1,3 +1,6 @@
1
+#ifndef _IPXE_EFI_PROCESSOR_BIND_H
2
+#define _IPXE_EFI_PROCESSOR_BIND_H
3
+
1 4
 /*
2 5
  * EFI header files rely on having the CPU architecture directory
3 6
  * present in the search path in order to pick up ProcessorBind.h.  We
@@ -12,3 +15,5 @@
12 15
 #if __x86_64__
13 16
 #include <ipxe/efi/X64/ProcessorBind.h>
14 17
 #endif
18
+
19
+#endif /* _IPXE_EFI_PROCESSOR_BIND_H */

+ 3
- 3
src/include/ipxe/efi/efi.h Näytä tiedosto

@@ -1,5 +1,5 @@
1
-#ifndef _EFI_H
2
-#define _EFI_H
1
+#ifndef _IPXE_EFI_H
2
+#define _IPXE_EFI_H
3 3
 
4 4
 /** @file
5 5
  *
@@ -142,4 +142,4 @@ extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
142 142
 			     EFI_SYSTEM_TABLE *systab );
143 143
 extern int efi_snp_install ( void );
144 144
 
145
-#endif /* _EFI_H */
145
+#endif /* _IPXE_EFI_H */

+ 57
- 16
src/include/ipxe/efi/import.pl Näytä tiedosto

@@ -1,28 +1,58 @@
1 1
 #!/usr/bin/perl -w
2 2
 
3
+=head1 NAME
4
+
5
+import.pl
6
+
7
+=head1 SYNOPSIS
8
+
9
+import.pl [options] /path/to/edk2/edk2
10
+
11
+Options:
12
+
13
+    -h,--help		Display brief help message
14
+    -v,--verbose	Increase verbosity
15
+    -q,--quiet		Decrease verbosity
16
+
17
+=cut
18
+
3 19
 use File::Spec::Functions qw ( :ALL );
4 20
 use File::Find;
5 21
 use File::Path;
22
+use Getopt::Long;
23
+use Pod::Usage;
6 24
 use FindBin;
7 25
 use strict;
8 26
 use warnings;
9 27
 
28
+my $verbosity = 0;
29
+
10 30
 sub try_import_file {
11 31
   my $ipxedir = shift;
32
+  my $edktop = shift;
12 33
   my $edkdirs = shift;
13 34
   my $filename = shift;
14 35
 
15 36
   # Skip everything except headers
16 37
   return unless $filename =~ /\.h$/;
17
-  print "$filename...";
18 38
 
19
-  ( undef, undef, my $basename ) = splitpath ( $filename );
39
+  # Skip files that are iPXE native headers
20 40
   my $outfile = catfile ( $ipxedir, $filename );
41
+  if ( -s $outfile ) {
42
+    open my $outfh, "<$outfile" or die "Could not open $outfile: $!\n";
43
+    my $line = <$outfh>;
44
+    close $outfh;
45
+    chomp $line;
46
+    return if $line =~ /^\#ifndef\s+_IPXE_\S+_H$/;
47
+  }
48
+
49
+  # Search for importable header
21 50
   foreach my $edkdir ( @$edkdirs ) {
22
-    my $infile = catfile ( $edkdir, $filename );
51
+    my $infile = catfile ( $edktop, $edkdir, $filename );
23 52
     if ( -e $infile ) {
24 53
       # We have found a matching source file - import it
25
-      print "$infile\n";
54
+      print "$filename <- ".catfile ( $edkdir, $filename )."\n"
55
+	  if $verbosity >= 1;
26 56
       open my $infh, "<$infile" or die "Could not open $infile: $!\n";
27 57
       ( undef, my $outdir, undef ) = splitpath ( $outfile );
28 58
       mkpath ( $outdir );
@@ -61,33 +91,44 @@ sub try_import_file {
61 91
       # Recurse to handle any included files that we don't already have
62 92
       foreach my $dependency ( @dependencies ) {
63 93
 	if ( ! -e catfile ( $ipxedir, $dependency ) ) {
64
-	  print "...following dependency on $dependency\n";
65
-	  try_import_file ( $ipxedir, $edkdirs, $dependency );
94
+	  print "...following dependency on $dependency\n" if $verbosity >= 1;
95
+	  try_import_file ( $ipxedir, $edktop, $edkdirs, $dependency );
66 96
 	}
67 97
       }
68 98
       return;
69 99
     }
70 100
   }
71
-  print "no equivalent found\n";
101
+  die "$filename has no equivalent in $edktop\n";
72 102
 }
73 103
 
74
-# Identify edk import directories
75
-die "Syntax $0 /path/to/edk2/edk2\n" unless @ARGV == 1;
104
+# Parse command-line options
105
+Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
106
+GetOptions (
107
+  'verbose|v+' => sub { $verbosity++; },
108
+  'quiet|q+' => sub { $verbosity--; },
109
+  'help|h' => sub { pod2usage ( 1 ); },
110
+) or die "Could not parse command-line options\n";
111
+pod2usage ( 1 ) unless @ARGV == 1;
76 112
 my $edktop = shift;
77
-die "Directory \"$edktop\" does not appear to contain the EFI EDK2\n"
78
-    unless -e catfile ( $edktop, "MdePkg" );
79
-my $edkdirs = [ catfile ( $edktop, "MdePkg/Include" ),
80
-		catfile ( $edktop, "IntelFrameworkPkg/Include" ) ];
113
+
114
+# Identify edk import directories
115
+my $edkdirs = [ "MdePkg/Include", "IntelFrameworkPkg/Include" ];
116
+foreach my $edkdir ( @$edkdirs ) {
117
+  die "Directory \"$edktop\" does not appear to contain the EFI EDK2 "
118
+      ."(missing \"$edkdir\")\n" unless -d catdir ( $edktop, $edkdir );
119
+}
81 120
 
82 121
 # Identify iPXE EFI includes directory
83 122
 my $ipxedir = $FindBin::Bin;
84 123
 die "Directory \"$ipxedir\" does not appear to contain the iPXE EFI includes\n"
85 124
     unless -e catfile ( $ipxedir, "../../../include/ipxe/efi" );
86 125
 
87
-print "Importing EFI headers into $ipxedir\nfrom ";
88
-print join ( "\n and ", @$edkdirs )."\n";
126
+if ( $verbosity >= 1 ) {
127
+  print "Importing EFI headers into $ipxedir\nfrom ";
128
+  print join ( "\n and ", map { catdir ( $edktop, $_ ) } @$edkdirs )."\n";
129
+}
89 130
 
90 131
 # Import headers
91 132
 find ( { wanted => sub {
92
-  try_import_file ( $ipxedir, $edkdirs, abs2rel ( $_, $ipxedir ) );
133
+  try_import_file ( $ipxedir, $edktop, $edkdirs, abs2rel ( $_, $ipxedir ) );
93 134
 }, no_chdir => 1 }, $ipxedir );

Loading…
Peruuta
Tallenna