]>
Commit | Line | Data |
---|---|---|
1f86b822 RL |
1 | #! {- $config{HASHBANGPERL} -} |
2 | # -*- mode: perl -*- | |
3 | {- | |
1f86b822 RL |
4 | # We must make sourcedir() return an absolute path, because configdata.pm |
5 | # may be loaded as a module from any script in any directory, making | |
6 | # relative paths untrustable. Because the result is used with 'use lib', | |
7 | # we must ensure that it returns a Unix style path. Cwd::abs_path does | |
8 | # that (File::Spec::Functions::rel2abs return O/S specific paths) | |
9 | use File::Spec::Functions; | |
10 | use Cwd qw(abs_path); | |
11 | sub sourcedir { | |
12 | return abs_path(catdir($config{sourcedir}, @_)); | |
13 | } | |
14 | sub sourcefile { | |
15 | return abs_path(catfile($config{sourcedir}, @_)); | |
16 | } | |
da51dc5f RL |
17 | use lib sourcedir('util', 'perl'); |
18 | use OpenSSL::Util; | |
1f86b822 RL |
19 | -} |
20 | package configdata; | |
21 | ||
22 | use strict; | |
23 | use warnings; | |
24 | ||
25 | use Exporter; | |
26 | our @ISA = qw(Exporter); | |
27 | our @EXPORT = qw( | |
28 | %config %target %disabled %withargs %unified_info | |
29 | @disablables @disablables_int | |
30 | ); | |
31 | ||
da51dc5f RL |
32 | our %config = ({- dump_data(\%config, indent => 0); -}); |
33 | our %target = ({- dump_data(\%target, indent => 0); -}); | |
34 | our @disablables = ({- dump_data(\@disablables, indent => 0) -}); | |
35 | our @disablables_int = ({- dump_data(\@disablables_int, indent => 0) -}); | |
36 | our %disabled = ({- dump_data(\%disabled, indent => 0); -}); | |
37 | our %withargs = ({- dump_data(\%withargs, indent => 0); -}); | |
38 | our %unified_info = ({- dump_data(\%unified_info, indent => 0); -}); | |
1f86b822 RL |
39 | |
40 | # Unexported, only used by OpenSSL::Test::Utils::available_protocols() | |
41 | our %available_protocols = ( | |
da51dc5f RL |
42 | tls => [{- dump_data(\@tls, indent => 0) -}], |
43 | dtls => [{- dump_data(\@dtls, indent => 0) -}], | |
1f86b822 RL |
44 | ); |
45 | ||
46 | # The following data is only used when this files is use as a script | |
da51dc5f RL |
47 | my @makevars = ({- dump_data(\@makevars, indent => 0); -}); |
48 | my %disabled_info = ({- dump_data(\%disabled_info, indent => 0); -}); | |
1f86b822 RL |
49 | my @user_crossable = qw( {- join (' ', @user_crossable) -} ); |
50 | ||
51 | # If run directly, we can give some answers, and even reconfigure | |
52 | unless (caller) { | |
53 | use Getopt::Long; | |
54 | use File::Spec::Functions; | |
55 | use File::Basename; | |
56 | use Pod::Usage; | |
57 | ||
841a438c RL |
58 | use lib '{- sourcedir('util', 'perl') -}'; |
59 | use OpenSSL::fallback '{- sourcefile('external', 'perl', 'MODULES.txt') -}'; | |
60 | ||
1f86b822 RL |
61 | my $here = dirname($0); |
62 | ||
63 | if (scalar @ARGV == 0) { | |
64 | # With no arguments, re-create the build file | |
65 | ||
1f86b822 RL |
66 | use OpenSSL::Template; |
67 | ||
09803e9c | 68 | my $prepend = <<'_____'; |
1f86b822 RL |
69 | use File::Spec::Functions; |
70 | use lib '{- sourcedir('util', 'perl') -}'; | |
1f86b822 RL |
71 | use lib '{- sourcedir('Configurations') -}'; |
72 | use lib '{- $config{builddir} -}'; | |
73 | use platform; | |
74 | _____ | |
75 | ||
76 | my @autowarntext = ( | |
77 | 'WARNING: do not edit!', | |
78 | "Generated by configdata.pm from " | |
79 | .join(", ", @{$config{build_file_templates}}) | |
80 | ); | |
81 | ||
82 | print 'Creating ',$target{build_file},"\n"; | |
83 | open BUILDFILE, ">$target{build_file}.new" | |
84 | or die "Trying to create $target{build_file}.new: $!"; | |
85 | foreach (@{$config{build_file_templates}}) { | |
86 | my $tmpl = OpenSSL::Template->new(TYPE => 'FILE', | |
87 | SOURCE => $_); | |
88 | $tmpl->fill_in(FILENAME => $_, | |
89 | OUTPUT => \*BUILDFILE, | |
90 | HASH => { config => \%config, | |
91 | target => \%target, | |
92 | disabled => \%disabled, | |
93 | withargs => \%withargs, | |
94 | unified_info => \%unified_info, | |
95 | autowarntext => \@autowarntext }, | |
96 | PREPEND => $prepend, | |
97 | # To ensure that global variables and functions | |
98 | # defined in one template stick around for the | |
99 | # next, making them combinable | |
100 | PACKAGE => 'OpenSSL::safe') | |
101 | or die $Text::Template::ERROR; | |
102 | } | |
103 | close BUILDFILE; | |
104 | rename("$target{build_file}.new", $target{build_file}) | |
105 | or die "Trying to rename $target{build_file}.new to $target{build_file}: $!"; | |
106 | ||
107 | exit(0); | |
108 | } | |
109 | ||
110 | my $dump = undef; | |
111 | my $cmdline = undef; | |
112 | my $options = undef; | |
113 | my $target = undef; | |
114 | my $envvars = undef; | |
115 | my $makevars = undef; | |
116 | my $buildparams = undef; | |
117 | my $reconf = undef; | |
118 | my $verbose = undef; | |
841a438c | 119 | my $query = undef; |
1f86b822 RL |
120 | my $help = undef; |
121 | my $man = undef; | |
122 | GetOptions('dump|d' => \$dump, | |
123 | 'command-line|c' => \$cmdline, | |
124 | 'options|o' => \$options, | |
125 | 'target|t' => \$target, | |
126 | 'environment|e' => \$envvars, | |
127 | 'make-variables|m' => \$makevars, | |
128 | 'build-parameters|b' => \$buildparams, | |
129 | 'reconfigure|reconf|r' => \$reconf, | |
130 | 'verbose|v' => \$verbose, | |
841a438c | 131 | 'query|q=s' => \$query, |
1f86b822 RL |
132 | 'help' => \$help, |
133 | 'man' => \$man) | |
134 | or die "Errors in command line arguments\n"; | |
135 | ||
136 | if (scalar @ARGV > 0) { | |
137 | print STDERR <<"_____"; | |
138 | Unrecognised arguments. | |
139 | For more information, do '$0 --help' | |
140 | _____ | |
141 | exit(2); | |
142 | } | |
143 | ||
144 | if ($help) { | |
145 | pod2usage(-exitval => 0, | |
146 | -verbose => 1); | |
147 | } | |
148 | if ($man) { | |
149 | pod2usage(-exitval => 0, | |
150 | -verbose => 2); | |
151 | } | |
152 | if ($dump || $cmdline) { | |
153 | print "\nCommand line (with current working directory = $here):\n\n"; | |
154 | print ' ',join(' ', | |
155 | $config{PERL}, | |
156 | catfile($config{sourcedir}, 'Configure'), | |
157 | @{$config{perlargv}}), "\n"; | |
158 | print "\nPerl information:\n\n"; | |
159 | print ' ',$config{perl_cmd},"\n"; | |
160 | print ' ',$config{perl_version},' for ',$config{perl_archname},"\n"; | |
161 | } | |
162 | if ($dump || $options) { | |
163 | my $longest = 0; | |
164 | my $longest2 = 0; | |
165 | foreach my $what (@disablables) { | |
166 | $longest = length($what) if $longest < length($what); | |
167 | $longest2 = length($disabled{$what}) | |
168 | if $disabled{$what} && $longest2 < length($disabled{$what}); | |
169 | } | |
170 | print "\nEnabled features:\n\n"; | |
171 | foreach my $what (@disablables) { | |
172 | print " $what\n" unless $disabled{$what}; | |
173 | } | |
174 | print "\nDisabled features:\n\n"; | |
175 | foreach my $what (@disablables) { | |
176 | if ($disabled{$what}) { | |
177 | print " $what", ' ' x ($longest - length($what) + 1), | |
178 | "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1); | |
179 | print $disabled_info{$what}->{macro} | |
180 | if $disabled_info{$what}->{macro}; | |
181 | print ' (skip ', | |
182 | join(', ', @{$disabled_info{$what}->{skipped}}), | |
183 | ')' | |
184 | if $disabled_info{$what}->{skipped}; | |
185 | print "\n"; | |
186 | } | |
187 | } | |
188 | } | |
189 | if ($dump || $target) { | |
190 | print "\nConfig target attributes:\n\n"; | |
191 | foreach (sort keys %target) { | |
192 | next if $_ =~ m|^_| || $_ eq 'template'; | |
193 | my $quotify = sub { | |
278de77b RL |
194 | map { |
195 | if (defined $_) { | |
196 | (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\"" | |
197 | } else { | |
198 | "undef"; | |
199 | } | |
200 | } @_; | |
1f86b822 RL |
201 | }; |
202 | print ' ', $_, ' => '; | |
203 | if (ref($target{$_}) eq "ARRAY") { | |
204 | print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n"; | |
205 | } else { | |
206 | print $quotify->($target{$_}), ",\n" | |
207 | } | |
208 | } | |
209 | } | |
210 | if ($dump || $envvars) { | |
211 | print "\nRecorded environment:\n\n"; | |
212 | foreach (sort keys %{$config{perlenv}}) { | |
213 | print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n"; | |
214 | } | |
215 | } | |
216 | if ($dump || $makevars) { | |
217 | print "\nMakevars:\n\n"; | |
218 | foreach my $var (@makevars) { | |
219 | my $prefix = ''; | |
220 | $prefix = $config{CROSS_COMPILE} | |
221 | if grep { $var eq $_ } @user_crossable; | |
222 | $prefix //= ''; | |
223 | print ' ',$var,' ' x (16 - length $var),'= ', | |
224 | (ref $config{$var} eq 'ARRAY' | |
225 | ? join(' ', @{$config{$var}}) | |
226 | : $prefix.$config{$var}), | |
227 | "\n" | |
228 | if defined $config{$var}; | |
229 | } | |
230 | ||
231 | my @buildfile = ($config{builddir}, $config{build_file}); | |
232 | unshift @buildfile, $here | |
233 | unless file_name_is_absolute($config{builddir}); | |
234 | my $buildfile = canonpath(catdir(@buildfile)); | |
235 | print <<"_____"; | |
236 | ||
237 | NOTE: These variables only represent the configuration view. The build file | |
238 | template may have processed these variables further, please have a look at the | |
239 | build file for more exact data: | |
240 | $buildfile | |
241 | _____ | |
242 | } | |
243 | if ($dump || $buildparams) { | |
244 | my @buildfile = ($config{builddir}, $config{build_file}); | |
245 | unshift @buildfile, $here | |
246 | unless file_name_is_absolute($config{builddir}); | |
247 | print "\nbuild file:\n\n"; | |
248 | print " ", canonpath(catfile(@buildfile)),"\n"; | |
249 | ||
250 | print "\nbuild file templates:\n\n"; | |
251 | foreach (@{$config{build_file_templates}}) { | |
252 | my @tmpl = ($_); | |
253 | unshift @tmpl, $here | |
254 | unless file_name_is_absolute($config{sourcedir}); | |
255 | print ' ',canonpath(catfile(@tmpl)),"\n"; | |
256 | } | |
257 | } | |
258 | if ($reconf) { | |
259 | if ($verbose) { | |
260 | print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n"; | |
261 | foreach (sort keys %{$config{perlenv}}) { | |
262 | print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n"; | |
263 | } | |
264 | } | |
265 | ||
266 | chdir $here; | |
267 | exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf'; | |
268 | } | |
841a438c RL |
269 | if ($query) { |
270 | use OpenSSL::Config::Query; | |
271 | ||
272 | my $confquery = OpenSSL::Config::Query->new(info => \%unified_info, | |
273 | config => \%config); | |
274 | my $result = eval "\$confquery->$query"; | |
275 | ||
276 | # We may need a result class with a printing function at some point. | |
277 | # Until then, we assume that we get a scalar, or a list or a hash table | |
278 | # with scalar values and simply print them in some orderly fashion. | |
279 | if (ref $result eq 'ARRAY') { | |
280 | print "$_\n" foreach @$result; | |
281 | } elsif (ref $result eq 'HASH') { | |
282 | print "$_ : \\\n ", join(" \\\n ", @{$result->{$_}}), "\n" | |
283 | foreach sort keys %$result; | |
284 | } elsif (ref $result eq 'SCALAR') { | |
285 | print "$$result\n"; | |
286 | } | |
287 | } | |
1f86b822 RL |
288 | } |
289 | ||
290 | 1; | |
291 | ||
292 | __END__ | |
293 | ||
294 | =head1 NAME | |
295 | ||
296 | configdata.pm - configuration data for OpenSSL builds | |
297 | ||
298 | =head1 SYNOPSIS | |
299 | ||
300 | Interactive: | |
301 | ||
302 | perl configdata.pm [options] | |
303 | ||
304 | As data bank module: | |
305 | ||
306 | use configdata; | |
307 | ||
308 | =head1 DESCRIPTION | |
309 | ||
310 | This module can be used in two modes, interactively and as a module containing | |
311 | all the data recorded by OpenSSL's Configure script. | |
312 | ||
313 | When used interactively, simply run it as any perl script. | |
314 | If run with no arguments, it will rebuild the build file (Makefile or | |
315 | corresponding). | |
316 | With at least one option, it will instead get the information you ask for, or | |
317 | re-run the configuration process. | |
318 | See L</OPTIONS> below for more information. | |
319 | ||
320 | When loaded as a module, you get a few databanks with useful information to | |
321 | perform build related tasks. The databanks are: | |
322 | ||
323 | %config Configured things. | |
324 | %target The OpenSSL config target with all inheritances | |
325 | resolved. | |
326 | %disabled The features that are disabled. | |
327 | @disablables The list of features that can be disabled. | |
328 | %withargs All data given through --with-THING options. | |
329 | %unified_info All information that was computed from the build.info | |
330 | files. | |
331 | ||
332 | =head1 OPTIONS | |
333 | ||
334 | =over 4 | |
335 | ||
336 | =item B<--help> | |
337 | ||
338 | Print a brief help message and exit. | |
339 | ||
340 | =item B<--man> | |
341 | ||
342 | Print the manual page and exit. | |
343 | ||
344 | =item B<--dump> | B<-d> | |
345 | ||
346 | Print all relevant configuration data. This is equivalent to B<--command-line> | |
347 | B<--options> B<--target> B<--environment> B<--make-variables> | |
348 | B<--build-parameters>. | |
349 | ||
350 | =item B<--command-line> | B<-c> | |
351 | ||
352 | Print the current configuration command line. | |
353 | ||
354 | =item B<--options> | B<-o> | |
355 | ||
356 | Print the features, both enabled and disabled, and display defined macro and | |
357 | skipped directories where applicable. | |
358 | ||
359 | =item B<--target> | B<-t> | |
360 | ||
361 | Print the config attributes for this config target. | |
362 | ||
363 | =item B<--environment> | B<-e> | |
364 | ||
365 | Print the environment variables and their values at the time of configuration. | |
366 | ||
367 | =item B<--make-variables> | B<-m> | |
368 | ||
369 | Print the main make variables generated in the current configuration | |
370 | ||
371 | =item B<--build-parameters> | B<-b> | |
372 | ||
373 | Print the build parameters, i.e. build file and build file templates. | |
374 | ||
375 | =item B<--reconfigure> | B<--reconf> | B<-r> | |
376 | ||
377 | Re-run the configuration process. | |
378 | ||
379 | =item B<--verbose> | B<-v> | |
380 | ||
381 | Verbose output. | |
382 | ||
383 | =back | |
384 | ||
385 | =cut | |
386 | ||
387 | EOF |