]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Set ARC4 disable in OpensslLib
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / process_files.pl
1 #!/usr/bin/perl -w
2 #
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.
6 #
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.
11 #
12 use strict;
13 use Cwd;
14 use File::Copy;
15
16 #
17 # Find the openssl directory name for use lib. We have to do this
18 # inside of BEGIN. The variables we create here, however, don't seem
19 # to be available to the main script, so we have to repeat the
20 # exercise.
21 #
22 my $inf_file;
23 my $OPENSSL_PATH;
24 my @inf;
25
26 BEGIN {
27 $inf_file = "OpensslLib.inf";
28
29 # Read the contents of the inf file
30 open( FD, "<" . $inf_file ) ||
31 die "Cannot open \"" . $inf_file . "\"!";
32 @inf = (<FD>);
33 close(FD) ||
34 die "Cannot close \"" . $inf_file . "\"!";
35
36 foreach (@inf) {
37 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
38
39 # We need to run Configure before we can include its result...
40 $OPENSSL_PATH = $1;
41
42 my $basedir = getcwd();
43
44 chdir($OPENSSL_PATH) ||
45 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
46
47 # Configure UEFI
48 system(
49 "./Configure",
50 "UEFI",
51 "no-afalgeng",
52 "no-asm",
53 "no-async",
54 "no-autoerrinit",
55 "no-autoload-config",
56 "no-bf",
57 "no-blake2",
58 "no-camellia",
59 "no-capieng",
60 "no-cast",
61 "no-chacha",
62 "no-cms",
63 "no-ct",
64 "no-deprecated",
65 "no-dgram",
66 "no-dsa",
67 "no-dynamic-engine",
68 "no-ec",
69 "no-ec2m",
70 "no-engine",
71 "no-err",
72 "no-filenames",
73 "no-gost",
74 "no-hw",
75 "no-idea",
76 "no-md4",
77 "no-mdc2",
78 "no-pic",
79 "no-ocb",
80 "no-poly1305",
81 "no-posix-io",
82 "no-rc2",
83 "no-rc4",
84 "no-rfc3779",
85 "no-rmd160",
86 "no-scrypt",
87 "no-seed",
88 "no-sock",
89 "no-srp",
90 "no-ssl",
91 "no-stdio",
92 "no-threads",
93 "no-ts",
94 "no-ui",
95 "no-whirlpool",
96 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI
97 # UEFI only support --with-rand-seed=none
98 "--with-rand-seed=none"
99 ) == 0 ||
100 die "OpenSSL Configure failed!\n";
101
102 # Generate opensslconf.h per config data
103 system(
104 "perl -I. -Mconfigdata util/dofile.pl " .
105 "include/openssl/opensslconf.h.in " .
106 "> include/openssl/opensslconf.h"
107 ) == 0 ||
108 die "Failed to generate opensslconf.h!\n";
109
110 # Generate dso_conf.h per config data
111 system(
112 "perl -I. -Mconfigdata util/dofile.pl " .
113 "crypto/include/internal/dso_conf.h.in " .
114 "> include/internal/dso_conf.h"
115 ) == 0 ||
116 die "Failed to generate dso_conf.h!\n";
117
118 chdir($basedir) ||
119 die "Cannot change to base directory \"" . $basedir . "\"";
120
121 push @INC, $1;
122 last;
123 }
124 }
125 }
126
127 #
128 # Retrieve file lists from OpenSSL configdata
129 #
130 use configdata qw/%unified_info/;
131
132 my @cryptofilelist = ();
133 my @sslfilelist = ();
134 foreach my $product ((@{$unified_info{libraries}},
135 @{$unified_info{engines}})) {
136 foreach my $o (@{$unified_info{sources}->{$product}}) {
137 foreach my $s (@{$unified_info{sources}->{$o}}) {
138 next if ($unified_info{generate}->{$s});
139 next if $s =~ "crypto/bio/b_print.c";
140
141 # No need to add unused files in UEFI.
142 # So it can reduce porting time, compile time, library size.
143 next if $s =~ "crypto/rand/randfile.c";
144 next if $s =~ "crypto/store/";
145 next if $s =~ "crypto/err/err_all.c";
146
147 if ($product =~ "libssl") {
148 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
149 next;
150 }
151 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
152 }
153 }
154 }
155
156
157 #
158 # Update the perl script to generate the missing header files
159 #
160 my @dir_list = ();
161 for (sort keys %{$unified_info{dirinfo}}){
162 push @dir_list,$_;
163 }
164
165 my $dir = getcwd();
166 my @files = ();
167 my @headers = ();
168 chdir ("openssl");
169 foreach(@dir_list){
170 @files = glob($_."/*.h");
171 push @headers, @files;
172 }
173 chdir ($dir);
174
175 foreach (@headers){
176 if(/ssl/){
177 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
178 next;
179 }
180 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
181 }
182
183
184 #
185 # Update OpensslLib.inf with autogenerated file list
186 #
187 my @new_inf = ();
188 my $subbing = 0;
189 print "\n--> Updating OpensslLib.inf ... ";
190 foreach (@inf) {
191 if ( $_ =~ "# Autogenerated files list starts here" ) {
192 push @new_inf, $_, @cryptofilelist, @sslfilelist;
193 $subbing = 1;
194 next;
195 }
196 if ( $_ =~ "# Autogenerated files list ends here" ) {
197 push @new_inf, $_;
198 $subbing = 0;
199 next;
200 }
201
202 push @new_inf, $_
203 unless ($subbing);
204 }
205
206 my $new_inf_file = $inf_file . ".new";
207 open( FD, ">" . $new_inf_file ) ||
208 die $new_inf_file;
209 print( FD @new_inf ) ||
210 die $new_inf_file;
211 close(FD) ||
212 die $new_inf_file;
213 rename( $new_inf_file, $inf_file ) ||
214 die "rename $inf_file";
215 print "Done!";
216
217 #
218 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
219 #
220 $inf_file = "OpensslLibCrypto.inf";
221
222 # Read the contents of the inf file
223 @inf = ();
224 @new_inf = ();
225 open( FD, "<" . $inf_file ) ||
226 die "Cannot open \"" . $inf_file . "\"!";
227 @inf = (<FD>);
228 close(FD) ||
229 die "Cannot close \"" . $inf_file . "\"!";
230
231 $subbing = 0;
232 print "\n--> Updating OpensslLibCrypto.inf ... ";
233 foreach (@inf) {
234 if ( $_ =~ "# Autogenerated files list starts here" ) {
235 push @new_inf, $_, @cryptofilelist;
236 $subbing = 1;
237 next;
238 }
239 if ( $_ =~ "# Autogenerated files list ends here" ) {
240 push @new_inf, $_;
241 $subbing = 0;
242 next;
243 }
244
245 push @new_inf, $_
246 unless ($subbing);
247 }
248
249 $new_inf_file = $inf_file . ".new";
250 open( FD, ">" . $new_inf_file ) ||
251 die $new_inf_file;
252 print( FD @new_inf ) ||
253 die $new_inf_file;
254 close(FD) ||
255 die $new_inf_file;
256 rename( $new_inf_file, $inf_file ) ||
257 die "rename $inf_file";
258 print "Done!";
259
260 #
261 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration
262 #
263 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
264 copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
265 $OPENSSL_PATH . "/../../Include/openssl/") ||
266 die "Cannot copy opensslconf.h!";
267 print "Done!";
268 print "\n--> Duplicating dso_conf.h into Include/internal ... ";
269 copy($OPENSSL_PATH . "/include/internal/dso_conf.h",
270 $OPENSSL_PATH . "/../../Include/internal/") ||
271 die "Cannot copy dso_conf.h!";
272 print "Done!\n";
273
274 print "\nProcessing Files Done!\n";
275
276 exit(0);
277