]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Set TDES 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-des",
66 "no-dgram",
67 "no-dsa",
68 "no-dynamic-engine",
69 "no-ec",
70 "no-ec2m",
71 "no-engine",
72 "no-err",
73 "no-filenames",
74 "no-gost",
75 "no-hw",
76 "no-idea",
77 "no-md4",
78 "no-mdc2",
79 "no-pic",
80 "no-ocb",
81 "no-poly1305",
82 "no-posix-io",
83 "no-rc2",
84 "no-rc4",
85 "no-rfc3779",
86 "no-rmd160",
87 "no-scrypt",
88 "no-seed",
89 "no-sock",
90 "no-srp",
91 "no-ssl",
92 "no-stdio",
93 "no-threads",
94 "no-ts",
95 "no-ui",
96 "no-whirlpool",
97 # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI
98 # UEFI only support --with-rand-seed=none
99 "--with-rand-seed=none"
100 ) == 0 ||
101 die "OpenSSL Configure failed!\n";
102
103 # Generate opensslconf.h per config data
104 system(
105 "perl -I. -Mconfigdata util/dofile.pl " .
106 "include/openssl/opensslconf.h.in " .
107 "> include/openssl/opensslconf.h"
108 ) == 0 ||
109 die "Failed to generate opensslconf.h!\n";
110
111 # Generate dso_conf.h per config data
112 system(
113 "perl -I. -Mconfigdata util/dofile.pl " .
114 "crypto/include/internal/dso_conf.h.in " .
115 "> include/internal/dso_conf.h"
116 ) == 0 ||
117 die "Failed to generate dso_conf.h!\n";
118
119 chdir($basedir) ||
120 die "Cannot change to base directory \"" . $basedir . "\"";
121
122 push @INC, $1;
123 last;
124 }
125 }
126 }
127
128 #
129 # Retrieve file lists from OpenSSL configdata
130 #
131 use configdata qw/%unified_info/;
132
133 my @cryptofilelist = ();
134 my @sslfilelist = ();
135 foreach my $product ((@{$unified_info{libraries}},
136 @{$unified_info{engines}})) {
137 foreach my $o (@{$unified_info{sources}->{$product}}) {
138 foreach my $s (@{$unified_info{sources}->{$o}}) {
139 next if ($unified_info{generate}->{$s});
140 next if $s =~ "crypto/bio/b_print.c";
141
142 # No need to add unused files in UEFI.
143 # So it can reduce porting time, compile time, library size.
144 next if $s =~ "crypto/rand/randfile.c";
145 next if $s =~ "crypto/store/";
146 next if $s =~ "crypto/err/err_all.c";
147
148 if ($product =~ "libssl") {
149 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
150 next;
151 }
152 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
153 }
154 }
155 }
156
157
158 #
159 # Update the perl script to generate the missing header files
160 #
161 my @dir_list = ();
162 for (sort keys %{$unified_info{dirinfo}}){
163 push @dir_list,$_;
164 }
165
166 my $dir = getcwd();
167 my @files = ();
168 my @headers = ();
169 chdir ("openssl");
170 foreach(@dir_list){
171 @files = glob($_."/*.h");
172 push @headers, @files;
173 }
174 chdir ($dir);
175
176 foreach (@headers){
177 if(/ssl/){
178 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
179 next;
180 }
181 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
182 }
183
184
185 #
186 # Update OpensslLib.inf with autogenerated file list
187 #
188 my @new_inf = ();
189 my $subbing = 0;
190 print "\n--> Updating OpensslLib.inf ... ";
191 foreach (@inf) {
192 if ( $_ =~ "# Autogenerated files list starts here" ) {
193 push @new_inf, $_, @cryptofilelist, @sslfilelist;
194 $subbing = 1;
195 next;
196 }
197 if ( $_ =~ "# Autogenerated files list ends here" ) {
198 push @new_inf, $_;
199 $subbing = 0;
200 next;
201 }
202
203 push @new_inf, $_
204 unless ($subbing);
205 }
206
207 my $new_inf_file = $inf_file . ".new";
208 open( FD, ">" . $new_inf_file ) ||
209 die $new_inf_file;
210 print( FD @new_inf ) ||
211 die $new_inf_file;
212 close(FD) ||
213 die $new_inf_file;
214 rename( $new_inf_file, $inf_file ) ||
215 die "rename $inf_file";
216 print "Done!";
217
218 #
219 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
220 #
221 $inf_file = "OpensslLibCrypto.inf";
222
223 # Read the contents of the inf file
224 @inf = ();
225 @new_inf = ();
226 open( FD, "<" . $inf_file ) ||
227 die "Cannot open \"" . $inf_file . "\"!";
228 @inf = (<FD>);
229 close(FD) ||
230 die "Cannot close \"" . $inf_file . "\"!";
231
232 $subbing = 0;
233 print "\n--> Updating OpensslLibCrypto.inf ... ";
234 foreach (@inf) {
235 if ( $_ =~ "# Autogenerated files list starts here" ) {
236 push @new_inf, $_, @cryptofilelist;
237 $subbing = 1;
238 next;
239 }
240 if ( $_ =~ "# Autogenerated files list ends here" ) {
241 push @new_inf, $_;
242 $subbing = 0;
243 next;
244 }
245
246 push @new_inf, $_
247 unless ($subbing);
248 }
249
250 $new_inf_file = $inf_file . ".new";
251 open( FD, ">" . $new_inf_file ) ||
252 die $new_inf_file;
253 print( FD @new_inf ) ||
254 die $new_inf_file;
255 close(FD) ||
256 die $new_inf_file;
257 rename( $new_inf_file, $inf_file ) ||
258 die "rename $inf_file";
259 print "Done!";
260
261 #
262 # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration
263 #
264 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
265 copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
266 $OPENSSL_PATH . "/../../Include/openssl/") ||
267 die "Cannot copy opensslconf.h!";
268 print "Done!";
269 print "\n--> Duplicating dso_conf.h into Include/internal ... ";
270 copy($OPENSSL_PATH . "/include/internal/dso_conf.h",
271 $OPENSSL_PATH . "/../../Include/internal/") ||
272 die "Cannot copy dso_conf.h!";
273 print "Done!\n";
274
275 print "\nProcessing Files Done!\n";
276
277 exit(0);
278