]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg: update openssl submodule to 1.1.1n
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / process_files.pl
index 57ce1953947b0a1347cccf2f0fe58fa1b74d8a2c..42bff05fa629bd93340d467cde3b1e3809ad12c7 100755 (executable)
@@ -9,9 +9,65 @@
 # do not need to do this, since the results are stored in the EDK2\r
 # git repository for them.\r
 #\r
+# Due to the script wrapping required to process the OpenSSL\r
+# configuration data, each native architecture must be processed\r
+# individually by the maintainer (in addition to the standard version):\r
+#   ./process_files.pl\r
+#   ./process_files.pl X64\r
+#   ./process_files.pl [Arch]\r
+\r
 use strict;\r
 use Cwd;\r
 use File::Copy;\r
+use File::Basename;\r
+use File::Path qw(make_path remove_tree);\r
+use Text::Tabs;\r
+\r
+my $comment_character;\r
+\r
+#\r
+# OpenSSL perlasm generator script does not transfer the copyright header\r
+#\r
+sub copy_license_header\r
+{\r
+    my @args = split / /, shift;    #Separate args by spaces\r
+    my $source = $args[1];          #Source file is second (after "perl")\r
+    my $target = pop @args;         #Target file is always last\r
+    chop ($target);                 #Remove newline char\r
+\r
+    my $temp_file_name = "license.tmp";\r
+    open (my $source_file, "<" . $source) || die $source;\r
+    open (my $target_file, "<" . $target) || die $target;\r
+    open (my $temp_file, ">" . $temp_file_name) || die $temp_file_name;\r
+\r
+    #Add "generated file" warning\r
+    $source =~ s/^..//;             #Remove leading "./"\r
+    print ($temp_file "$comment_character WARNING: do not edit!\r\n");\r
+    print ($temp_file "$comment_character Generated from $source\r\n");\r
+    print ($temp_file "$comment_character\r\n");\r
+\r
+    #Copy source file header to temp file\r
+    while (my $line = <$source_file>) {\r
+        next if ($line =~ /#!/);    #Ignore shebang line\r
+        $line =~ s/#/$comment_character/;            #Fix comment character for assembly\r
+        $line =~ s/\s+$/\r\n/;      #Trim trailing whitepsace, fixup line endings\r
+        print ($temp_file $line);\r
+        last if ($line =~ /http/);  #Last line of copyright header contains a web link\r
+    }\r
+    print ($temp_file "\r\n");\r
+    #Retrieve generated assembly contents\r
+    while (my $line = <$target_file>) {\r
+        $line =~ s/\s+$/\r\n/;      #Trim trailing whitepsace, fixup line endings\r
+        print ($temp_file expand ($line));  #expand() replaces tabs with spaces\r
+    }\r
+\r
+    close ($source_file);\r
+    close ($target_file);\r
+    close ($temp_file);\r
+\r
+    move ($temp_file_name, $target) ||\r
+        die "Cannot replace \"" . $target . "\"!";\r
+}\r
 \r
 #\r
 # Find the openssl directory name for use lib. We have to do this\r
@@ -21,10 +77,57 @@ use File::Copy;
 #\r
 my $inf_file;\r
 my $OPENSSL_PATH;\r
+my $uefi_config;\r
+my $extension;\r
+my $arch;\r
 my @inf;\r
 \r
 BEGIN {\r
     $inf_file = "OpensslLib.inf";\r
+    $uefi_config = "UEFI";\r
+    $arch = shift;\r
+\r
+    if (defined $arch) {\r
+        if (uc ($arch) eq "X64") {\r
+            $arch = "X64";\r
+            $inf_file = "OpensslLibX64.inf";\r
+            $uefi_config = "UEFI-x86_64";\r
+            $extension = "nasm";\r
+            $comment_character = ";";\r
+        } elsif (uc ($arch) eq "X64GCC") {\r
+            $arch = "X64Gcc";\r
+            $inf_file = "OpensslLibX64Gcc.inf";\r
+            $uefi_config = "UEFI-x86_64-GCC";\r
+            $extension = "S";\r
+            $comment_character = "#";\r
+        } else {\r
+            die "Unsupported architecture \"" . $arch . "\"!";\r
+        }\r
+        if ($extension eq "nasm") {\r
+            if (`nasm -v 2>&1`) {\r
+                #Presence of nasm executable will trigger inclusion of AVX instructions\r
+                die "\nCannot run assembly generators with NASM in path!\n\n";\r
+            }\r
+        }\r
+\r
+        # Prepare assembly folder\r
+        if (-d $arch) {\r
+            opendir my $dir, $arch ||\r
+                die "Cannot open assembly folder \"" . $arch . "\"!";\r
+            while (defined (my $file = readdir $dir)) {\r
+                if (-d "$arch/$file") {\r
+                    next if $file eq ".";\r
+                    next if $file eq "..";\r
+                    remove_tree ("$arch/$file", {safe => 1}) ||\r
+                       die "Cannot clean assembly folder \"" . "$arch/$file" . "\"!";\r
+                }\r
+            }\r
+\r
+        } else {\r
+            mkdir $arch ||\r
+                die "Cannot create assembly folder \"" . $arch . "\"!";\r
+        }\r
+    }\r
 \r
     # Read the contents of the inf file\r
     open( FD, "<" . $inf_file ) ||\r
@@ -47,9 +150,9 @@ BEGIN {
             # Configure UEFI\r
             system(\r
                 "./Configure",\r
-                "UEFI",\r
+                "--config=../UefiAsm.conf",\r
+                "$uefi_config",\r
                 "no-afalgeng",\r
-                "no-asm",\r
                 "no-async",\r
                 "no-autoerrinit",\r
                 "no-autoload-config",\r
@@ -129,23 +232,53 @@ BEGIN {
 # Retrieve file lists from OpenSSL configdata\r
 #\r
 use configdata qw/%unified_info/;\r
+use configdata qw/%config/;\r
+use configdata qw/%target/;\r
+\r
+#\r
+# Collect build flags from configdata\r
+#\r
+my $flags = "";\r
+foreach my $f (@{$config{lib_defines}}) {\r
+    $flags .= " -D$f";\r
+}\r
 \r
 my @cryptofilelist = ();\r
 my @sslfilelist = ();\r
+my @asmfilelist = ();\r
+my @asmbuild = ();\r
 foreach my $product ((@{$unified_info{libraries}},\r
                       @{$unified_info{engines}})) {\r
     foreach my $o (@{$unified_info{sources}->{$product}}) {\r
         foreach my $s (@{$unified_info{sources}->{$o}}) {\r
-            next if ($unified_info{generate}->{$s});\r
-            next if $s =~ "crypto/bio/b_print.c";\r
-\r
             # No need to add unused files in UEFI.\r
             # So it can reduce porting time, compile time, library size.\r
+            next if $s =~ "crypto/bio/b_print.c";\r
             next if $s =~ "crypto/rand/randfile.c";\r
             next if $s =~ "crypto/store/";\r
             next if $s =~ "crypto/err/err_all.c";\r
             next if $s =~ "crypto/aes/aes_ecb.c";\r
 \r
+            if ($unified_info{generate}->{$s}) {\r
+                if (defined $arch) {\r
+                    my $buildstring = "perl";\r
+                    foreach my $arg (@{$unified_info{generate}->{$s}}) {\r
+                        if ($arg =~ ".pl") {\r
+                            $buildstring .= " ./openssl/$arg";\r
+                        } elsif ($arg =~ "PERLASM_SCHEME") {\r
+                            $buildstring .= " $target{perlasm_scheme}";\r
+                        } elsif ($arg =~ "LIB_CFLAGS") {\r
+                            $buildstring .= "$flags";\r
+                        }\r
+                    }\r
+                    ($s, my $path, undef) = fileparse($s, qr/\.[^.]*/);\r
+                    $buildstring .= " ./$arch/$path$s.$extension";\r
+                    make_path ("./$arch/$path");\r
+                    push @asmbuild, "$buildstring\n";\r
+                    push @asmfilelist, "  $arch/$path$s.$extension\r\n";\r
+                }\r
+                next;\r
+            }\r
             if ($product =~ "libssl") {\r
                 push @sslfilelist, '  $(OPENSSL_PATH)/' . $s . "\r\n";\r
                 next;\r
@@ -183,15 +316,31 @@ foreach (@headers){
 }\r
 \r
 \r
+#\r
+# Generate assembly files\r
+#\r
+if (@asmbuild) {\r
+    print "\n--> Generating assembly files ... ";\r
+    foreach my $buildstring (@asmbuild) {\r
+        system ("$buildstring");\r
+        copy_license_header ($buildstring);\r
+    }\r
+    print "Done!";\r
+}\r
+\r
 #\r
 # Update OpensslLib.inf with autogenerated file list\r
 #\r
 my @new_inf = ();\r
 my $subbing = 0;\r
-print "\n--> Updating OpensslLib.inf ... ";\r
+print "\n--> Updating $inf_file ... ";\r
 foreach (@inf) {\r
+    if ($_ =~ "DEFINE OPENSSL_FLAGS_CONFIG") {\r
+        push @new_inf, "  DEFINE OPENSSL_FLAGS_CONFIG    =" . $flags . "\r\n";\r
+        next;\r
+    }\r
     if ( $_ =~ "# Autogenerated files list starts here" ) {\r
-        push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
+        push @new_inf, $_, @asmfilelist, @cryptofilelist, @sslfilelist;\r
         $subbing = 1;\r
         next;\r
     }\r
@@ -216,49 +365,51 @@ rename( $new_inf_file, $inf_file ) ||
     die "rename $inf_file";\r
 print "Done!";\r
 \r
-#\r
-# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
-#\r
-$inf_file = "OpensslLibCrypto.inf";\r
-\r
-# Read the contents of the inf file\r
-@inf = ();\r
-@new_inf = ();\r
-open( FD, "<" . $inf_file ) ||\r
-    die "Cannot open \"" . $inf_file . "\"!";\r
-@inf = (<FD>);\r
-close(FD) ||\r
-    die "Cannot close \"" . $inf_file . "\"!";\r
+if (!defined $arch) {\r
+    #\r
+    # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
+    #\r
+    $inf_file = "OpensslLibCrypto.inf";\r
 \r
-$subbing = 0;\r
-print "\n--> Updating OpensslLibCrypto.inf ... ";\r
-foreach (@inf) {\r
-    if ( $_ =~ "# Autogenerated files list starts here" ) {\r
-        push @new_inf, $_, @cryptofilelist;\r
-        $subbing = 1;\r
-        next;\r
-    }\r
-    if ( $_ =~ "# Autogenerated files list ends here" ) {\r
-        push @new_inf, $_;\r
-        $subbing = 0;\r
-        next;\r
+    # Read the contents of the inf file\r
+    @inf = ();\r
+    @new_inf = ();\r
+    open( FD, "<" . $inf_file ) ||\r
+        die "Cannot open \"" . $inf_file . "\"!";\r
+    @inf = (<FD>);\r
+    close(FD) ||\r
+        die "Cannot close \"" . $inf_file . "\"!";\r
+\r
+    $subbing = 0;\r
+    print "\n--> Updating OpensslLibCrypto.inf ... ";\r
+    foreach (@inf) {\r
+        if ( $_ =~ "# Autogenerated files list starts here" ) {\r
+            push @new_inf, $_, @cryptofilelist;\r
+            $subbing = 1;\r
+            next;\r
+        }\r
+        if ( $_ =~ "# Autogenerated files list ends here" ) {\r
+            push @new_inf, $_;\r
+            $subbing = 0;\r
+            next;\r
+        }\r
+\r
+        push @new_inf, $_\r
+            unless ($subbing);\r
     }\r
 \r
-    push @new_inf, $_\r
-        unless ($subbing);\r
+    $new_inf_file = $inf_file . ".new";\r
+    open( FD, ">" . $new_inf_file ) ||\r
+        die $new_inf_file;\r
+    print( FD @new_inf ) ||\r
+        die $new_inf_file;\r
+    close(FD) ||\r
+        die $new_inf_file;\r
+    rename( $new_inf_file, $inf_file ) ||\r
+        die "rename $inf_file";\r
+    print "Done!";\r
 }\r
 \r
-$new_inf_file = $inf_file . ".new";\r
-open( FD, ">" . $new_inf_file ) ||\r
-    die $new_inf_file;\r
-print( FD @new_inf ) ||\r
-    die $new_inf_file;\r
-close(FD) ||\r
-    die $new_inf_file;\r
-rename( $new_inf_file, $inf_file ) ||\r
-    die "rename $inf_file";\r
-print "Done!";\r
-\r
 #\r
 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r
 #\r