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