]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Set MD4 disable in OpensslLib
[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
1bcc65b9 5# takes copies of opensslconf.h and dso_conf.h.\r
264702a0
HW
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
264702a0 54 "no-autoerrinit",\r
c72ca466 55 "no-autoload-config",\r
264702a0
HW
56 "no-bf",\r
57 "no-blake2",\r
58 "no-camellia",\r
59 "no-capieng",\r
60 "no-cast",\r
61 "no-chacha",\r
62 "no-cms",\r
63 "no-ct",\r
64 "no-deprecated",\r
65 "no-dgram",\r
66 "no-dsa",\r
67 "no-dynamic-engine",\r
68 "no-ec",\r
69 "no-ec2m",\r
70 "no-engine",\r
71 "no-err",\r
72 "no-filenames",\r
73 "no-gost",\r
74 "no-hw",\r
75 "no-idea",\r
9b2a082e 76 "no-md4",\r
264702a0
HW
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
1bcc65b9
SZ
109 # Generate dso_conf.h per config data\r
110 system(\r
111 "perl -I. -Mconfigdata util/dofile.pl " .\r
112 "crypto/include/internal/dso_conf.h.in " .\r
113 "> include/internal/dso_conf.h"\r
114 ) == 0 ||\r
115 die "Failed to generate dso_conf.h!\n";\r
116\r
264702a0
HW
117 chdir($basedir) ||\r
118 die "Cannot change to base directory \"" . $basedir . "\"";\r
119\r
120 push @INC, $1;\r
121 last;\r
122 }\r
123 }\r
124}\r
125\r
126#\r
127# Retrieve file lists from OpenSSL configdata\r
128#\r
129use configdata qw/%unified_info/;\r
130\r
131my @cryptofilelist = ();\r
132my @sslfilelist = ();\r
133foreach my $product ((@{$unified_info{libraries}},\r
134 @{$unified_info{engines}})) {\r
135 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
136 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
137 next if ($unified_info{generate}->{$s});\r
138 next if $s =~ "crypto/bio/b_print.c";\r
7eee0488
XL
139\r
140 # No need to add unused files in UEFI.\r
141 # So it can reduce porting time, compile time, library size.\r
142 next if $s =~ "crypto/rand/randfile.c";\r
143 next if $s =~ "crypto/store/";\r
51f7a3e6 144 next if $s =~ "crypto/err/err_all.c";\r
7eee0488 145\r
264702a0
HW
146 if ($product =~ "libssl") {\r
147 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
148 next;\r
149 }\r
150 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
151 }\r
152 }\r
153}\r
154\r
9f4fbd56
SZ
155\r
156#\r
157# Update the perl script to generate the missing header files\r
158#\r
159my @dir_list = ();\r
c72ca466 160for (sort keys %{$unified_info{dirinfo}}){\r
9f4fbd56
SZ
161 push @dir_list,$_;\r
162}\r
163\r
164my $dir = getcwd();\r
165my @files = ();\r
166my @headers = ();\r
167chdir ("openssl");\r
168foreach(@dir_list){\r
169 @files = glob($_."/*.h");\r
170 push @headers, @files;\r
171}\r
172chdir ($dir);\r
173\r
174foreach (@headers){\r
175 if(/ssl/){\r
176 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
177 next;\r
178 }\r
179 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r
180}\r
181\r
182\r
264702a0
HW
183#\r
184# Update OpensslLib.inf with autogenerated file list\r
185#\r
186my @new_inf = ();\r
187my $subbing = 0;\r
188print "\n--> Updating OpensslLib.inf ... ";\r
189foreach (@inf) {\r
190 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
191 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
192 $subbing = 1;\r
193 next;\r
194 }\r
195 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
196 push @new_inf, $_;\r
197 $subbing = 0;\r
198 next;\r
199 }\r
200\r
201 push @new_inf, $_\r
202 unless ($subbing);\r
203}\r
204\r
205my $new_inf_file = $inf_file . ".new";\r
206open( FD, ">" . $new_inf_file ) ||\r
207 die $new_inf_file;\r
208print( FD @new_inf ) ||\r
209 die $new_inf_file;\r
210close(FD) ||\r
211 die $new_inf_file;\r
212rename( $new_inf_file, $inf_file ) ||\r
213 die "rename $inf_file";\r
214print "Done!";\r
215\r
216#\r
217# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
218#\r
219$inf_file = "OpensslLibCrypto.inf";\r
220\r
221# Read the contents of the inf file\r
222@inf = ();\r
223@new_inf = ();\r
224open( FD, "<" . $inf_file ) ||\r
225 die "Cannot open \"" . $inf_file . "\"!";\r
226@inf = (<FD>);\r
227close(FD) ||\r
228 die "Cannot close \"" . $inf_file . "\"!";\r
229\r
230$subbing = 0;\r
231print "\n--> Updating OpensslLibCrypto.inf ... ";\r
232foreach (@inf) {\r
233 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
234 push @new_inf, $_, @cryptofilelist;\r
235 $subbing = 1;\r
236 next;\r
237 }\r
238 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
239 push @new_inf, $_;\r
240 $subbing = 0;\r
241 next;\r
242 }\r
243\r
244 push @new_inf, $_\r
245 unless ($subbing);\r
246}\r
247\r
248$new_inf_file = $inf_file . ".new";\r
249open( FD, ">" . $new_inf_file ) ||\r
250 die $new_inf_file;\r
251print( FD @new_inf ) ||\r
252 die $new_inf_file;\r
253close(FD) ||\r
254 die $new_inf_file;\r
255rename( $new_inf_file, $inf_file ) ||\r
256 die "rename $inf_file";\r
257print "Done!";\r
258\r
259#\r
1bcc65b9 260# Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r
264702a0
HW
261#\r
262print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
263copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 264 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0 265 die "Cannot copy opensslconf.h!";\r
1bcc65b9
SZ
266print "Done!";\r
267print "\n--> Duplicating dso_conf.h into Include/internal ... ";\r
268copy($OPENSSL_PATH . "/include/internal/dso_conf.h",\r
269 $OPENSSL_PATH . "/../../Include/internal/") ||\r
270 die "Cannot copy dso_conf.h!";\r
264702a0
HW
271print "Done!\n";\r
272\r
273print "\nProcessing Files Done!\n";\r
274\r
275exit(0);\r
276\r