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