]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
Revert "BaseTools: Add gcc flag to warn on void* pointer arithmetic"
[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
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
114 "crypto/include/internal/dso_conf.h.in " .\r
115 "> include/internal/dso_conf.h"\r
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
131use configdata qw/%unified_info/;\r
132\r
133my @cryptofilelist = ();\r
134my @sslfilelist = ();\r
135foreach 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
162my @dir_list = ();\r
c72ca466 163for (sort keys %{$unified_info{dirinfo}}){\r
9f4fbd56
SZ
164 push @dir_list,$_;\r
165}\r
166\r
167my $dir = getcwd();\r
168my @files = ();\r
169my @headers = ();\r
170chdir ("openssl");\r
171foreach(@dir_list){\r
172 @files = glob($_."/*.h");\r
173 push @headers, @files;\r
174}\r
175chdir ($dir);\r
176\r
177foreach (@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
189my @new_inf = ();\r
190my $subbing = 0;\r
191print "\n--> Updating OpensslLib.inf ... ";\r
192foreach (@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
208my $new_inf_file = $inf_file . ".new";\r
209open( FD, ">" . $new_inf_file ) ||\r
210 die $new_inf_file;\r
211print( FD @new_inf ) ||\r
212 die $new_inf_file;\r
213close(FD) ||\r
214 die $new_inf_file;\r
215rename( $new_inf_file, $inf_file ) ||\r
216 die "rename $inf_file";\r
217print "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
227open( FD, "<" . $inf_file ) ||\r
228 die "Cannot open \"" . $inf_file . "\"!";\r
229@inf = (<FD>);\r
230close(FD) ||\r
231 die "Cannot close \"" . $inf_file . "\"!";\r
232\r
233$subbing = 0;\r
234print "\n--> Updating OpensslLibCrypto.inf ... ";\r
235foreach (@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
252open( FD, ">" . $new_inf_file ) ||\r
253 die $new_inf_file;\r
254print( FD @new_inf ) ||\r
255 die $new_inf_file;\r
256close(FD) ||\r
257 die $new_inf_file;\r
258rename( $new_inf_file, $inf_file ) ||\r
259 die "rename $inf_file";\r
260print "Done!";\r
261\r
262#\r
1bcc65b9 263# Copy opensslconf.h and dso_conf.h generated from OpenSSL Configuration\r
264702a0
HW
264#\r
265print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
266copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 267 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0 268 die "Cannot copy opensslconf.h!";\r
1bcc65b9
SZ
269print "Done!";\r
270print "\n--> Duplicating dso_conf.h into Include/internal ... ";\r
271copy($OPENSSL_PATH . "/include/internal/dso_conf.h",\r
272 $OPENSSL_PATH . "/../../Include/internal/") ||\r
273 die "Cannot copy dso_conf.h!";\r
264702a0
HW
274print "Done!\n";\r
275\r
276print "\nProcessing Files Done!\n";\r
277\r
278exit(0);\r
279\r