]>
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]
23 use File
::Path
qw(make_path remove_tree);
26 my $comment_character;
29 # OpenSSL perlasm generator script does not transfer the copyright header
31 sub copy_license_header
33 my @args = split / /, shift; #Separate args by spaces
34 my $source = $args[1]; #Source file is second (after "perl")
35 my $target = pop @args; #Target file is always last
36 chop ($target); #Remove newline char
38 my $temp_file_name = "license.tmp";
39 open (my $source_file, "<" . $source) || die $source;
40 open (my $target_file, "<" . $target) || die $target;
41 open (my $temp_file, ">" . $temp_file_name) || die $temp_file_name;
43 #Add "generated file" warning
44 $source =~ s/^..//; #Remove leading "./"
45 print ($temp_file "$comment_character WARNING: do not edit!\r\n");
46 print ($temp_file "$comment_character Generated from $source\r\n");
47 print ($temp_file "$comment_character\r\n");
49 #Copy source file header to temp file
50 while (my $line = <$source_file>) {
51 next if ($line =~ /#!/); #Ignore shebang line
52 $line =~ s/#/$comment_character/; #Fix comment character for assembly
53 $line =~ s/\s+$/\r\n/; #Trim trailing whitepsace, fixup line endings
54 print ($temp_file $line);
55 last if ($line =~ /http/); #Last line of copyright header contains a web link
57 print ($temp_file "\r\n");
58 #Retrieve generated assembly contents
59 while (my $line = <$target_file>) {
60 $line =~ s/\s+$/\r\n/; #Trim trailing whitepsace, fixup line endings
61 print ($temp_file expand
($line)); #expand() replaces tabs with spaces
68 move
($temp_file_name, $target) ||
69 die "Cannot replace \"" . $target . "\"!";
73 # Find the openssl directory name for use lib. We have to do this
74 # inside of BEGIN. The variables we create here, however, don't seem
75 # to be available to the main script, so we have to repeat the
86 $inf_file = "OpensslLib.inf";
87 $uefi_config = "UEFI";
91 if (uc ($arch) eq "X64") {
93 $inf_file = "OpensslLibX64.inf";
94 $uefi_config = "UEFI-x86_64";
96 $comment_character = ";";
97 } elsif (uc ($arch) eq "X64GCC") {
99 $inf_file = "OpensslLibX64Gcc.inf";
100 $uefi_config = "UEFI-x86_64-GCC";
102 $comment_character = "#";
103 } elsif (uc ($arch) eq "IA32") {
105 $inf_file = "OpensslLibIa32.inf";
106 $uefi_config = "UEFI-x86";
108 $comment_character = ";";
109 } elsif (uc ($arch) eq "IA32GCC") {
111 $inf_file = "OpensslLibIa32Gcc.inf";
112 $uefi_config = "UEFI-x86-GCC";
114 $comment_character = "#";
116 die "Unsupported architecture \"" . $arch . "\"!";
118 if ($extension eq "nasm") {
119 if (`nasm -v 2>&1`) {
120 #Presence of nasm executable will trigger inclusion of AVX instructions
121 die "\nCannot run assembly generators with NASM in path!\n\n";
125 # Prepare assembly folder
127 opendir my $dir, $arch ||
128 die "Cannot open assembly folder \"" . $arch . "\"!";
129 while (defined (my $file = readdir $dir)) {
130 if (-d
"$arch/$file") {
131 next if $file eq ".";
132 next if $file eq "..";
133 remove_tree
("$arch/$file", {safe
=> 1}) ||
134 die "Cannot clean assembly folder \"" . "$arch/$file" . "\"!";
140 die "Cannot create assembly folder \"" . $arch . "\"!";
144 # Read the contents of the inf file
145 open( FD
, "<" . $inf_file ) ||
146 die "Cannot open \"" . $inf_file . "\"!";
149 die "Cannot close \"" . $inf_file . "\"!";
152 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
154 # We need to run Configure before we can include its result...
157 my $basedir = getcwd
();
159 chdir($OPENSSL_PATH) ||
160 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
165 "--config=../UefiAsm.conf",
170 "no-autoload-config",
211 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI
212 # UEFI only support --with-rand-seed=none
213 "--with-rand-seed=none"
215 die "OpenSSL Configure failed!\n";
217 # Generate opensslconf.h per config data
219 "perl -I. -Mconfigdata util/dofile.pl " .
220 "include/openssl/opensslconf.h.in " .
221 "> include/openssl/opensslconf.h"
223 die "Failed to generate opensslconf.h!\n";
225 # Generate dso_conf.h per config data
227 "perl -I. -Mconfigdata util/dofile.pl " .
228 "include/crypto/dso_conf.h.in " .
229 "> include/crypto/dso_conf.h"
231 die "Failed to generate dso_conf.h!\n";
234 die "Cannot change to base directory \"" . $basedir . "\"";
243 # Retrieve file lists from OpenSSL configdata
245 use configdata qw
/%unified_info/;
246 use configdata qw
/%config/;
247 use configdata qw
/%target/;
250 # Collect build flags from configdata
253 foreach my $f (@{$config{lib_defines
}}) {
257 my @cryptofilelist = ();
258 my @sslfilelist = ();
259 my @asmfilelist = ();
261 foreach my $product ((@{$unified_info{libraries
}},
262 @{$unified_info{engines
}})) {
263 foreach my $o (@{$unified_info{sources
}->{$product}}) {
264 foreach my $s (@{$unified_info{sources
}->{$o}}) {
265 # No need to add unused files in UEFI.
266 # So it can reduce porting time, compile time, library size.
267 next if $s =~ "crypto/bio/b_print.c";
268 next if $s =~ "crypto/rand/randfile.c";
269 next if $s =~ "crypto/store/";
270 next if $s =~ "crypto/err/err_all.c";
271 next if $s =~ "crypto/aes/aes_ecb.c";
273 if ($unified_info{generate
}->{$s}) {
275 my $buildstring = "perl";
276 foreach my $arg (@{$unified_info{generate
}->{$s}}) {
278 $buildstring .= " ./openssl/$arg";
279 } elsif ($arg =~ "PERLASM_SCHEME") {
280 $buildstring .= " $target{perlasm_scheme}";
281 } elsif ($arg =~ "LIB_CFLAGS") {
282 $buildstring .= "$flags";
285 ($s, my $path, undef) = fileparse
($s, qr/\.[^.]*/);
286 $buildstring .= " ./$arch/$path$s.$extension";
287 make_path
("./$arch/$path");
288 push @asmbuild, "$buildstring\n";
289 push @asmfilelist, " $arch/$path$s.$extension\r\n";
293 if ($product =~ "libssl") {
294 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
297 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
304 # Update the perl script to generate the missing header files
307 for (sort keys %{$unified_info{dirinfo
}}){
316 @files = glob($_."/*.h");
317 push @headers, @files;
323 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
326 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
331 # Generate assembly files
334 print "\n--> Generating assembly files ... ";
335 foreach my $buildstring (@asmbuild) {
336 system ("$buildstring");
337 copy_license_header
($buildstring);
343 # Update OpensslLib.inf with autogenerated file list
347 print "\n--> Updating $inf_file ... ";
349 if ($_ =~ "DEFINE OPENSSL_FLAGS_CONFIG") {
350 push @new_inf, " DEFINE OPENSSL_FLAGS_CONFIG =" . $flags . "\r\n";
353 if ( $_ =~ "# Autogenerated files list starts here" ) {
354 push @new_inf, $_, @asmfilelist, @cryptofilelist, @sslfilelist;
358 if ( $_ =~ "# Autogenerated files list ends here" ) {
368 my $new_inf_file = $inf_file . ".new";
369 open( FD
, ">" . $new_inf_file ) ||
371 print( FD
@new_inf ) ||
375 rename( $new_inf_file, $inf_file ) ||
376 die "rename $inf_file";
379 if (!defined $arch) {
381 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
383 $inf_file = "OpensslLibCrypto.inf";
385 # Read the contents of the inf file
388 open( FD
, "<" . $inf_file ) ||
389 die "Cannot open \"" . $inf_file . "\"!";
392 die "Cannot close \"" . $inf_file . "\"!";
395 print "\n--> Updating OpensslLibCrypto.inf ... ";
397 if ( $_ =~ "# Autogenerated files list starts here" ) {
398 push @new_inf, $_, @cryptofilelist;
402 if ( $_ =~ "# Autogenerated files list ends here" ) {
412 $new_inf_file = $inf_file . ".new";
413 open( FD
, ">" . $new_inf_file ) ||
415 print( FD
@new_inf ) ||
419 rename( $new_inf_file, $inf_file ) ||
420 die "rename $inf_file";
425 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration
427 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
429 "perl -pe 's/\\n/\\r\\n/' " .
430 "< " . $OPENSSL_PATH . "/include/openssl/opensslconf.h " .
431 "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf.h"
433 die "Cannot copy opensslconf.h!";
436 print "\n--> Duplicating dso_conf.h into Include/crypto ... ";
438 "perl -pe 's/\\n/\\r\\n/' " .
439 "< " . $OPENSSL_PATH . "/include/crypto/dso_conf.h" .
440 "> " . $OPENSSL_PATH . "/../../Include/crypto/dso_conf.h"
442 die "Cannot copy dso_conf.h!";
445 print "\nProcessing Files Done!\n";