]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: disable autoload-config for OpenSSL
[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
137 if ($product =~ "libssl") {
138 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
139 next;
140 }
141 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
142 }
143 }
144 }
145
146 #
147 # Update OpensslLib.inf with autogenerated file list
148 #
149 my @new_inf = ();
150 my $subbing = 0;
151 print "\n--> Updating OpensslLib.inf ... ";
152 foreach (@inf) {
153 if ( $_ =~ "# Autogenerated files list starts here" ) {
154 push @new_inf, $_, @cryptofilelist, @sslfilelist;
155 $subbing = 1;
156 next;
157 }
158 if ( $_ =~ "# Autogenerated files list ends here" ) {
159 push @new_inf, $_;
160 $subbing = 0;
161 next;
162 }
163
164 push @new_inf, $_
165 unless ($subbing);
166 }
167
168 my $new_inf_file = $inf_file . ".new";
169 open( FD, ">" . $new_inf_file ) ||
170 die $new_inf_file;
171 print( FD @new_inf ) ||
172 die $new_inf_file;
173 close(FD) ||
174 die $new_inf_file;
175 rename( $new_inf_file, $inf_file ) ||
176 die "rename $inf_file";
177 print "Done!";
178
179 #
180 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
181 #
182 $inf_file = "OpensslLibCrypto.inf";
183
184 # Read the contents of the inf file
185 @inf = ();
186 @new_inf = ();
187 open( FD, "<" . $inf_file ) ||
188 die "Cannot open \"" . $inf_file . "\"!";
189 @inf = (<FD>);
190 close(FD) ||
191 die "Cannot close \"" . $inf_file . "\"!";
192
193 $subbing = 0;
194 print "\n--> Updating OpensslLibCrypto.inf ... ";
195 foreach (@inf) {
196 if ( $_ =~ "# Autogenerated files list starts here" ) {
197 push @new_inf, $_, @cryptofilelist;
198 $subbing = 1;
199 next;
200 }
201 if ( $_ =~ "# Autogenerated files list ends here" ) {
202 push @new_inf, $_;
203 $subbing = 0;
204 next;
205 }
206
207 push @new_inf, $_
208 unless ($subbing);
209 }
210
211 $new_inf_file = $inf_file . ".new";
212 open( FD, ">" . $new_inf_file ) ||
213 die $new_inf_file;
214 print( FD @new_inf ) ||
215 die $new_inf_file;
216 close(FD) ||
217 die $new_inf_file;
218 rename( $new_inf_file, $inf_file ) ||
219 die "rename $inf_file";
220 print "Done!";
221
222 #
223 # Copy opensslconf.h generated from OpenSSL Configuration
224 #
225 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
226 copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
227 $OPENSSL_PATH . "/../../Include/openssl/") ||
228 die "Cannot copy opensslconf.h!";
229 print "Done!\n";
230
231 print "\nProcessing Files Done!\n";
232
233 exit(0);
234