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