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