]>
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 = "#";
104 die "Unsupported architecture \"" . $arch . "\"!";
106 if ($extension eq "nasm") {
107 if (`nasm -v 2>&1`) {
108 #Presence of nasm executable will trigger inclusion of AVX instructions
109 die "\nCannot run assembly generators with NASM in path!\n\n";
113 # Prepare assembly folder
115 opendir my $dir, $arch ||
116 die "Cannot open assembly folder \"" . $arch . "\"!";
117 while (defined (my $file = readdir $dir)) {
118 if (-d
"$arch/$file") {
119 next if $file eq ".";
120 next if $file eq "..";
121 remove_tree
("$arch/$file", {safe
=> 1}) ||
122 die "Cannot clean assembly folder \"" . "$arch/$file" . "\"!";
128 die "Cannot create assembly folder \"" . $arch . "\"!";
132 # Read the contents of the inf file
133 open( FD
, "<" . $inf_file ) ||
134 die "Cannot open \"" . $inf_file . "\"!";
137 die "Cannot close \"" . $inf_file . "\"!";
140 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
142 # We need to run Configure before we can include its result...
145 my $basedir = getcwd
();
147 chdir($OPENSSL_PATH) ||
148 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
153 "--config=../UefiAsm.conf",
158 "no-autoload-config",
199 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI
200 # UEFI only support --with-rand-seed=none
201 "--with-rand-seed=none"
203 die "OpenSSL Configure failed!\n";
205 # Generate opensslconf.h per config data
207 "perl -I. -Mconfigdata util/dofile.pl " .
208 "include/openssl/opensslconf.h.in " .
209 "> include/openssl/opensslconf.h"
211 die "Failed to generate opensslconf.h!\n";
213 # Generate dso_conf.h per config data
215 "perl -I. -Mconfigdata util/dofile.pl " .
216 "include/crypto/dso_conf.h.in " .
217 "> include/crypto/dso_conf.h"
219 die "Failed to generate dso_conf.h!\n";
222 die "Cannot change to base directory \"" . $basedir . "\"";
231 # Retrieve file lists from OpenSSL configdata
233 use configdata qw
/%unified_info/;
234 use configdata qw
/%config/;
235 use configdata qw
/%target/;
238 # Collect build flags from configdata
241 foreach my $f (@{$config{lib_defines
}}) {
245 my @cryptofilelist = ();
246 my @sslfilelist = ();
247 my @asmfilelist = ();
249 foreach my $product ((@{$unified_info{libraries
}},
250 @{$unified_info{engines
}})) {
251 foreach my $o (@{$unified_info{sources
}->{$product}}) {
252 foreach my $s (@{$unified_info{sources
}->{$o}}) {
253 # No need to add unused files in UEFI.
254 # So it can reduce porting time, compile time, library size.
255 next if $s =~ "crypto/bio/b_print.c";
256 next if $s =~ "crypto/rand/randfile.c";
257 next if $s =~ "crypto/store/";
258 next if $s =~ "crypto/err/err_all.c";
259 next if $s =~ "crypto/aes/aes_ecb.c";
261 if ($unified_info{generate
}->{$s}) {
263 my $buildstring = "perl";
264 foreach my $arg (@{$unified_info{generate
}->{$s}}) {
266 $buildstring .= " ./openssl/$arg";
267 } elsif ($arg =~ "PERLASM_SCHEME") {
268 $buildstring .= " $target{perlasm_scheme}";
269 } elsif ($arg =~ "LIB_CFLAGS") {
270 $buildstring .= "$flags";
273 ($s, my $path, undef) = fileparse
($s, qr/\.[^.]*/);
274 $buildstring .= " ./$arch/$path$s.$extension";
275 make_path
("./$arch/$path");
276 push @asmbuild, "$buildstring\n";
277 push @asmfilelist, " $arch/$path$s.$extension\r\n";
281 if ($product =~ "libssl") {
282 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
285 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
292 # Update the perl script to generate the missing header files
295 for (sort keys %{$unified_info{dirinfo
}}){
304 @files = glob($_."/*.h");
305 push @headers, @files;
311 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
314 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
319 # Generate assembly files
322 print "\n--> Generating assembly files ... ";
323 foreach my $buildstring (@asmbuild) {
324 system ("$buildstring");
325 copy_license_header
($buildstring);
331 # Update OpensslLib.inf with autogenerated file list
335 print "\n--> Updating $inf_file ... ";
337 if ($_ =~ "DEFINE OPENSSL_FLAGS_CONFIG") {
338 push @new_inf, " DEFINE OPENSSL_FLAGS_CONFIG =" . $flags . "\r\n";
341 if ( $_ =~ "# Autogenerated files list starts here" ) {
342 push @new_inf, $_, @asmfilelist, @cryptofilelist, @sslfilelist;
346 if ( $_ =~ "# Autogenerated files list ends here" ) {
356 my $new_inf_file = $inf_file . ".new";
357 open( FD
, ">" . $new_inf_file ) ||
359 print( FD
@new_inf ) ||
363 rename( $new_inf_file, $inf_file ) ||
364 die "rename $inf_file";
367 if (!defined $arch) {
369 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
371 $inf_file = "OpensslLibCrypto.inf";
373 # Read the contents of the inf file
376 open( FD
, "<" . $inf_file ) ||
377 die "Cannot open \"" . $inf_file . "\"!";
380 die "Cannot close \"" . $inf_file . "\"!";
383 print "\n--> Updating OpensslLibCrypto.inf ... ";
385 if ( $_ =~ "# Autogenerated files list starts here" ) {
386 push @new_inf, $_, @cryptofilelist;
390 if ( $_ =~ "# Autogenerated files list ends here" ) {
400 $new_inf_file = $inf_file . ".new";
401 open( FD
, ">" . $new_inf_file ) ||
403 print( FD
@new_inf ) ||
407 rename( $new_inf_file, $inf_file ) ||
408 die "rename $inf_file";
413 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration
415 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
417 "perl -pe 's/\\n/\\r\\n/' " .
418 "< " . $OPENSSL_PATH . "/include/openssl/opensslconf.h " .
419 "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf.h"
421 die "Cannot copy opensslconf.h!";
424 print "\n--> Duplicating dso_conf.h into Include/crypto ... ";
426 "perl -pe 's/\\n/\\r\\n/' " .
427 "< " . $OPENSSL_PATH . "/include/crypto/dso_conf.h" .
428 "> " . $OPENSSL_PATH . "/../../Include/crypto/dso_conf.h"
430 die "Cannot copy dso_conf.h!";
433 print "\nProcessing Files Done!\n";