]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/OpensslLib/process_files.pl
CryptoPkg/OpensslLib: Modify process_files.pl for upgrading OpenSSL
[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
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
108 chdir($basedir) ||\r
109 die "Cannot change to base directory \"" . $basedir . "\"";\r
110\r
111 push @INC, $1;\r
112 last;\r
113 }\r
114 }\r
115}\r
116\r
117#\r
118# Retrieve file lists from OpenSSL configdata\r
119#\r
120use configdata qw/%unified_info/;\r
121\r
122my @cryptofilelist = ();\r
123my @sslfilelist = ();\r
124foreach my $product ((@{$unified_info{libraries}},\r
125 @{$unified_info{engines}})) {\r
126 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
127 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
128 next if ($unified_info{generate}->{$s});\r
129 next if $s =~ "crypto/bio/b_print.c";\r
130 if ($product =~ "libssl") {\r
131 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
132 next;\r
133 }\r
134 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
135 }\r
136 }\r
137}\r
138\r
139#\r
140# Update OpensslLib.inf with autogenerated file list\r
141#\r
142my @new_inf = ();\r
143my $subbing = 0;\r
144print "\n--> Updating OpensslLib.inf ... ";\r
145foreach (@inf) {\r
146 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
147 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
148 $subbing = 1;\r
149 next;\r
150 }\r
151 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
152 push @new_inf, $_;\r
153 $subbing = 0;\r
154 next;\r
155 }\r
156\r
157 push @new_inf, $_\r
158 unless ($subbing);\r
159}\r
160\r
161my $new_inf_file = $inf_file . ".new";\r
162open( FD, ">" . $new_inf_file ) ||\r
163 die $new_inf_file;\r
164print( FD @new_inf ) ||\r
165 die $new_inf_file;\r
166close(FD) ||\r
167 die $new_inf_file;\r
168rename( $new_inf_file, $inf_file ) ||\r
169 die "rename $inf_file";\r
170print "Done!";\r
171\r
172#\r
173# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
174#\r
175$inf_file = "OpensslLibCrypto.inf";\r
176\r
177# Read the contents of the inf file\r
178@inf = ();\r
179@new_inf = ();\r
180open( FD, "<" . $inf_file ) ||\r
181 die "Cannot open \"" . $inf_file . "\"!";\r
182@inf = (<FD>);\r
183close(FD) ||\r
184 die "Cannot close \"" . $inf_file . "\"!";\r
185\r
186$subbing = 0;\r
187print "\n--> Updating OpensslLibCrypto.inf ... ";\r
188foreach (@inf) {\r
189 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
190 push @new_inf, $_, @cryptofilelist;\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
204$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# Copy opensslconf.h generated from OpenSSL Configuration\r
217#\r
218print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
219copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 220 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0
HW
221 die "Cannot copy opensslconf.h!";\r
222print "Done!\n";\r
223\r
224print "\nProcessing Files Done!\n";\r
225\r
226exit(0);\r
227\r