]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/process_files.pl
3 # This script runs the OpenSSL Configure script, then processes the
4 # resulting file list into our local OpensslLib[Crypto].inf and also
5 # takes copies of opensslconf.h and dso_conf.h.
7 # This only needs to be done once by a developer when updating to a
8 # new version of OpenSSL (or changing options, etc.). Normal users
9 # do not need to do this, since the results are stored in the EDK2
10 # git repository for them.
12 # Due to the script wrapping required to process the OpenSSL
13 # configuration data, each native architecture must be processed
14 # individually by the maintainer (in addition to the standard version):
16 # ./process_files.pl X64
17 # ./process_files.pl [Arch]
19 # Follow the command below to update the INF file:
20 # 1. OpensslLib.inf ,OpensslLibCrypto.inf and OpensslLibFull.inf
22 # 2. OpensslLibAccel.inf and OpensslLibFullAccel.inf
23 # ./process_files.pl X64
24 # ./process_files.pl X64Gcc
25 # ./process_files.pl IA32
26 # ./process_files.pl IA32Gcc
32 use File
::Path
qw(make_path remove_tree);
35 my $comment_character;
38 # OpenSSL perlasm generator script does not transfer the copyright header
40 sub copy_license_header
42 my @args = split / /, shift; #Separate args by spaces
43 my $source = $args[1]; #Source file is second (after "perl")
44 my $target = pop @args; #Target file is always last
45 chop ($target); #Remove newline char
47 my $temp_file_name = "license.tmp";
48 open (my $source_file, "<" . $source) || die $source;
49 open (my $target_file, "<" . $target) || die $target;
50 open (my $temp_file, ">" . $temp_file_name) || die $temp_file_name;
52 #Add "generated file" warning
53 $source =~ s/^..//; #Remove leading "./"
54 print ($temp_file "$comment_character WARNING: do not edit!\r\n");
55 print ($temp_file "$comment_character Generated from $source\r\n");
56 print ($temp_file "$comment_character\r\n");
58 #Copy source file header to temp file
59 while (my $line = <$source_file>) {
60 next if ($line =~ /#!/); #Ignore shebang line
61 $line =~ s/#/$comment_character/; #Fix comment character for assembly
62 $line =~ s/\s+$/\r\n/; #Trim trailing whitepsace, fixup line endings
63 print ($temp_file $line);
64 last if ($line =~ /http/); #Last line of copyright header contains a web link
66 print ($temp_file "\r\n");
67 #Retrieve generated assembly contents
68 while (my $line = <$target_file>) {
69 $line =~ s/\s+$/\r\n/; #Trim trailing whitepsace, fixup line endings
70 print ($temp_file expand
($line)); #expand() replaces tabs with spaces
77 move
($temp_file_name, $target) ||
78 die "Cannot replace \"" . $target . "\"!";
82 # Find the openssl directory name for use lib. We have to do this
83 # inside of BEGIN. The variables we create here, however, don't seem
84 # to be available to the main script, so we have to repeat the
96 $inf_file = "OpensslLib.inf";
97 $uefi_config = "UEFI";
101 if (uc ($arch) eq "X64") {
103 $uefi_config = "UEFI-x86_64";
106 $comment_character = ";";
107 } elsif (uc ($arch) eq "X64GCC") {
109 $uefi_config = "UEFI-x86_64-GCC";
112 $comment_character = "#";
113 } elsif (uc ($arch) eq "IA32") {
115 $uefi_config = "UEFI-x86";
118 $comment_character = ";";
119 } elsif (uc ($arch) eq "IA32GCC") {
121 $uefi_config = "UEFI-x86-GCC";
124 $comment_character = "#";
126 die "Unsupported architecture \"" . $arch . "\"!";
128 $inf_file = "OpensslLibAccel.inf";
129 if ($extension eq "nasm") {
130 if (`nasm -v 2>&1`) {
131 #Presence of nasm executable will trigger inclusion of AVX instructions
132 die "\nCannot run assembly generators with NASM in path!\n\n";
136 # Prepare assembly folder
138 opendir my $dir, $arch ||
139 die "Cannot open assembly folder \"" . $arch . "\"!";
140 while (defined (my $file = readdir $dir)) {
141 if (-d
"$arch/$file") {
142 next if $file eq ".";
143 next if $file eq "..";
144 remove_tree
("$arch/$file", {safe
=> 1}) ||
145 die "Cannot clean assembly folder \"" . "$arch/$file" . "\"!";
151 die "Cannot create assembly folder \"" . $arch . "\"!";
155 # Read the contents of the inf file
156 open( FD
, "<" . $inf_file ) ||
157 die "Cannot open \"" . $inf_file . "\"!";
160 die "Cannot close \"" . $inf_file . "\"!";
163 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
165 # We need to run Configure before we can include its result...
168 my $basedir = getcwd
();
170 chdir($OPENSSL_PATH) ||
171 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
176 "--config=../UefiAsm.conf",
181 "no-autoload-config",
222 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI
223 # UEFI only support --with-rand-seed=none
224 "--with-rand-seed=none"
226 die "OpenSSL Configure failed!\n";
228 # Generate opensslconf.h per config data
230 "perl -I. -Mconfigdata util/dofile.pl " .
231 "include/openssl/opensslconf.h.in " .
232 "> include/openssl/opensslconf.h"
234 die "Failed to generate opensslconf.h!\n";
236 # Generate dso_conf.h per config data
238 "perl -I. -Mconfigdata util/dofile.pl " .
239 "include/crypto/dso_conf.h.in " .
240 "> include/crypto/dso_conf.h"
242 die "Failed to generate dso_conf.h!\n";
245 die "Cannot change to base directory \"" . $basedir . "\"";
254 # Retrieve file lists from OpenSSL configdata
256 use configdata qw
/%unified_info/;
257 use configdata qw
/%config/;
258 use configdata qw
/%target/;
261 # Collect build flags from configdata
264 foreach my $f (@{$config{lib_defines
}}) {
268 my @cryptofilelist = ();
269 my @sslfilelist = ();
271 my @asmfilelist = ();
273 foreach my $product ((@{$unified_info{libraries
}},
274 @{$unified_info{engines
}})) {
275 foreach my $o (@{$unified_info{sources
}->{$product}}) {
276 foreach my $s (@{$unified_info{sources
}->{$o}}) {
277 # No need to add unused files in UEFI.
278 # So it can reduce porting time, compile time, library size.
279 next if $s =~ "crypto/bio/b_print.c";
280 next if $s =~ "crypto/rand/randfile.c";
281 next if $s =~ "crypto/store/";
282 next if $s =~ "crypto/err/err_all.c";
283 next if $s =~ "crypto/aes/aes_ecb.c";
285 if ($unified_info{generate
}->{$s}) {
287 my $buildstring = "perl";
288 foreach my $arg (@{$unified_info{generate
}->{$s}}) {
290 $buildstring .= " ./openssl/$arg";
291 } elsif ($arg =~ "PERLASM_SCHEME") {
292 $buildstring .= " $target{perlasm_scheme}";
293 } elsif ($arg =~ "LIB_CFLAGS") {
294 $buildstring .= "$flags";
297 ($s, my $path, undef) = fileparse
($s, qr/\.[^.]*/);
298 $buildstring .= " ./$arch/$path$s.$extension";
299 make_path
("./$arch/$path");
300 push @asmbuild, "$buildstring\n";
301 push @asmfilelist, " $arch/$path$s.$extension |$compile\r\n";
305 if ($s =~ "/ec/" || $s =~ "/sm2/") {
306 push @ecfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
309 if ($product =~ "libssl") {
310 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
313 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
320 # Update the perl script to generate the missing header files
323 for (sort keys %{$unified_info{dirinfo
}}){
332 @files = glob($_."/*.h");
333 push @headers, @files;
339 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
342 if ($_ =~ "/ec/" || $_ =~ "/sm2/") {
343 push @ecfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
346 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
351 # Generate assembly files
354 print "\n--> Generating assembly files ... ";
355 foreach my $buildstring (@asmbuild) {
356 system ("$buildstring");
357 copy_license_header
($buildstring);
363 # Update OpensslLib.inf with autogenerated file list
367 print "\n--> Updating $inf_file ... ";
369 if ($_ =~ "DEFINE OPENSSL_FLAGS_CONFIG") {
370 push @new_inf, " DEFINE OPENSSL_FLAGS_CONFIG =" . $flags . "\r\n";
373 if ( $_ =~ "# Autogenerated files list starts here" ) {
374 push @new_inf, $_, @cryptofilelist, @sslfilelist;
379 my $arch_asmfile_flag = "# Autogenerated " . $arch . " files list starts here";
380 if ($_ =~ $arch_asmfile_flag) {
381 push @new_inf, $_, @asmfilelist;
386 if ( $_ =~ "# Autogenerated files list ends here" ) {
396 my $new_inf_file = $inf_file . ".new";
397 open( FD
, ">" . $new_inf_file ) ||
399 print( FD
@new_inf ) ||
403 rename( $new_inf_file, $inf_file ) ||
404 die "rename $inf_file";
407 if (!defined $arch) {
409 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
411 $inf_file = "OpensslLibCrypto.inf";
413 # Read the contents of the inf file
416 open( FD
, "<" . $inf_file ) ||
417 die "Cannot open \"" . $inf_file . "\"!";
420 die "Cannot close \"" . $inf_file . "\"!";
423 print "\n--> Updating OpensslLibCrypto.inf ... ";
425 if ( $_ =~ "# Autogenerated files list starts here" ) {
426 push @new_inf, $_, @cryptofilelist;
430 if ( $_ =~ "# Autogenerated files list ends here" ) {
440 $new_inf_file = $inf_file . ".new";
441 open( FD
, ">" . $new_inf_file ) ||
443 print( FD
@new_inf ) ||
447 rename( $new_inf_file, $inf_file ) ||
448 die "rename $inf_file";
453 # Update OpensslLibFull.inf with autogenerated file list
455 if (!defined $arch) {
456 $inf_file = "OpensslLibFull.inf";
458 $inf_file = "OpensslLibFullAccel.inf";
460 # Read the contents of the inf file
463 open( FD
, "<" . $inf_file ) ||
464 die "Cannot open \"" . $inf_file . "\"!";
467 die "Cannot close \"" . $inf_file . "\"!";
469 print "\n--> Updating $inf_file ... ";
471 if ( $_ =~ "# Autogenerated files list starts here" ) {
472 push @new_inf, $_, @cryptofilelist, @sslfilelist, @ecfilelist;
477 my $arch_asmfile_flag = "# Autogenerated " . $arch . " files list starts here";
478 if ($_ =~ $arch_asmfile_flag) {
479 push @new_inf, $_, @asmfilelist;
484 if ( $_ =~ "# Autogenerated files list ends here" ) {
494 $new_inf_file = $inf_file . ".new";
495 open( FD
, ">" . $new_inf_file ) ||
497 print( FD
@new_inf ) ||
501 rename( $new_inf_file, $inf_file ) ||
502 die "rename $inf_file";
506 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration
508 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
510 "perl -pe 's/\\n/\\r\\n/' " .
511 "< " . $OPENSSL_PATH . "/include/openssl/opensslconf.h " .
512 "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf.h"
514 die "Cannot copy opensslconf.h!";
517 print "\n--> Duplicating dso_conf.h into Include/crypto ... ";
519 "perl -pe 's/\\n/\\r\\n/' " .
520 "< " . $OPENSSL_PATH . "/include/crypto/dso_conf.h" .
521 "> " . $OPENSSL_PATH . "/../../Include/crypto/dso_conf.h"
523 die "Cannot copy dso_conf.h!";
526 print "\nProcessing Files Done!\n";