9 import.pl [options] /path/to/edk2/edk2
13 -h,--help Display brief help message
14 -v,--verbose Increase verbosity
15 -q,--quiet Decrease verbosity
19 use File
::Spec
::Functions qw
( :ALL
);
31 my $wimbootdir = shift;
36 # Skip everything except headers
37 return unless $filename =~ /\.h$/;
39 # Skip files that are wimboot native headers
40 my $outfile = catfile
( $wimbootdir, $filename );
42 open my $outfh, "<$outfile" or die "Could not open $outfile: $!\n";
46 return if $line =~ /^\#ifndef\s+_WIMBOOT_\S+_H$/;
49 # Search for importable header
50 foreach my $edkdir ( @$edkdirs ) {
51 my $infile = catfile
( $edktop, $edkdir, $filename );
53 # We have found a matching source file - import it
54 print "$filename <- ".catfile
( $edkdir, $filename )."\n"
56 open my $infh, "<$infile" or die "Could not open $infile: $!\n";
57 ( undef, my $outdir, undef ) = splitpath
( $outfile );
59 open my $outfh, ">$outfile" or die "Could not open $outfile: $!\n";
60 my @dependencies = ();
62 # Strip CR and trailing whitespace
66 # Update include lines, and record included files
67 if ( s/^\#include\s+[<\"](\S+)[>\"]/\#include "efi\/$1"/ ) {
68 push @dependencies, $1;
75 # Recurse to handle any included files that we don't already have
76 foreach my $dependency ( @dependencies ) {
77 if ( ! -e catfile ( $wimbootdir, $dependency ) ) {
78 print "...following dependency on
$dependency\n" if $verbosity >= 1;
79 try_import_file ( $wimbootdir, $edktop, $edkdirs, $dependency );
85 die "$filename has no equivalent
in $edktop\n";
88 # Parse command-line options
89 Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
91 'verbose|v+' => sub { $verbosity++; },
92 'quiet|q+' => sub { $verbosity--; },
93 'help|h' => sub { pod2usage ( 1 ); },
94 ) or die "Could
not parse command-line options
\n";
95 pod2usage ( 1 ) unless @ARGV == 1;
98 # Identify edk import directories
99 my $edkdirs = [ "MdePkg
/Include", "IntelFrameworkPkg/Include
",
100 "MdeModulePkg
/Include", "EdkCompatibilityPkg/Foundation
" ];
101 foreach my $edkdir ( @$edkdirs ) {
102 die "Directory
\"$edktop\" does not appear to contain the EFI EDK2
"
103 ."(missing
\"$edkdir\")\n" unless -d catdir ( $edktop, $edkdir );
106 # Identify wimboot EFI includes directory
107 my $wimbootdir = $FindBin::Bin;
108 die "Directory
\"$wimbootdir\" does not contain the wimboot EFI includes
\n"
109 unless -e catfile ( $wimbootdir, "../wimboot
.h
" );
111 if ( $verbosity >= 1 ) {
112 print "Importing EFI headers into
$wimbootdir\nfrom
";
113 print join ( "\n and ", map { catdir ( $edktop, $_ ) } @$edkdirs )."\n";
117 find ( { wanted => sub {
118 try_import_file ( $wimbootdir, $edktop, $edkdirs,
119 abs2rel ( $_, $wimbootdir ) );
120 }, no_chdir => 1 }, $wimbootdir );