]>
Commit | Line | Data |
---|---|---|
264702a0 HW |
1 | #!/usr/bin/perl -w\r |
2 | #\r | |
3 | # This script runs the OpenSSL Configure script, then processes the\r | |
4 | # resulting file list into our local OpensslLib[Crypto].inf and also\r | |
1bcc65b9 | 5 | # takes copies of opensslconf.h and dso_conf.h.\r |
264702a0 HW |
6 | #\r |
7 | # This only needs to be done once by a developer when updating to a\r | |
8 | # new version of OpenSSL (or changing options, etc.). Normal users\r | |
9 | # do not need to do this, since the results are stored in the EDK2\r | |
10 | # git repository for them.\r | |
11 | #\r | |
12 | use strict;\r | |
13 | use Cwd;\r | |
14 | use File::Copy;\r | |
15 | \r | |
16 | #\r | |
17 | # Find the openssl directory name for use lib. We have to do this\r | |
18 | # inside of BEGIN. The variables we create here, however, don't seem\r | |
19 | # to be available to the main script, so we have to repeat the\r | |
20 | # exercise.\r | |
21 | #\r | |
22 | my $inf_file;\r | |
23 | my $OPENSSL_PATH;\r | |
24 | my @inf;\r | |
25 | \r | |
26 | BEGIN {\r | |
27 | $inf_file = "OpensslLib.inf";\r | |
28 | \r | |
29 | # Read the contents of the inf file\r | |
30 | open( FD, "<" . $inf_file ) ||\r | |
31 | die "Cannot open \"" . $inf_file . "\"!";\r | |
32 | @inf = (<FD>);\r | |
33 | close(FD) ||\r | |
34 | die "Cannot close \"" . $inf_file . "\"!";\r | |
35 | \r | |
36 | foreach (@inf) {\r | |
37 | if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {\r | |
38 | \r | |
39 | # We need to run Configure before we can include its result...\r | |
40 | $OPENSSL_PATH = $1;\r | |
41 | \r | |
42 | my $basedir = getcwd();\r | |
43 | \r | |
44 | chdir($OPENSSL_PATH) ||\r | |
45 | die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";\r | |
46 | \r | |
47 | # Configure UEFI\r | |
48 | system(\r | |
49 | "./Configure",\r | |
50 | "UEFI",\r | |
51 | "no-afalgeng",\r | |
52 | "no-asm",\r | |
53 | "no-async",\r | |
264702a0 | 54 | "no-autoerrinit",\r |
c72ca466 | 55 | "no-autoload-config",\r |
264702a0 HW |
56 | "no-bf",\r |
57 | "no-blake2",\r | |
58 | "no-camellia",\r | |
59 | "no-capieng",\r | |
60 | "no-cast",\r | |
61 | "no-chacha",\r | |
62 | "no-cms",\r | |
63 | "no-ct",\r | |
64 | "no-deprecated",\r | |
394d5896 | 65 | "no-des",\r |
264702a0 HW |
66 | "no-dgram",\r |
67 | "no-dsa",\r | |
68 | "no-dynamic-engine",\r | |
69 | "no-ec",\r | |
70 | "no-ec2m",\r | |
71 | "no-engine",\r | |
72 | "no-err",\r | |
73 | "no-filenames",\r | |
74 | "no-gost",\r | |
75 | "no-hw",\r | |
76 | "no-idea",\r | |
9b2a082e | 77 | "no-md4",\r |
264702a0 HW |
78 | "no-mdc2",\r |
79 | "no-pic",\r | |
80 | "no-ocb",\r | |
81 | "no-poly1305",\r | |
82 | "no-posix-io",\r | |
83 | "no-rc2",\r | |
f4c15d38 | 84 | "no-rc4",\r |
264702a0 HW |
85 | "no-rfc3779",\r |
86 | "no-rmd160",\r | |
87 | "no-scrypt",\r | |
88 | "no-seed",\r | |
89 | "no-sock",\r | |
90 | "no-srp",\r | |
91 | "no-ssl",\r | |
92 | "no-stdio",\r | |
93 | "no-threads",\r | |
94 | "no-ts",\r | |
95 | "no-ui",\r | |
6fcc3d68 XL |
96 | "no-whirlpool",\r |
97 | # OpenSSL1_1_1b doesn't support default rand-seed-os for UEFI\r | |
98 | # UEFI only support --with-rand-seed=none\r | |
99 | "--with-rand-seed=none"\r | |
264702a0 HW |
100 | ) == 0 ||\r |
101 | die "OpenSSL Configure failed!\n";\r | |
102 | \r | |
103 | # Generate opensslconf.h per config data\r | |
104 | system(\r | |
105 | "perl -I. -Mconfigdata util/dofile.pl " .\r | |
106 | "include/openssl/opensslconf.h.in " .\r | |
107 | "> include/openssl/opensslconf.h"\r | |
108 | ) == 0 ||\r | |
109 | die "Failed to generate opensslconf.h!\n";\r | |
110 | \r | |
1bcc65b9 SZ |
111 | # Generate dso_conf.h per config data\r |
112 | system(\r | |
113 | "perl -I. -Mconfigdata util/dofile.pl " .\r | |
8c30327d GJ |
114 | "include/crypto/dso_conf.h.in " .\r |
115 | "> include/crypto/dso_conf.h"\r | |
1bcc65b9 SZ |
116 | ) == 0 ||\r |
117 | die "Failed to generate dso_conf.h!\n";\r | |
118 | \r | |
264702a0 HW |
119 | chdir($basedir) ||\r |
120 | die "Cannot change to base directory \"" . $basedir . "\"";\r | |
121 | \r | |
122 | push @INC, $1;\r | |
123 | last;\r | |
124 | }\r | |
125 | }\r | |
126 | }\r | |
127 | \r | |
128 | #\r | |
129 | # Retrieve file lists from OpenSSL configdata\r | |
130 | #\r | |
131 | use configdata qw/%unified_info/;\r | |
132 | \r | |
133 | my @cryptofilelist = ();\r | |
134 | my @sslfilelist = ();\r | |
135 | foreach my $product ((@{$unified_info{libraries}},\r | |
136 | @{$unified_info{engines}})) {\r | |
137 | foreach my $o (@{$unified_info{sources}->{$product}}) {\r | |
138 | foreach my $s (@{$unified_info{sources}->{$o}}) {\r | |
139 | next if ($unified_info{generate}->{$s});\r | |
140 | next if $s =~ "crypto/bio/b_print.c";\r | |
7eee0488 XL |
141 | \r |
142 | # No need to add unused files in UEFI.\r | |
143 | # So it can reduce porting time, compile time, library size.\r | |
144 | next if $s =~ "crypto/rand/randfile.c";\r | |
145 | next if $s =~ "crypto/store/";\r | |
51f7a3e6 | 146 | next if $s =~ "crypto/err/err_all.c";\r |
89db28b9 | 147 | next if $s =~ "crypto/aes/aes_ecb.c";\r |
7eee0488 | 148 | \r |
264702a0 HW |
149 | if ($product =~ "libssl") {\r |
150 | push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r | |
151 | next;\r | |
152 | }\r | |
153 | push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r | |
154 | }\r | |
155 | }\r | |
156 | }\r | |
157 | \r | |
9f4fbd56 SZ |
158 | \r |
159 | #\r | |
160 | # Update the perl script to generate the missing header files\r | |
161 | #\r | |
162 | my @dir_list = ();\r | |
c72ca466 | 163 | for (sort keys %{$unified_info{dirinfo}}){\r |
9f4fbd56 SZ |
164 | push @dir_list,$_;\r |
165 | }\r | |
166 | \r | |
167 | my $dir = getcwd();\r | |
168 | my @files = ();\r | |
169 | my @headers = ();\r | |
170 | chdir ("openssl");\r | |
171 | foreach(@dir_list){\r | |
172 | @files = glob($_."/*.h");\r | |
173 | push @headers, @files;\r | |
174 | }\r | |
175 | chdir ($dir);\r | |
176 | \r | |
177 | foreach (@headers){\r | |
178 | if(/ssl/){\r | |
179 | push @sslfilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r | |
180 | next;\r | |
181 | }\r | |
182 | push @cryptofilelist, ' $(OPENSSL_PATH)/' . $_ . "\r\n";\r | |
183 | }\r | |
184 | \r | |
185 | \r | |
264702a0 HW |
186 | #\r |
187 | # Update OpensslLib.inf with autogenerated file list\r | |
188 | #\r | |
189 | my @new_inf = ();\r | |
190 | my $subbing = 0;\r | |
191 | print "\n--> Updating OpensslLib.inf ... ";\r | |
192 | foreach (@inf) {\r | |
193 | if ( $_ =~ "# Autogenerated files list starts here" ) {\r | |
194 | push @new_inf, $_, @cryptofilelist, @sslfilelist;\r | |
195 | $subbing = 1;\r | |
196 | next;\r | |
197 | }\r | |
198 | if ( $_ =~ "# Autogenerated files list ends here" ) {\r | |
199 | push @new_inf, $_;\r | |
200 | $subbing = 0;\r | |
201 | next;\r | |
202 | }\r | |
203 | \r | |
204 | push @new_inf, $_\r | |
205 | unless ($subbing);\r | |
206 | }\r | |
207 | \r | |
208 | my $new_inf_file = $inf_file . ".new";\r | |
209 | open( FD, ">" . $new_inf_file ) ||\r | |
210 | die $new_inf_file;\r | |
211 | print( FD @new_inf ) ||\r | |
212 | die $new_inf_file;\r | |
213 | close(FD) ||\r | |
214 | die $new_inf_file;\r | |
215 | rename( $new_inf_file, $inf_file ) ||\r | |
216 | die "rename $inf_file";\r | |
217 | print "Done!";\r | |
218 | \r | |
219 | #\r | |
220 | # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r | |
221 | #\r | |
222 | $inf_file = "OpensslLibCrypto.inf";\r | |
223 | \r | |
224 | # Read the contents of the inf file\r | |
225 | @inf = ();\r | |
226 | @new_inf = ();\r | |
227 | open( FD, "<" . $inf_file ) ||\r | |
228 | die "Cannot open \"" . $inf_file . "\"!";\r | |
229 | @inf = (<FD>);\r | |
230 | close(FD) ||\r | |
231 | die "Cannot close \"" . $inf_file . "\"!";\r | |
232 | \r | |
233 | $subbing = 0;\r | |
234 | print "\n--> Updating OpensslLibCrypto.inf ... ";\r | |
235 | foreach (@inf) {\r | |
236 | if ( $_ =~ "# Autogenerated files list starts here" ) {\r | |
237 | push @new_inf, $_, @cryptofilelist;\r | |
238 | $subbing = 1;\r | |
239 | next;\r | |
240 | }\r | |
241 | if ( $_ =~ "# Autogenerated files list ends here" ) {\r | |
242 | push @new_inf, $_;\r | |
243 | $subbing = 0;\r | |
244 | next;\r | |
245 | }\r | |
246 | \r | |
247 | push @new_inf, $_\r | |
248 | unless ($subbing);\r | |
249 | }\r | |
250 | \r | |
251 | $new_inf_file = $inf_file . ".new";\r | |
252 | open( FD, ">" . $new_inf_file ) ||\r | |
253 | die $new_inf_file;\r | |
254 | print( FD @new_inf ) ||\r | |
255 | die $new_inf_file;\r | |
256 | close(FD) ||\r | |
257 | die $new_inf_file;\r | |
258 | rename( $new_inf_file, $inf_file ) ||\r | |
259 | die "rename $inf_file";\r | |
260 | print "Done!";\r | |
261 | \r | |
262 | #\r | |
1bcc65b9 | 263 | # Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r |
264702a0 HW |
264 | #\r |
265 | print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r | |
8c30327d GJ |
266 | system(\r |
267 | "perl -pe 's/\\n/\\r\\n/' " .\r | |
268 | "< " . $OPENSSL_PATH . "/include/openssl/opensslconf.h " .\r | |
269 | "> " . $OPENSSL_PATH . "/../../Include/openssl/opensslconf.h"\r | |
270 | ) == 0 ||\r | |
271 | die "Cannot copy opensslconf.h!";\r | |
1bcc65b9 | 272 | print "Done!";\r |
8c30327d GJ |
273 | \r |
274 | print "\n--> Duplicating dso_conf.h into Include/crypto ... ";\r | |
275 | system(\r | |
276 | "perl -pe 's/\\n/\\r\\n/' " .\r | |
277 | "< " . $OPENSSL_PATH . "/include/crypto/dso_conf.h" .\r | |
278 | "> " . $OPENSSL_PATH . "/../../Include/crypto/dso_conf.h"\r | |
279 | ) == 0 ||\r | |
280 | die "Cannot copy dso_conf.h!";\r | |
264702a0 HW |
281 | print "Done!\n";\r |
282 | \r | |
283 | print "\nProcessing Files Done!\n";\r | |
284 | \r | |
285 | exit(0);\r | |
286 | \r |