CryptoPkg/TlsLib: rewrite TlsSetCipherList()
[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
93 "no-whirlpool"\r
94 ) == 0 ||\r
95 die "OpenSSL Configure failed!\n";\r
96\r
97 # Generate opensslconf.h per config data\r
98 system(\r
99 "perl -I. -Mconfigdata util/dofile.pl " .\r
100 "include/openssl/opensslconf.h.in " .\r
101 "> include/openssl/opensslconf.h"\r
102 ) == 0 ||\r
103 die "Failed to generate opensslconf.h!\n";\r
104\r
105 chdir($basedir) ||\r
106 die "Cannot change to base directory \"" . $basedir . "\"";\r
107\r
108 push @INC, $1;\r
109 last;\r
110 }\r
111 }\r
112}\r
113\r
114#\r
115# Retrieve file lists from OpenSSL configdata\r
116#\r
117use configdata qw/%unified_info/;\r
118\r
119my @cryptofilelist = ();\r
120my @sslfilelist = ();\r
121foreach my $product ((@{$unified_info{libraries}},\r
122 @{$unified_info{engines}})) {\r
123 foreach my $o (@{$unified_info{sources}->{$product}}) {\r
124 foreach my $s (@{$unified_info{sources}->{$o}}) {\r
125 next if ($unified_info{generate}->{$s});\r
126 next if $s =~ "crypto/bio/b_print.c";\r
127 if ($product =~ "libssl") {\r
128 push @sslfilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
129 next;\r
130 }\r
131 push @cryptofilelist, ' $(OPENSSL_PATH)/' . $s . "\r\n";\r
132 }\r
133 }\r
134}\r
135\r
136#\r
137# Update OpensslLib.inf with autogenerated file list\r
138#\r
139my @new_inf = ();\r
140my $subbing = 0;\r
141print "\n--> Updating OpensslLib.inf ... ";\r
142foreach (@inf) {\r
143 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
144 push @new_inf, $_, @cryptofilelist, @sslfilelist;\r
145 $subbing = 1;\r
146 next;\r
147 }\r
148 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
149 push @new_inf, $_;\r
150 $subbing = 0;\r
151 next;\r
152 }\r
153\r
154 push @new_inf, $_\r
155 unless ($subbing);\r
156}\r
157\r
158my $new_inf_file = $inf_file . ".new";\r
159open( FD, ">" . $new_inf_file ) ||\r
160 die $new_inf_file;\r
161print( FD @new_inf ) ||\r
162 die $new_inf_file;\r
163close(FD) ||\r
164 die $new_inf_file;\r
165rename( $new_inf_file, $inf_file ) ||\r
166 die "rename $inf_file";\r
167print "Done!";\r
168\r
169#\r
170# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)\r
171#\r
172$inf_file = "OpensslLibCrypto.inf";\r
173\r
174# Read the contents of the inf file\r
175@inf = ();\r
176@new_inf = ();\r
177open( FD, "<" . $inf_file ) ||\r
178 die "Cannot open \"" . $inf_file . "\"!";\r
179@inf = (<FD>);\r
180close(FD) ||\r
181 die "Cannot close \"" . $inf_file . "\"!";\r
182\r
183$subbing = 0;\r
184print "\n--> Updating OpensslLibCrypto.inf ... ";\r
185foreach (@inf) {\r
186 if ( $_ =~ "# Autogenerated files list starts here" ) {\r
187 push @new_inf, $_, @cryptofilelist;\r
188 $subbing = 1;\r
189 next;\r
190 }\r
191 if ( $_ =~ "# Autogenerated files list ends here" ) {\r
192 push @new_inf, $_;\r
193 $subbing = 0;\r
194 next;\r
195 }\r
196\r
197 push @new_inf, $_\r
198 unless ($subbing);\r
199}\r
200\r
201$new_inf_file = $inf_file . ".new";\r
202open( FD, ">" . $new_inf_file ) ||\r
203 die $new_inf_file;\r
204print( FD @new_inf ) ||\r
205 die $new_inf_file;\r
206close(FD) ||\r
207 die $new_inf_file;\r
208rename( $new_inf_file, $inf_file ) ||\r
209 die "rename $inf_file";\r
210print "Done!";\r
211\r
212#\r
213# Copy opensslconf.h generated from OpenSSL Configuration\r
214#\r
215print "\n--> Duplicating opensslconf.h into Include/openssl ... ";\r
216copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",\r
abc4c817 217 $OPENSSL_PATH . "/../../Include/openssl/") ||\r
264702a0
HW
218 die "Cannot copy opensslconf.h!";\r
219print "Done!\n";\r
220\r
221print "\nProcessing Files Done!\n";\r
222\r
223exit(0);\r
224\r