]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
BaseTools: Move Build Cache related function out of CreateAsBuiltInf
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / process_files.pl
CommitLineData
264702a0
HW
1#!/usr/bin/perl -w\r
2#\r
3# This script runs the OpenSSL Configure script, then processes the\r
4# resulting file list into our local OpensslLib[Crypto].inf and also\r
5# takes a copy of opensslconf.h.\r
6#\r
7# This only needs to be done once by a developer when updating to a\r
8# new version of OpenSSL (or changing options, etc.). Normal users\r
9# do not need to do this, since the results are stored in the EDK2\r
10# git repository for them.\r
11#\r
12use strict;\r
13use Cwd;\r
14use File::Copy;\r
15\r
16#\r
17# Find the openssl directory name for use lib. We have to do this\r
18# inside of BEGIN. The variables we create here, however, don't seem\r
19# to be available to the main script, so we have to repeat the\r
20# exercise.\r
21#\r
22my $inf_file;\r
23my $OPENSSL_PATH;\r
24my @inf;\r
25\r
26BEGIN {\r
27 $inf_file = "OpensslLib.inf";\r
28\r
29 # Read the contents of the inf file\r
30 open( FD, "<" . $inf_file ) ||\r
31 die "Cannot open \"" . $inf_file . "\"!";\r
32 @inf = (<FD>);\r
33 close(FD) ||\r
34 die "Cannot close \"" . $inf_file . "\"!";\r
35\r
36 foreach (@inf) {\r
37 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {\r
38\r
39 # We need to run Configure before we can include its result...\r
40 $OPENSSL_PATH = $1;\r
41\r
42 my $basedir = getcwd();\r
43\r
44 chdir($OPENSSL_PATH) ||\r
45 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";\r
46\r
47 # Configure UEFI\r
48 system(\r
49 "./Configure",\r
50 "UEFI",\r
51 "no-afalgeng",\r
52 "no-asm",\r
53 "no-async",\r
54 "no-autoalginit",\r
55 "no-autoerrinit",\r
b86fbe1f 56 "no-autoload-config",
264702a0
HW
57 "no-bf",\r
58 "no-blake2",\r
59 "no-camellia",\r
60 "no-capieng",\r
61 "no-cast",\r
62 "no-chacha",\r
63 "no-cms",\r
64 "no-ct",\r
65 "no-deprecated",\r
66 "no-dgram",\r
67 "no-dsa",\r
68 "no-dynamic-engine",\r
69 "no-ec",\r
70 "no-ec2m",\r
71 "no-engine",\r
72 "no-err",\r
73 "no-filenames",\r
74 "no-gost",\r
75 "no-hw",\r
76 "no-idea",\r
77 "no-mdc2",\r
78 "no-pic",\r
79 "no-ocb",\r
80 "no-poly1305",\r
81 "no-posix-io",\r
82 "no-rc2",\r
83 "no-rfc3779",\r
84 "no-rmd160",\r
85 "no-scrypt",\r
86 "no-seed",\r
87 "no-sock",\r
88 "no-srp",\r
89 "no-ssl",\r
90 "no-stdio",\r
91 "no-threads",\r
92 "no-ts",\r
93 "no-ui",\r
6fcc3d68
XL
94 "no-whirlpool",\r
95 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI\r
96 # UEFI only support --with-rand-seed=none\r
97 "--with-rand-seed=none"\r
264702a0
HW
98 ) == 0 ||\r
99 die "OpenSSL Configure failed!\n";\r
100\r
101 # Generate opensslconf.h per config data\r
102 system(\r
103 "perl -I. -Mconfigdata util/dofile.pl " .\r
104 "include/openssl/opensslconf.h.in " .\r
105 "> include/openssl/opensslconf.h"\r
106 ) == 0 ||\r
107 die "Failed to generate opensslconf.h!\n";\r
108\r
109 chdir($basedir) ||\r
110 die "Cannot change to base directory \"" . $basedir . "\"";\r
111\r
112 push @INC, $1;\r
113 last;\r
114 }\r
115 }\r
116}\r
117\r
118#\r
119# Retrieve file lists from OpenSSL configdata\r
120#\r
121use configdata qw/%unified_info/;\r
122\r
123my @cryptofilelist = ();\r
124my @sslfilelist = ();\r
125foreach my $product ((@{$unified_info{libraries}},\r
126 @{$unified_info{engines}})) {\r
127 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
128 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
129 next if ($unified_info{generate}->{$s});\r
130 next if $s =~ "crypto/bio/b_print.c";\r
7eee0488
XL
131\r
132 # No need to add unused files in UEFI.\r
133 # So it can reduce porting time, compile time, library size.\r
134 next if $s =~ "crypto/rand/randfile.c";\r
135 next if $s =~ "crypto/store/";\r
136\r
264702a0
HW
137 if ($product =~ "libssl") {\r
138 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
139 next;\r
140 }\r
141 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
142 }\r
143 }\r
144}\r
145\r
146#\r
147# Update OpensslLib.inf with autogenerated file list\r
148#\r
149my @new_inf = ();\r
150my $subbing = 0;\r
151print "\n--> Updating OpensslLib.inf ... ";\r
152foreach (@inf) {\r
153 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
154 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
155 $subbing = 1;\r
156 next;\r
157 }\r
158 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
159 push @new_inf, $_;\r
160 $subbing = 0;\r
161 next;\r
162 }\r
163\r
164 push @new_inf, $_\r
165 unless ($subbing);\r
166}\r
167\r
168my $new_inf_file = $inf_file . ".new";\r
169open( FD, ">" . $new_inf_file ) ||\r
170 die $new_inf_file;\r
171print( FD @new_inf ) ||\r
172 die $new_inf_file;\r
173close(FD) ||\r
174 die $new_inf_file;\r
175rename( $new_inf_file, $inf_file ) ||\r
176 die "rename $inf_file";\r
177print "Done!";\r
178\r
179#\r
180# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
181#\r
182$inf_file = "OpensslLibCrypto.inf";\r
183\r
184# Read the contents of the inf file\r
185@inf = ();\r
186@new_inf = ();\r
187open( FD, "<" . $inf_file ) ||\r
188 die "Cannot open \"" . $inf_file . "\"!";\r
189@inf = (<FD>);\r
190close(FD) ||\r
191 die "Cannot close \"" . $inf_file . "\"!";\r
192\r
193$subbing = 0;\r
194print "\n--> Updating OpensslLibCrypto.inf ... ";\r
195foreach (@inf) {\r
196 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
197 push @new_inf, $_, @cryptofilelist;\r
198 $subbing = 1;\r
199 next;\r
200 }\r
201 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
202 push @new_inf, $_;\r
203 $subbing = 0;\r
204 next;\r
205 }\r
206\r
207 push @new_inf, $_\r
208 unless ($subbing);\r
209}\r
210\r
211$new_inf_file = $inf_file . ".new";\r
212open( FD, ">" . $new_inf_file ) ||\r
213 die $new_inf_file;\r
214print( FD @new_inf ) ||\r
215 die $new_inf_file;\r
216close(FD) ||\r
217 die $new_inf_file;\r
218rename( $new_inf_file, $inf_file ) ||\r
219 die "rename $inf_file";\r
220print "Done!";\r
221\r
222#\r
223# Copy opensslconf.h generated from OpenSSL Configuration\r
224#\r
225print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
226copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 227 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0
HW
228 die "Cannot copy opensslconf.h!";\r
229print "Done!\n";\r
230\r
231print "\nProcessing Files Done!\n";\r
232\r
233exit(0);\r
234\r