You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

import.pl 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl -w
  2. use File::Spec::Functions qw ( :ALL );
  3. use File::Find;
  4. use File::Path;
  5. use FindBin;
  6. use strict;
  7. use warnings;
  8. sub try_import_file {
  9. my $gpxedir = shift;
  10. my $edkdirs = shift;
  11. my $filename = shift;
  12. # Skip everything except headers
  13. return unless $filename =~ /\.h$/;
  14. print "$filename...";
  15. my $outfile = catfile ( $gpxedir, $filename );
  16. foreach my $edkdir ( @$edkdirs ) {
  17. my $infile = catfile ( $edkdir, $filename );
  18. if ( -e $infile ) {
  19. # We have found a matching source file - import it
  20. print "$infile\n";
  21. open my $infh, "<$infile" or die "Could not open $infile: $!\n";
  22. ( undef, my $outdir, undef ) = splitpath ( $outfile );
  23. mkpath ( $outdir );
  24. open my $outfh, ">$outfile" or die "Could not open $outfile: $!\n";
  25. my @dependencies = ();
  26. while ( <$infh> ) {
  27. # Strip CR and trailing whitespace
  28. s/\r//g;
  29. s/\s*$//g;
  30. chomp;
  31. # Update include lines, and record included files
  32. if ( s/^\#include\s+[<\"](\S+)[>\"]/\#include <gpxe\/efi\/$1>/ ) {
  33. push @dependencies, $1;
  34. }
  35. print $outfh "$_\n";
  36. }
  37. close $outfh;
  38. close $infh;
  39. # Recurse to handle any included files that we don't already have
  40. foreach my $dependency ( @dependencies ) {
  41. if ( ! -e catfile ( $gpxedir, $dependency ) ) {
  42. print "...following dependency on $dependency\n";
  43. try_import_file ( $gpxedir, $edkdirs, $dependency );
  44. }
  45. }
  46. return;
  47. }
  48. }
  49. print "no equivalent found\n";
  50. }
  51. # Identify edk import directories
  52. die "Syntax $0 /path/to/edk2/edk2\n" unless @ARGV == 1;
  53. my $edktop = shift;
  54. die "Directory \"$edktop\" does not appear to contain the EFI EDK2\n"
  55. unless -e catfile ( $edktop, "MdePkg" );
  56. my $edkdirs = [ catfile ( $edktop, "MdePkg/Include" ),
  57. catfile ( $edktop, "IntelFrameworkPkg/Include" ) ];
  58. # Identify gPXE EFI includes directory
  59. my $gpxedir = $FindBin::Bin;
  60. die "Directory \"$gpxedir\" does not appear to contain the gPXE EFI includes\n"
  61. unless -e catfile ( $gpxedir, "../../../include/gpxe/efi" );
  62. print "Importing EFI headers into $gpxedir\nfrom ";
  63. print join ( "\n and ", @$edkdirs )."\n";
  64. # Import headers
  65. find ( { wanted => sub {
  66. try_import_file ( $gpxedir, $edkdirs, abs2rel ( $_, $gpxedir ) );
  67. }, no_chdir => 1 }, $gpxedir );