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 );
36 # Skip everything except headers
37 return unless $filename =~ /\.h$/;
39 # Skip files that are iPXE native headers
40 my $outfile = catfile ( $ipxedir, $filename );
42 open my $outfh, "<$outfile" or die "Could not open $outfile: $!\n";
46 return if $line =~ /^\#ifndef\s+_IPXE_\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 = ();
64 # Strip CR and trailing whitespace
68 # Update include lines, and record included files
69 if ( s/^\#include\s+[<\"](\S+)[>\"]/\#include <ipxe\/efi\/$1>/ ) {
70 push @dependencies, $1;
72 # Check for BSD licence statement
73 if ( /^\s*THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE/ ) {
74 die "Licence detected after header guard\n" if $guard;
79 # Apply FILE_LICENCE() immediately after include guard
80 if ( /^\#define\s+_?_\S+_H_?_$/ ) {
81 die "Duplicate header guard detected in $infile\n" if $guard;
83 print $outfh "\nFILE_LICENCE ( $licence );\n" if $licence;
88 # Warn if no licence was detected
89 warn "Cannot detect licence in $infile\n" unless $licence;
90 warn "Cannot detect header guard in $infile\n" unless $guard;
91 # Recurse to handle any included files that we don't already have
92 foreach my $dependency ( @dependencies ) {
93 if ( ! -e catfile ( $ipxedir, $dependency ) ) {
94 print "...following dependency on $dependency\n" if $verbosity >= 1;
95 try_import_file ( $ipxedir, $edktop, $edkdirs, $dependency );
101 die "$filename has no equivalent in $edktop\n";
104 # Parse command-line options
105 Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
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;
114 # Identify edk import directories
115 my $edkdirs = [ "MdePkg/Include", "IntelFrameworkPkg/Include",
116 "MdeModulePkg/Include" ];
117 foreach my $edkdir ( @$edkdirs ) {
118 die "Directory \"$edktop\" does not appear to contain the EFI EDK2 "
119 ."(missing \"$edkdir\")\n" unless -d catdir ( $edktop, $edkdir );
122 # Identify iPXE EFI includes directory
123 my $ipxedir = $FindBin::Bin;
124 die "Directory \"$ipxedir\" does not appear to contain the iPXE EFI includes\n"
125 unless -e catfile ( $ipxedir, "../../../include/ipxe/efi" );
127 if ( $verbosity >= 1 ) {
128 print "Importing EFI headers into $ipxedir\nfrom ";
129 print join ( "\n and ", map { catdir ( $edktop, $_ ) } @$edkdirs )."\n";
133 find ( { wanted => sub {
134 try_import_file ( $ipxedir, $edktop, $edkdirs, abs2rel ( $_, $ipxedir ) );
135 }, no_chdir => 1 }, $ipxedir );