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