CryptoPkg/TlsLib: rewrite TlsSetCipherList()
[mirror_edk2.git] / CryptoPkg / Library / OpensslLib / process_files.pl
1 #!/usr/bin/perl -w
2 #
3 # This script runs the OpenSSL Configure script, then processes the
4 # resulting file list into our local OpensslLib[Crypto].inf and also
5 # takes a copy of opensslconf.h.
6 #
7 # This only needs to be done once by a developer when updating to a
8 # new version of OpenSSL (or changing options, etc.). Normal users
9 # do not need to do this, since the results are stored in the EDK2
10 # git repository for them.
11 #
12 use strict;
13 use Cwd;
14 use File::Copy;
15
16 #
17 # Find the openssl directory name for use lib. We have to do this
18 # inside of BEGIN. The variables we create here, however, don't seem
19 # to be available to the main script, so we have to repeat the
20 # exercise.
21 #
22 my $inf_file;
23 my $OPENSSL_PATH;
24 my @inf;
25
26 BEGIN {
27 $inf_file = "OpensslLib.inf";
28
29 # Read the contents of the inf file
30 open( FD, "<" . $inf_file ) ||
31 die "Cannot open \"" . $inf_file . "\"!";
32 @inf = (<FD>);
33 close(FD) ||
34 die "Cannot close \"" . $inf_file . "\"!";
35
36 foreach (@inf) {
37 if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
38
39 # We need to run Configure before we can include its result...
40 $OPENSSL_PATH = $1;
41
42 my $basedir = getcwd();
43
44 chdir($OPENSSL_PATH) ||
45 die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
46
47 # Configure UEFI
48 system(
49 "./Configure",
50 "UEFI",
51 "no-afalgeng",
52 "no-asm",
53 "no-async",
54 "no-autoalginit",
55 "no-autoerrinit",
56 "no-bf",
57 "no-blake2",
58 "no-camellia",
59 "no-capieng",
60 "no-cast",
61 "no-chacha",
62 "no-cms",
63 "no-ct",
64 "no-deprecated",
65 "no-dgram",
66 "no-dsa",
67 "no-dynamic-engine",
68 "no-ec",
69 "no-ec2m",
70 "no-engine",
71 "no-err",
72 "no-filenames",
73 "no-gost",
74 "no-hw",
75 "no-idea",
76 "no-mdc2",
77 "no-pic",
78 "no-ocb",
79 "no-poly1305",
80 "no-posix-io",
81 "no-rc2",
82 "no-rfc3779",
83 "no-rmd160",
84 "no-scrypt",
85 "no-seed",
86 "no-sock",
87 "no-srp",
88 "no-ssl",
89 "no-stdio",
90 "no-threads",
91 "no-ts",
92 "no-ui",
93 "no-whirlpool"
94 ) == 0 ||
95 die "OpenSSL Configure failed!\n";
96
97 # Generate opensslconf.h per config data
98 system(
99 "perl -I. -Mconfigdata util/dofile.pl " .
100 "include/openssl/opensslconf.h.in " .
101 "> include/openssl/opensslconf.h"
102 ) == 0 ||
103 die "Failed to generate opensslconf.h!\n";
104
105 chdir($basedir) ||
106 die "Cannot change to base directory \"" . $basedir . "\"";
107
108 push @INC, $1;
109 last;
110 }
111 }
112 }
113
114 #
115 # Retrieve file lists from OpenSSL configdata
116 #
117 use configdata qw/%unified_info/;
118
119 my @cryptofilelist = ();
120 my @sslfilelist = ();
121 foreach my $product ((@{$unified_info{libraries}},
122 @{$unified_info{engines}})) {
123 foreach my $o (@{$unified_info{sources}->{$product}}) {
124 foreach my $s (@{$unified_info{sources}->{$o}}) {
125 next if ($unified_info{generate}->{$s});
126 next if $s =~ "crypto/bio/b_print.c";
127 if ($product =~ "libssl") {
128 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
129 next;
130 }
131 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";
132 }
133 }
134 }
135
136 #
137 # Update OpensslLib.inf with autogenerated file list
138 #
139 my @new_inf = ();
140 my $subbing = 0;
141 print "\n--> Updating OpensslLib.inf ... ";
142 foreach (@inf) {
143 if ( $_ =~ "# Autogenerated files list starts here" ) {
144 push @new_inf, $_, @cryptofilelist, @sslfilelist;
145 $subbing = 1;
146 next;
147 }
148 if ( $_ =~ "# Autogenerated files list ends here" ) {
149 push @new_inf, $_;
150 $subbing = 0;
151 next;
152 }
153
154 push @new_inf, $_
155 unless ($subbing);
156 }
157
158 my $new_inf_file = $inf_file . ".new";
159 open( FD, ">" . $new_inf_file ) ||
160 die $new_inf_file;
161 print( FD @new_inf ) ||
162 die $new_inf_file;
163 close(FD) ||
164 die $new_inf_file;
165 rename( $new_inf_file, $inf_file ) ||
166 die "rename $inf_file";
167 print "Done!";
168
169 #
170 # Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
171 #
172 $inf_file = "OpensslLibCrypto.inf";
173
174 # Read the contents of the inf file
175 @inf = ();
176 @new_inf = ();
177 open( FD, "<" . $inf_file ) ||
178 die "Cannot open \"" . $inf_file . "\"!";
179 @inf = (<FD>);
180 close(FD) ||
181 die "Cannot close \"" . $inf_file . "\"!";
182
183 $subbing = 0;
184 print "\n--> Updating OpensslLibCrypto.inf ... ";
185 foreach (@inf) {
186 if ( $_ =~ "# Autogenerated files list starts here" ) {
187 push @new_inf, $_, @cryptofilelist;
188 $subbing = 1;
189 next;
190 }
191 if ( $_ =~ "# Autogenerated files list ends here" ) {
192 push @new_inf, $_;
193 $subbing = 0;
194 next;
195 }
196
197 push @new_inf, $_
198 unless ($subbing);
199 }
200
201 $new_inf_file = $inf_file . ".new";
202 open( FD, ">" . $new_inf_file ) ||
203 die $new_inf_file;
204 print( FD @new_inf ) ||
205 die $new_inf_file;
206 close(FD) ||
207 die $new_inf_file;
208 rename( $new_inf_file, $inf_file ) ||
209 die "rename $inf_file";
210 print "Done!";
211
212 #
213 # Copy opensslconf.h generated from OpenSSL Configuration
214 #
215 print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
216 copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
217 $OPENSSL_PATH . "/../../Include/openssl/") ||
218 die "Cannot copy opensslconf.h!";
219 print "Done!\n";
220
221 print "\nProcessing Files Done!\n";
222
223 exit(0);
224