]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Update process_files.pl to generate .h files
[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 a copy of opensslconf.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 chdir($basedir) ||
110 die "Cannot change to base directory \"" . $basedir . "\"";
111
112 push @INC, $1;
113 last;
114 }
115 }
116 }
117
118 #
119 # Retrieve file lists from OpenSSL configdata
120 #
121 use configdata qw/%unified_info/;
122
123 my @cryptofilelist = ();
124 my @sslfilelist = ();
125 foreach my $product ((@{$unified_info{libraries}},
126 @{$unified_info{engines}})) {
127 foreach my $o (@{$unified_info{sources}->{$product}}) {
128 foreach my $s (@{$unified_info{sources}->{$o}}) {
129 next if ($unified_info{generate}->{$s});
130 next if $s =~ "crypto/bio/b_print.c";
131
132 # No need to add unused files in UEFI.
133 # So it can reduce porting time, compile time, library size.
134 next if $s =~ "crypto/rand/randfile.c";
135 next if $s =~ "crypto/store/";
136 next if $s =~ "crypto/err/err_all.c";
137
138 if ($product =~ "libssl") {
139 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
140 next;
141 }
142 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
143 }
144 }
145 }
146
147
148 #
149 # Update the perl script to generate the missing header files
150 #
151 my @dir_list = ();
152 for (keys %{$unified_info{dirinfo}}){
153 push @dir_list,$_;
154 }
155
156 my $dir = getcwd();
157 my @files = ();
158 my @headers = ();
159 chdir ("openssl");
160 foreach(@dir_list){
161 @files = glob($_."/*.h");
162 push @headers, @files;
163 }
164 chdir ($dir);
165
166 foreach (@headers){
167 if(/ssl/){
168 push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
169 next;
170 }
171 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";
172 }
173
174
175 #
176 # Update OpensslLib.inf with autogenerated file list
177 #
178 my @new_inf = ();
179 my $subbing = 0;
180 print "\n--> Updating OpensslLib.inf ... ";
181 foreach (@inf) {
182 if ( $_ =~ "# Autogenerated files list starts here" ) {
183 push @new_inf, $_, @cryptofilelist, @sslfilelist;
184 $subbing = 1;
185 next;
186 }
187 if ( $_ =~ "# Autogenerated files list ends here" ) {
188 push @new_inf, $_;
189 $subbing = 0;
190 next;
191 }
192
193 push @new_inf, $_
194 unless ($subbing);
195 }
196
197 my $new_inf_file = $inf_file . ".new";
198 open( FD, ">" . $new_inf_file ) ||
199 die $new_inf_file;
200 print( FD @new_inf ) ||
201 die $new_inf_file;
202 close(FD) ||
203 die $new_inf_file;
204 rename( $new_inf_file, $inf_file ) ||
205 die "rename $inf_file";
206 print "Done!";
207
208 #
209 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
210 #
211 $inf_file = "OpensslLibCrypto.inf";
212
213 # Read the contents of the inf file
214 @inf = ();
215 @new_inf = ();
216 open( FD, "<" . $inf_file ) ||
217 die "Cannot open \"" . $inf_file . "\"!";
218 @inf = (<FD>);
219 close(FD) ||
220 die "Cannot close \"" . $inf_file . "\"!";
221
222 $subbing = 0;
223 print "\n--> Updating OpensslLibCrypto.inf ... ";
224 foreach (@inf) {
225 if ( $_ =~ "# Autogenerated files list starts here" ) {
226 push @new_inf, $_, @cryptofilelist;
227 $subbing = 1;
228 next;
229 }
230 if ( $_ =~ "# Autogenerated files list ends here" ) {
231 push @new_inf, $_;
232 $subbing = 0;
233 next;
234 }
235
236 push @new_inf, $_
237 unless ($subbing);
238 }
239
240 $new_inf_file = $inf_file . ".new";
241 open( FD, ">" . $new_inf_file ) ||
242 die $new_inf_file;
243 print( FD @new_inf ) ||
244 die $new_inf_file;
245 close(FD) ||
246 die $new_inf_file;
247 rename( $new_inf_file, $inf_file ) ||
248 die "rename $inf_file";
249 print "Done!";
250
251 #
252 # Copy opensslconf.h generated from OpenSSL Configuration
253 #
254 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
255 copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
256 $OPENSSL_PATH . "/../../Include/openssl/") ||
257 die "Cannot copy opensslconf.h!";
258 print "Done!\n";
259
260 print "\nProcessing Files Done!\n";
261
262 exit(0);
263